From fd064a7be22b536c1e8214094b087a36767d73ff Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 14 May 2019 10:24:47 -0700 Subject: [PATCH] Make `error.killed` more consistent (#248) --- index.js | 3 ++- readme.md | 3 ++- test.js | 20 ++++++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 303537d95..1ca516a85 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 d735f0143..1b3ca69b6 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 957976433..bcc850aac 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); });