Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make error.killed more consistent #248

Merged
merged 4 commits into from May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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