From 1731cdb0459dced04859c5e331e2f94d4623d317 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 14 May 2019 17:36:58 +0200 Subject: [PATCH 1/4] Make error.killed more consistent --- index.js | 2 +- test.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 303537d95..80deaff51 100644 --- a/index.js +++ b/index.js @@ -195,7 +195,7 @@ function makeError(result, options) { error.failed = true; error.timedOut = timedOut; error.isCanceled = isCanceled; - error.killed = killed && !timedOut; + error.killed = Boolean(killed) && !timedOut; // `signal` emitted on `spawned.on('exit')` event can be `null`. We normalize // it to `undefined` error.signal = signal || undefined; diff --git a/test.js b/test.js index 957976433..0130de02a 100644 --- a/test.js +++ b/test.js @@ -318,6 +318,16 @@ 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 => { From 992e978b3aaa417e816908330bff18640cb77d0d Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 14 May 2019 17:39:51 +0200 Subject: [PATCH 2/4] Fix README --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 } */ } From e919ed6c08d9353e210cc1feba16c71e2aad32e6 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 14 May 2019 17:45:12 +0200 Subject: [PATCH 3/4] Improve error.killed for sync() --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 80deaff51..1ca516a85 100644 --- a/index.js +++ b/index.js @@ -195,7 +195,7 @@ function makeError(result, options) { error.failed = true; error.timedOut = timedOut; error.isCanceled = isCanceled; - error.killed = Boolean(killed) && !timedOut; + error.killed = killed && !timedOut; // `signal` emitted on `spawned.on('exit')` event can be `null`. We normalize // it to `undefined` error.signal = signal || undefined; @@ -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) { From 124a2caaa07d7d1c2e42c11facaff19fe16f4995 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 14 May 2019 19:06:59 +0200 Subject: [PATCH 4/4] Use different arrow function style --- test.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test.js b/test.js index 0130de02a..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'); }); @@ -324,7 +326,9 @@ test('result.killed is false on process error', async t => { }); test('result.killed is false on process error, in sync mode', t => { - const {killed} = t.throws(() => execa.sync('wrong command')); + const {killed} = t.throws(() => { + execa.sync('wrong command'); + }); t.false(killed); }); @@ -623,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); });