Skip to content

Commit

Permalink
Make error.killed more consistent (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored and sindresorhus committed May 14, 2019
1 parent 0097423 commit fd064a7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Expand Up @@ -113,7 +113,8 @@ try {
stderr: null,
failed: true,
timedOut: false,
isCanceled: false
isCanceled: false,
killed: false
}
*/
}
Expand Down
20 changes: 18 additions & 2 deletions test.js
Expand Up @@ -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');
});

Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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);
});

Expand Down

0 comments on commit fd064a7

Please sign in to comment.