node/test/parallel/test-child-process-spawnsync-kill-signal.js
James M Snell 91e96d8f08 lib,src: fix consistent spacing inside braces
PR-URL: #14162
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-09-20 12:32:17 -07:00

51 lines
1.4 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
if (process.argv[2] === 'child') {
setInterval(() => {}, 1000);
} else {
const { SIGKILL } = process.binding('constants').os.signals;
function spawn(killSignal) {
const child = cp.spawnSync(process.execPath,
[__filename, 'child'],
{ killSignal, timeout: 100 });
assert.strictEqual(child.status, null);
assert.strictEqual(child.error.code, 'ETIMEDOUT');
return child;
}
// Verify that an error is thrown for unknown signals.
assert.throws(() => {
spawn('SIG_NOT_A_REAL_SIGNAL');
}, common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL' }));
// Verify that the default kill signal is SIGTERM.
{
const child = spawn();
assert.strictEqual(child.signal, 'SIGTERM');
assert.strictEqual(child.options.killSignal, undefined);
}
// Verify that a string signal name is handled properly.
{
const child = spawn('SIGKILL');
assert.strictEqual(child.signal, 'SIGKILL');
assert.strictEqual(child.options.killSignal, SIGKILL);
}
// Verify that a numeric signal is handled properly.
{
const child = spawn(SIGKILL);
assert.strictEqual(typeof SIGKILL, 'number');
assert.strictEqual(child.signal, 'SIGKILL');
assert.strictEqual(child.options.killSignal, SIGKILL);
}
}