Skip to content
Myr

Make `error.killed` and `error.isCanceled` always boolean (not `undefined`) (#229)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by Sindre Sorhus · parent 5f8bd52 · Browse files · 2 files+38 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+38 added−4 removed

  • other:+38 added−4 removed

2 files+38 added−4 removed

modified:index.js+7 added-3 removed
194 unmodified lines
195 // `signal` emitted on `spawned.on('exit')` event can be `null`. We normalize196 // it to `undefined`197 error.signal = signal || undefined;198 error.command = joinedCommand;199 error.timedOut = Boolean(timedOut);199 error.timedOut = timedOut;200 error.isCanceled = isCanceled;201202 if ('all' in result) {203 error.all = result.all;
244 unmodified lines
448449 if (result.error || result.status !== 0 || result.signal !== null) {450 const error = makeError(result, {451 joinedCommand,452 parsed452 parsed,453 timedOut: false,454 isCanceled: false455 });456457 if (!parsed.options.reject) {458 return error;
8 unmodified lines
467 code: 0,468 exitCode: 0,469 exitCodeName: 'SUCCESS',470 failed: false,471 killed: false,472 command: joinedCommand,470 timedOut: false473 timedOut: false,474 isCanceled: false475 };476};
modified:test.js+31 added-1 removed
303 unmodified lines
304 const error = await t.throwsAsync(cp, {message});305 t.false(error.killed);306});307308test('result.killed is false if not killed', async t => {309 const result = await execa('noop');310 t.false(result.killed);311});312313test('result.killed is false if not killed, in sync mode', t => {314 const result = execa.sync('noop');315 t.false(result.killed);316});317318if (process.platform === 'darwin') {319 test.cb('sanity check: child_process.exec also has killed.false if killed indirectly', t => {320 const cp = childProcess.exec('forever', error => {321 t.truthy(error);
62 unmodified lines
384 const result = await execa('noop');385 t.false(result.timedOut);386});387388test('timedOut will be false if no timeout was set and zero exit code in sync mode', t => {389 const result = execa.sync('noop');390 t.false(result.timedOut);391});392393async function errorMessage(t, expected, ...args) {394 await t.throwsAsync(execa('exit', args), {message: expected});395}396
195 unmodified lines
592 subprocess.cancel();593 t.true(subprocess.killed);594});595581test('result.isCanceled is false when spawned.cancel isn\'t called', async t => {596test('result.isCanceled is false when spawned.cancel() isn\'t called (success)', async t => {597 const result = await execa('noop');598 t.false(result.isCanceled);599});600601test('result.isCanceled is false when spawned.cancel() isn\'t called (failure)', async t => {602 const error = await t.throwsAsync(execa('fail'));603 t.false(error.isCanceled);604});605606test('result.isCanceled is false when spawned.cancel() isn\'t called in sync mode (success)', t => {607 const result = execa.sync('noop');608 t.false(result.isCanceled);609});610611test('result.isCanceled is false when spawned.cancel() isn\'t called in sync mode (failure)', t => {612 const error = t.throws(() => execa.sync('fail'));613 t.false(error.isCanceled);614});615616test('calling cancel method throws an error with message "Command was canceled"', async t => {617 const subprocess = execa('noop');618 subprocess.cancel();619 await t.throwsAsync(subprocess, {message: /Command was canceled/});
38 unmodified lines