diff --git a/index.js b/index.js index dc0f983c5..84d1c484e 100644 --- a/index.js +++ b/index.js @@ -173,7 +173,7 @@ function getStream(process, stream, {encoding, buffer, maxBuffer}) { function makeError(result, options) { const {stdout, stderr, code, signal} = result; let {error} = result; - const {joinedCommand, timedOut, isCanceled, parsed: {options: {timeout}}} = options; + const {joinedCommand, timedOut, isCanceled, killed, parsed: {options: {timeout}}} = options; const [exitCodeName, exitCode] = getCode(result, code); @@ -198,6 +198,7 @@ function makeError(result, options) { error.command = joinedCommand; error.timedOut = Boolean(timedOut); error.isCanceled = isCanceled; + error.killed = killed && !timedOut; if ('all' in result) { error.all = result.all; @@ -364,14 +365,10 @@ const execa = (command, args, options) => { joinedCommand, parsed, timedOut, - isCanceled + isCanceled, + killed: spawned.killed }); - // 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 5d7a4b41a..9f44b645c 100644 --- a/test.js +++ b/test.js @@ -293,7 +293,6 @@ 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 => { const cp = execa('forever'); @@ -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); });