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 2438df2 commit c5cb96c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 1 addition & 5 deletions index.js
Expand Up @@ -194,6 +194,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 @@ -366,11 +367,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
7 changes: 4 additions & 3 deletions test.js
Expand Up @@ -330,8 +330,7 @@ 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');

setTimeout(() => {
Expand All @@ -341,7 +340,7 @@ test('error.killed is false if process was killed indirectly', async t => {
// `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 @@ -411,6 +410,7 @@ test.serial('timeout will kill the process early', async t => {
const diff = Date.now() - time;

t.true(error.timedOut);
t.false(error.killed);
t.not(error.exitCode, 22);
t.true(diff < 4000);
});
Expand All @@ -421,6 +421,7 @@ test.serial('timeout will kill the process early (sleep)', async t => {
const diff = Date.now() - time;

t.true(error.timedOut);
t.false(error.killed);
t.not(error.stdout, 'ok');
t.true(diff < 4000);
});
Expand Down

0 comments on commit c5cb96c

Please sign in to comment.