diff --git a/index.js b/index.js index 303537d957..1ca516a857 100644 --- a/index.js +++ b/index.js @@ -432,7 +432,8 @@ module.exports.sync = (command, args, options) => { joinedCommand, parsed, timedOut: false, - isCanceled: false + isCanceled: false, + killed: result.signal !== null }); if (!parsed.options.reject) { diff --git a/readme.md b/readme.md index d735f01431..1b3ca69b69 100644 --- a/readme.md +++ b/readme.md @@ -113,7 +113,8 @@ try { stderr: null, failed: true, timedOut: false, - isCanceled: false + isCanceled: false, + killed: false } */ } diff --git a/test.js b/test.js index 9579764332..bcc850aac8 100644 --- a/test.js +++ b/test.js @@ -141,7 +141,9 @@ test('stripFinalNewline in sync mode', t => { }); test('stripFinalNewline in sync mode on failure', t => { - const {stderr} = t.throws(() => execa.sync('noop-throw', ['foo'], {stripFinalNewline: true})); + const {stderr} = t.throws(() => { + execa.sync('noop-throw', ['foo'], {stripFinalNewline: true}); + }); t.is(stderr, 'foo'); }); @@ -318,6 +320,18 @@ test('result.killed is false if not killed, in sync mode', t => { t.false(result.killed); }); +test('result.killed is false on process error', async t => { + const {killed} = await t.throwsAsync(execa('wrong command')); + t.false(killed); +}); + +test('result.killed is false on process error, in sync mode', t => { + const {killed} = t.throws(() => { + execa.sync('wrong command'); + }); + t.false(killed); +}); + if (process.platform === 'darwin') { test.cb('sanity check: child_process.exec also has killed.false if killed indirectly', t => { const cp = childProcess.exec('forever', error => { @@ -613,7 +627,9 @@ test('result.isCanceled is false when spawned.cancel() isn\'t called in sync mod }); test('result.isCanceled is false when spawned.cancel() isn\'t called in sync mode (failure)', t => { - const error = t.throws(() => execa.sync('fail')); + const error = t.throws(() => { + execa.sync('fail'); + }); t.false(error.isCanceled); });