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
Provenance
- Commit
bb36e6d- Tree
d474200- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
5f8bd52
2 files changed+38 added−4 removed
modified:index.js+7 added-3 removed
194 unmodified lines195 // `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;201 202 if ('all' in result) {203 error.all = result.all;244 unmodified lines448 449 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 });456 457 if (!parsed.options.reject) {458 return error;8 unmodified lines467 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 lines304 const error = await t.throwsAsync(cp, {message});305 t.false(error.killed);306 });307 308+test('result.killed is false if not killed', async t => {309+ const result = await execa('noop');310+ t.false(result.killed);311+});312+313+test('result.killed is false if not killed, in sync mode', t => {314+ const result = execa.sync('noop');315+ t.false(result.killed);316+});317+318 if (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 lines384 const result = await execa('noop');385 t.false(result.timedOut);386 });387 388+test('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+});392+393 async function errorMessage(t, expected, ...args) {394 await t.throwsAsync(execa('exit', args), {message: expected});395 }396 195 unmodified lines592 subprocess.cancel();593 t.true(subprocess.killed);594 });595 581-test('result.isCanceled is false when spawned.cancel isn\'t called', async t => {596+test('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 });600 601+test('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+});605+606+test('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+});610+611+test('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+});615+616 test('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