cancel.js
This file
Path
test/exit/cancel.js
92 lines · 3.2 KiB · JavaScript
Last changed by
Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1
History of this fileTake it
Rename `signal` option to `cancelSignal` (#880)ehmickybefore adoption231beaf
lines 1–71why, one step back1import {once} from 'node:events';2import test from 'ava';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';56setFixtureDir();78test('result.isCanceled is false when abort isn\'t called (success)', async t => {9 const {isCanceled} = await execa('noop.js');10 t.false(isCanceled);11});1213test('result.isCanceled is false when abort isn\'t called (failure)', async t => {14 const {isCanceled} = await t.throwsAsync(execa('fail.js'));15 t.false(isCanceled);16});1718test('result.isCanceled is false when abort isn\'t called in sync mode (success)', t => {19 const {isCanceled} = execaSync('noop.js');20 t.false(isCanceled);21});2223test('result.isCanceled is false when abort isn\'t called in sync mode (failure)', t => {24 const {isCanceled} = t.throws(() => {25 execaSync('fail.js');26 });27 t.false(isCanceled);28});2930test('error.isCanceled is true when abort is used', async t => {31 const abortController = new AbortController();32 const subprocess = execa('noop.js', {cancelSignal: abortController.signal});33 abortController.abort();34 const {isCanceled} = await t.throwsAsync(subprocess);35 t.true(isCanceled);36});3738test('error.isCanceled is false when kill method is used', async t => {39 const abortController = new AbortController();40 const subprocess = execa('noop.js', {cancelSignal: abortController.signal});41 subprocess.kill();42 const {isCanceled} = await t.throwsAsync(subprocess);43 t.false(isCanceled);44});4546test('calling abort is considered a signal termination', async t => {47 const abortController = new AbortController();48 const subprocess = execa('forever.js', {cancelSignal: abortController.signal});49 await once(subprocess, 'spawn');50 abortController.abort();51 const {isTerminated, signal} = await t.throwsAsync(subprocess);52 t.true(isTerminated);53 t.is(signal, 'SIGTERM');54});5556test('calling abort throws an error with message "Command was canceled"', async t => {57 const abortController = new AbortController();58 const subprocess = execa('noop.js', {cancelSignal: abortController.signal});59 abortController.abort();60 await t.throwsAsync(subprocess, {message: /Command was canceled/});61});6263test('calling abort twice should show the same behaviour as calling it once', async t => {64 const abortController = new AbortController();65 const subprocess = execa('noop.js', {cancelSignal: abortController.signal});66 abortController.abort();67 abortController.abort();68 const {isCanceled} = await t.throwsAsync(subprocess);69 t.true(isCanceled);70});71Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 72why, one step back72test('calling abort on a successfully completed subprocess does not make result.isCanceled true', async t => {Rename `signal` option to `cancelSignal` (#880)ehmickybefore adoption231beaf
lines 73–82why, one step back73 const abortController = new AbortController();74 const subprocess = execa('noop.js', {cancelSignal: abortController.signal});75 const result = await subprocess;76 abortController.abort();77 t.false(result.isCanceled);78});7980test('Throws when using the former "signal" option name', t => {81 const abortController = new AbortController();82 t.throws(() => {Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1
line 83why, one step back83 execa('empty.js', {signal: abortController.signal});Rename `signal` option to `cancelSignal` (#880)ehmickybefore adoption231beaf
line 84why, one step back84 }, {message: /renamed to "cancelSignal"/});Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1
lines 85–91why, one step back85});8687test('Cannot use cancelSignal, sync', t => {88 const abortController = new AbortController();89 t.throws(() => {90 execaSync('empty.js', {cancelSignal: abortController.signal});91 }, {message: /The "cancelSignal" option cannot be used/});Rename `signal` option to `cancelSignal` (#880)ehmickybefore adoption231beaf
line 92why, one step back92});