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 and error.isCanceled always boolean (not undefined) #229

Merged
merged 1 commit into from May 10, 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
10 changes: 7 additions & 3 deletions index.js
Expand Up @@ -196,7 +196,7 @@ function makeError(result, options) {
// it to `undefined`
error.signal = signal || undefined;
error.command = joinedCommand;
error.timedOut = Boolean(timedOut);
error.timedOut = timedOut;
error.isCanceled = isCanceled;

if ('all' in result) {
Expand Down Expand Up @@ -449,7 +449,9 @@ module.exports.sync = (command, args, options) => {
if (result.error || result.status !== 0 || result.signal !== null) {
const error = makeError(result, {
joinedCommand,
parsed
parsed,
timedOut: false,
isCanceled: false
});

if (!parsed.options.reject) {
Expand All @@ -466,7 +468,9 @@ module.exports.sync = (command, args, options) => {
exitCode: 0,
exitCodeName: 'SUCCESS',
failed: false,
killed: false,
command: joinedCommand,
timedOut: false
timedOut: false,
isCanceled: false
};
};
32 changes: 31 additions & 1 deletion test.js
Expand Up @@ -305,6 +305,16 @@ test('error.killed is false if process was killed indirectly', async t => {
t.false(error.killed);
});

test('result.killed is false if not killed', async t => {
const result = await execa('noop');
t.false(result.killed);
});

test('result.killed is false if not killed, in sync mode', t => {
const result = execa.sync('noop');
t.false(result.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 @@ -375,6 +385,11 @@ test('timedOut is false if no timeout was set', async t => {
t.false(result.timedOut);
});

test('timedOut will be false if no timeout was set and zero exit code in sync mode', t => {
const result = execa.sync('noop');
t.false(result.timedOut);
});

async function errorMessage(t, expected, ...args) {
await t.throwsAsync(execa('exit', args), {message: expected});
}
Expand Down Expand Up @@ -578,11 +593,26 @@ test('cancel method kills the subprocess', t => {
t.true(subprocess.killed);
});

test('result.isCanceled is false when spawned.cancel isn\'t called', async t => {
test('result.isCanceled is false when spawned.cancel() isn\'t called (success)', async t => {
const result = await execa('noop');
t.false(result.isCanceled);
});

test('result.isCanceled is false when spawned.cancel() isn\'t called (failure)', async t => {
const error = await t.throwsAsync(execa('fail'));
t.false(error.isCanceled);
});

test('result.isCanceled is false when spawned.cancel() isn\'t called in sync mode (success)', t => {
const result = execa.sync('noop');
t.false(result.isCanceled);
});

test('result.isCanceled is false when spawned.cancel() isn\'t called in sync mode (failure)', t => {
const error = t.throws(() => execa.sync('fail'));
t.false(error.isCanceled);
});

test('calling cancel method throws an error with message "Command was canceled"', async t => {
const subprocess = execa('noop');
subprocess.cancel();
Expand Down