cancel.js
This file
Path
test/terminate/cancel.js
218 lines · 9.4 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
line 2why, one step back2import {once, getEventListeners} from 'node:events';TweaksSindre Sorhusbefore adoption698a1b8
lines 3–4why, one step back3import test from 'node:test';4import {assertThrows, assertRejects} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 5–6why, one step back5import {execa, execaSync} from '../../index.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
line 7why, one step back7import {foobarString} from '../helpers/input.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 8–10why, one step back89setFixtureDirectory();10TweaksSindre Sorhusbefore adoption698a1b8
lines 11–12why, one step back11const testValidCancelSignal = cancelSignal => {12 assertThrows(() => {Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 13–16why, one step back13 execa('empty.js', {cancelSignal});14 }, {message: /must be an AbortSignal/});15};16TweaksSindre Sorhusbefore adoption698a1b8
lines 17–20why, one step back17test('cancelSignal option cannot be AbortController', () => testValidCancelSignal(new AbortController()));18test('cancelSignal option cannot be {}', () => testValidCancelSignal({}));19test('cancelSignal option cannot be null', () => testValidCancelSignal(null));20test('cancelSignal option cannot be a symbol', () => testValidCancelSignal(Symbol('test')));Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
line 21why, one step back21TweaksSindre Sorhusbefore adoption698a1b8
line 22why, one step back22test('result.isCanceled is false when abort isn\'t called (success)', async () => {Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5
line 23why, one step back23 const {isCanceled, isGracefullyCanceled} = await execa('noop.js');TweaksSindre Sorhusbefore adoption698a1b8
lines 24–25why, one step back24 assert.equal(isCanceled, false);25 assert.equal(isGracefullyCanceled, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 26–27why, one step back26});27TweaksSindre Sorhusbefore adoption698a1b8
lines 28–31why, one step back28test('result.isCanceled is false when abort isn\'t called (failure)', async () => {29 const {isCanceled, isGracefullyCanceled} = await assertRejects(execa('fail.js'));30 assert.equal(isCanceled, false);31 assert.equal(isGracefullyCanceled, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 32–33why, one step back32});33TweaksSindre Sorhusbefore adoption698a1b8
line 34why, one step back34test('result.isCanceled is false when abort isn\'t called in sync mode (success)', () => {Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5
line 35why, one step back35 const {isCanceled, isGracefullyCanceled} = execaSync('noop.js');TweaksSindre Sorhusbefore adoption698a1b8
lines 36–37why, one step back36 assert.equal(isCanceled, false);37 assert.equal(isGracefullyCanceled, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 38–39why, one step back38});39TweaksSindre Sorhusbefore adoption698a1b8
lines 40–41why, one step back40test('result.isCanceled is false when abort isn\'t called in sync mode (failure)', () => {41 const {isCanceled, isGracefullyCanceled} = assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 42–43why, one step back42 execaSync('fail.js');43 });TweaksSindre Sorhusbefore adoption698a1b8
lines 44–45why, one step back44 assert.equal(isCanceled, false);45 assert.equal(isGracefullyCanceled, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 46–47why, one step back46});47TweaksSindre Sorhusbefore adoption698a1b8
line 48why, one step back48const testCancelSuccess = async options => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 49why, one step back49 const abortController = new AbortController();Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5
line 50why, one step back50 const subprocess = execa('noop.js', {cancelSignal: abortController.signal, ...options});100% test coverage (#1018)ehmickybefore adoption9f65b86
line 51why, one step back51 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
lines 52–54why, one step back52 const {isCanceled, isGracefullyCanceled} = await assertRejects(subprocess);53 assert.equal(isCanceled, true);54 assert.equal(isGracefullyCanceled, false);Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5
line 55why, one step back55};100% test coverage (#1018)ehmickybefore adoption9f65b86
line 56why, one step back56TweaksSindre Sorhusbefore adoption698a1b8
lines 57–60why, one step back57test('error.isCanceled is true when abort is used', () => testCancelSuccess({}));58test('gracefulCancel can be false with cancelSignal', () => testCancelSuccess({gracefulCancel: false}));59test('ipc can be false with cancelSignal', () => testCancelSuccess({ipc: false}));60test('serialization can be "json" with cancelSignal', () => testCancelSuccess({ipc: true, serialization: 'json'}));Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5
line 61why, one step back61TweaksSindre Sorhusbefore adoption698a1b8
line 62why, one step back62test('error.isCanceled is false when kill method is used', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 63–65why, one step back63 const abortController = new AbortController();64 const subprocess = execa('noop.js', {cancelSignal: abortController.signal});65 subprocess.kill();TweaksSindre Sorhusbefore adoption698a1b8
lines 66–68why, one step back66 const {isCanceled, isGracefullyCanceled} = await assertRejects(subprocess);67 assert.equal(isCanceled, false);68 assert.equal(isGracefullyCanceled, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 69–70why, one step back69});70TweaksSindre Sorhusbefore adoption698a1b8
line 71why, one step back71test('calling abort is considered a signal termination', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 72–73why, one step back72 const abortController = new AbortController();73 const subprocess = execa('forever.js', {cancelSignal: abortController.signal});Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 74why, one step back74 await once(subprocess.nodeChildProcess, 'spawn');100% test coverage (#1018)ehmickybefore adoption9f65b86
line 75why, one step back75 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
lines 76–80why, one step back76 const {isCanceled, isGracefullyCanceled, isTerminated, signal} = await assertRejects(subprocess);77 assert.equal(isCanceled, true);78 assert.equal(isGracefullyCanceled, false);79 assert.equal(isTerminated, true);80 assert.equal(signal, 'SIGTERM');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 81–82why, one step back81});82TweaksSindre Sorhusbefore adoption698a1b8
line 83why, one step back83test('cancelSignal can already be aborted', async () => {Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
line 84why, one step back84 const cancelSignal = AbortSignal.abort();TweaksSindre Sorhusbefore adoption698a1b8
lines 85–90why, one step back85 const {isCanceled, isGracefullyCanceled, isTerminated, signal} = await assertRejects(execa('forever.js', {cancelSignal}));86 assert.equal(isCanceled, true);87 assert.equal(isGracefullyCanceled, false);88 assert.equal(isTerminated, true);89 assert.equal(signal, 'SIGTERM');90 assert.deepEqual(getEventListeners(cancelSignal, 'abort'), []);Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 91–92why, one step back91});92TweaksSindre Sorhusbefore adoption698a1b8
line 93why, one step back93test('calling abort does not emit the "error" event', async () => {Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 94–96why, one step back94 const abortController = new AbortController();95 const subprocess = execa('forever.js', {cancelSignal: abortController.signal});96 let error;Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 97why, one step back97 subprocess.nodeChildProcess.once('error', errorArgument => {Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 98–100why, one step back98 error = errorArgument;99 });100 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
lines 101–104why, one step back101 const {isCanceled, isGracefullyCanceled} = await assertRejects(subprocess);102 assert.equal(isCanceled, true);103 assert.equal(isGracefullyCanceled, false);104 assert.equal(error, undefined);Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 105–106why, one step back105});106TweaksSindre Sorhusbefore adoption698a1b8
line 107why, one step back107test('calling abort cleans up listeners on cancelSignal, called', async () => {Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 108–109why, one step back108 const abortController = new AbortController();109 const subprocess = execa('forever.js', {cancelSignal: abortController.signal});TweaksSindre Sorhusbefore adoption698a1b8
line 110why, one step back110 assert.equal(getEventListeners(abortController.signal, 'abort').length, 1);Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
line 111why, one step back111 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
lines 112–115why, one step back112 const {isCanceled, isGracefullyCanceled} = await assertRejects(subprocess);113 assert.equal(isCanceled, true);114 assert.equal(isGracefullyCanceled, false);115 assert.equal(getEventListeners(abortController.signal, 'abort').length, 0);Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 116–117why, one step back116});117TweaksSindre Sorhusbefore adoption698a1b8
line 118why, one step back118test('calling abort cleans up listeners on cancelSignal, not called', async () => {Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 119–120why, one step back119 const abortController = new AbortController();120 const subprocess = execa('noop.js', {cancelSignal: abortController.signal});TweaksSindre Sorhusbefore adoption698a1b8
line 121why, one step back121 assert.equal(getEventListeners(abortController.signal, 'abort').length, 1);Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
line 122why, one step back122 await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 123why, one step back123 assert.equal(getEventListeners(abortController.signal, 'abort').length, 0);Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 124–125why, one step back124});125TweaksSindre Sorhusbefore adoption698a1b8
line 126why, one step back126test('calling abort cleans up listeners on cancelSignal, already aborted', async () => {Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 127–128why, one step back127 const cancelSignal = AbortSignal.abort();128 const subprocess = execa('noop.js', {cancelSignal});TweaksSindre Sorhusbefore adoption698a1b8
lines 129–133why, one step back129 assert.equal(getEventListeners(cancelSignal, 'abort').length, 0);130 const {isCanceled, isGracefullyCanceled} = await assertRejects(subprocess);131 assert.equal(isCanceled, true);132 assert.equal(isGracefullyCanceled, false);133 assert.equal(getEventListeners(cancelSignal, 'abort').length, 0);Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 134–135why, one step back134});135TweaksSindre Sorhusbefore adoption698a1b8
line 136why, one step back136test('calling abort throws an error with message "Command was canceled"', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 137–139why, one step back137 const abortController = new AbortController();138 const subprocess = execa('noop.js', {cancelSignal: abortController.signal});139 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
line 140why, one step back140 await assertRejects(subprocess, {message: /Command was canceled/});Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 141–142why, one step back141});142TweaksSindre Sorhusbefore adoption698a1b8
line 143why, one step back143test('calling abort with no argument keeps error properties', async () => {Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
line 144why, one step back144 const abortController = new AbortController();Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
line 145why, one step back145 const subprocess = execa('empty.js', {cancelSignal: abortController.signal});Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
line 146why, one step back146 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
lines 147–152why, one step back147 const {cause, originalMessage, shortMessage, message} = await assertRejects(subprocess);148 assert.equal(cause.message, 'This operation was aborted');149 assert.equal(cause.name, 'AbortError');150 assert.equal(originalMessage, 'This operation was aborted');151 assert.equal(shortMessage, 'Command was canceled: empty.js\nThis operation was aborted');152 assert.equal(message, 'Command was canceled: empty.js\nThis operation was aborted');Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 153–154why, one step back153});154TweaksSindre Sorhusbefore adoption698a1b8
line 155why, one step back155test('calling abort with an error instance keeps error properties', async () => {Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
line 156why, one step back156 const abortController = new AbortController();Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
line 157why, one step back157 const subprocess = execa('empty.js', {cancelSignal: abortController.signal});Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 158–160why, one step back158 const error = new Error(foobarString);159 error.code = foobarString;160 abortController.abort(error);TweaksSindre Sorhusbefore adoption698a1b8
lines 161–166why, one step back161 const {cause, originalMessage, shortMessage, message, code} = await assertRejects(subprocess);162 assert.equal(cause, error);163 assert.equal(originalMessage, foobarString);164 assert.equal(shortMessage, `Command was canceled: empty.js\n${foobarString}`);165 assert.equal(message, `Command was canceled: empty.js\n${foobarString}`);166 assert.equal(code, foobarString);Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
lines 167–168why, one step back167});168TweaksSindre Sorhusbefore adoption698a1b8
line 169why, one step back169test('calling abort with null keeps error properties', async () => {Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
line 170why, one step back170 const abortController = new AbortController();Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
line 171why, one step back171 const subprocess = execa('empty.js', {cancelSignal: abortController.signal});Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977
line 172why, one step back172 abortController.abort(null);TweaksSindre Sorhusbefore adoption698a1b8
lines 173–177why, one step back173 const {cause, originalMessage, shortMessage, message} = await assertRejects(subprocess);174 assert.equal(cause, null);175 assert.equal(originalMessage, 'null');176 assert.equal(shortMessage, 'Command was canceled: empty.js\nnull');177 assert.equal(message, 'Command was canceled: empty.js\nnull');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 178–179why, one step back178});179TweaksSindre Sorhusbefore adoption698a1b8
line 180why, one step back180test('calling abort twice should show the same behaviour as calling it once', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 181–184why, one step back181 const abortController = new AbortController();182 const subprocess = execa('noop.js', {cancelSignal: abortController.signal});183 abortController.abort();184 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
lines 185–187why, one step back185 const {isCanceled, isGracefullyCanceled} = await assertRejects(subprocess);186 assert.equal(isCanceled, true);187 assert.equal(isGracefullyCanceled, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 188–189why, one step back188});189TweaksSindre Sorhusbefore adoption698a1b8
line 190why, one step back190test('calling abort on a successfully completed subprocess does not make result.isCanceled true', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 191–192why, one step back191 const abortController = new AbortController();192 const subprocess = execa('noop.js', {cancelSignal: abortController.signal});Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5
line 193why, one step back193 const {isCanceled, isGracefullyCanceled} = await subprocess;100% test coverage (#1018)ehmickybefore adoption9f65b86
line 194why, one step back194 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
lines 195–196why, one step back195 assert.equal(isCanceled, false);196 assert.equal(isGracefullyCanceled, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 197–198why, one step back197});198TweaksSindre Sorhusbefore adoption698a1b8
line 199why, one step back199test('Throws when using the former "signal" option name', () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 200why, one step back200 const abortController = new AbortController();TweaksSindre Sorhusbefore adoption698a1b8
line 201why, one step back201 assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 202–205why, one step back202 execa('empty.js', {signal: abortController.signal});203 }, {message: /renamed to "cancelSignal"/});204});205TweaksSindre Sorhusbefore adoption698a1b8
line 206why, one step back206test('Throws when using the former "signal" option name, sync', () => {Fix the "signal" option being silently ignored by synchronous methodsSindre Sorhusbefore adoption59de065
line 207why, one step back207 const abortController = new AbortController();TweaksSindre Sorhusbefore adoption698a1b8
line 208why, one step back208 assertThrows(() => {Fix the "signal" option being silently ignored by synchronous methodsSindre Sorhusbefore adoption59de065
lines 209–212why, one step back209 execaSync('empty.js', {signal: abortController.signal});210 }, {message: /renamed to "cancelSignal"/});211});212TweaksSindre Sorhusbefore adoption698a1b8
line 213why, one step back213test('Cannot use cancelSignal, sync', () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 214why, one step back214 const abortController = new AbortController();TweaksSindre Sorhusbefore adoption698a1b8
line 215why, one step back215 assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 216–218why, one step back216 execaSync('empty.js', {cancelSignal: abortController.signal});217 }, {message: /The "cancelSignal" option cannot be used/});218});