Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 51b251d

Browse filesBrowse files
cjihrigMyles Borins
authored andcommitted
test: add coverage for spawnSync() killSignal
This commit adds a test for the killSignal option to spawnSync(), and the other sync child process functions by extension. PR-URL: #8960 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent e5d2a95 commit 51b251d
Copy full SHA for 51b251d

File tree

Expand file treeCollapse file tree

1 file changed

+51
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+51
-0
lines changed
Open diff view settings
Collapse file
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const cp = require('child_process');
5+
6+
if (process.argv[2] === 'child') {
7+
setInterval(() => {}, 1000);
8+
} else {
9+
const exitCode = common.isWindows ? 1 : 0;
10+
const SIGKILL = process.binding('constants').SIGKILL;
11+
12+
function spawn(killSignal) {
13+
const child = cp.spawnSync(process.execPath,
14+
[__filename, 'child'],
15+
{killSignal, timeout: 100});
16+
17+
assert.strictEqual(child.status, exitCode);
18+
assert.strictEqual(child.error.code, 'ETIMEDOUT');
19+
return child;
20+
}
21+
22+
// Verify that an error is thrown for unknown signals.
23+
assert.throws(() => {
24+
spawn('SIG_NOT_A_REAL_SIGNAL');
25+
}, /Error: Unknown signal: SIG_NOT_A_REAL_SIGNAL/);
26+
27+
// Verify that the default kill signal is SIGTERM.
28+
{
29+
const child = spawn();
30+
31+
assert.strictEqual(child.signal, 'SIGTERM');
32+
assert.strictEqual(child.options.killSignal, undefined);
33+
}
34+
35+
// Verify that a string signal name is handled properly.
36+
{
37+
const child = spawn('SIGKILL');
38+
39+
assert.strictEqual(child.signal, 'SIGKILL');
40+
assert.strictEqual(child.options.killSignal, SIGKILL);
41+
}
42+
43+
// Verify that a numeric signal is handled properly.
44+
{
45+
const child = spawn(SIGKILL);
46+
47+
assert.strictEqual(typeof SIGKILL, 'number');
48+
assert.strictEqual(child.signal, 'SIGKILL');
49+
assert.strictEqual(child.options.killSignal, SIGKILL);
50+
}
51+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.