From 93bbe09c20f41754fe081c3b9bda0f34f7c43b95 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Fri, 10 May 2019 12:17:33 +0200 Subject: [PATCH] Improve error.killed --- index.js | 6 +----- test.js | 7 ++++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index de3f22b6b4..4f6702d828 100644 --- a/index.js +++ b/index.js @@ -194,6 +194,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; @@ -366,11 +367,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 c95b31d011..7a8919d807 100644 --- a/test.js +++ b/test.js @@ -330,8 +330,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'); setTimeout(() => { @@ -341,7 +340,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') { @@ -411,6 +410,7 @@ test.serial('timeout will kill the process early', async t => { const diff = Date.now() - time; t.true(error.timedOut); + t.false(error.killed); t.not(error.exitCode, 22); t.true(diff < 4000); }); @@ -421,6 +421,7 @@ test.serial('timeout will kill the process early (sleep)', async t => { const diff = Date.now() - time; t.true(error.timedOut); + t.false(error.killed); t.not(error.stdout, 'ok'); t.true(diff < 4000); });