Skip to content

Commit

Permalink
Improve error.killed
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 10, 2019
1 parent 5f8bd52 commit 2cdbfdf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 1 addition & 5 deletions index.js
Expand Up @@ -195,6 +195,7 @@ function makeError(result, options) {
// `signal` emitted on `spawned.on('exit')` event can be `null`. We normalize
// it to `undefined`
error.signal = signal || undefined;
error.killed = signal !== null && !timedOut;
error.command = joinedCommand;
error.timedOut = Boolean(timedOut);
error.isCanceled = isCanceled;
Expand Down Expand Up @@ -367,11 +368,6 @@ const execa = (command, args, options) => {
isCanceled
});

// TODO: missing some timeout logic for killed
// https://github.com/nodejs/node/blob/master/lib/child_process.js#L203
// error.killed = spawned.killed || killed;
error.killed = error.killed || spawned.killed;

if (!parsed.options.reject) {
return error;
}
Expand Down
6 changes: 3 additions & 3 deletions test.js
Expand Up @@ -293,16 +293,15 @@ test('error.killed is true if process was killed directly', async t => {
t.true(error.killed);
});

// TODO: Should this really be the case, or should we improve on child_process?
test('error.killed is false if process was killed indirectly', async t => {
test('error.killed is true if process was killed indirectly', async t => {
const cp = execa('forever');

process.kill(cp.pid, 'SIGINT');

// `process.kill()` is emulated by Node.js on Windows
const message = process.platform === 'win32' ? /failed with exit code 1/ : /was killed with SIGINT/;
const error = await t.throwsAsync(cp, {message});
t.false(error.killed);
t.true(error.killed);
});

if (process.platform === 'darwin') {
Expand Down Expand Up @@ -362,6 +361,7 @@ test('error.code is 4', code, 4);

test('timeout kills the process if it times out', async t => {
const error = await t.throwsAsync(execa('forever', {timeout: 1, message: TIMEOUT_REGEXP}));
t.false(error.killed);
t.true(error.timedOut);
});

Expand Down

0 comments on commit 2cdbfdf

Please sign in to comment.