diff --git a/index.js b/index.js index dc0f983c50..aea21445cc 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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; } diff --git a/test.js b/test.js index 5d7a4b41a4..3b7429adef 100644 --- a/test.js +++ b/test.js @@ -293,8 +293,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'); process.kill(cp.pid, 'SIGINT'); @@ -302,7 +301,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') { @@ -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); });