kill-descendants.js
This file
Path
test/terminate/kill-descendants.js
318 lines · 11.0 KiB · JavaScript
Last changed by
Report `null` pipe options as a rejectionSindre Sorhusbefore adoptionecda56b
History of this fileTake it
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 2–4why, one step back2import childProcess from 'node:child_process';3import {syncBuiltinESMExports} from 'node:module';4import path from 'node:path/win32';Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
lines 5–6why, one step back5import process from 'node:process';6import {setTimeout} from 'node:timers/promises';TweaksSindre Sorhusbefore adoption698a1b8
line 7why, one step back7import test from 'node:test';Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
line 8why, one step back8import isRunning from 'is-running';TweaksSindre Sorhusbefore adoption698a1b8
line 9why, one step back9import {assertThrows, assertRejects} from '../helpers/assert.js';Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
line 10why, one step back10import {execa, execaSync} from '../../index.js';Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 11why, one step back11import {getTaskkillFile} from '../../lib/terminate/kill-descendants.js';Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
lines 12–36why, one step back12import {setFixtureDirectory} from '../helpers/fixtures-directory.js';1314setFixtureDirectory();1516const isWindows = process.platform === 'win32';1718const pollForSubprocessExit = async pid => {19 while (isRunning(pid)) {20 // eslint-disable-next-line no-await-in-loop21 await setTimeout(100);22 }23};2425// `ipc-send-pid.js` spawns a descendant process (`forever.js`) and sends back its PID.26const spawnDescendant = async (killDescendants, options) => {27 const subprocess = execa('ipc-send-pid.js', ['false', 'false'], {28 stdio: 'ignore',29 ipc: true,30 killDescendants,31 ...options,32 });33 const descendantPid = await subprocess.getOneMessage();34 return {subprocess, descendantPid};35};36TweaksSindre Sorhusbefore adoption698a1b8
line 37why, one step back37test('killDescendants terminates descendant processes', async () => {Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
line 38why, one step back38 const {subprocess, descendantPid} = await spawnDescendant(true);TweaksSindre Sorhusbefore adoption698a1b8
line 39why, one step back39 assert.ok(isRunning(descendantPid));Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
lines 40–41why, one step back4041 subprocess.kill();TweaksSindre Sorhusbefore adoption698a1b8
lines 42–43why, one step back42 await assertRejects(subprocess);43 assert.ok(!isRunning(subprocess.pid));Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
lines 44–48why, one step back4445 await Promise.race([46 setTimeout(1e4, undefined, {ref: false}),47 pollForSubprocessExit(descendantPid),48 ]);TweaksSindre Sorhusbefore adoption698a1b8
line 49why, one step back49 assert.ok(!isRunning(descendantPid));Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
lines 50–51why, one step back50});51TweaksSindre Sorhusbefore adoption698a1b8
line 52why, one step back52test('killDescendants also terminates descendant processes when the subprocess times out', async () => {Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
line 53why, one step back53 const {subprocess, descendantPid} = await spawnDescendant(true, {timeout: 1000});TweaksSindre Sorhusbefore adoption698a1b8
line 54why, one step back54 assert.ok(isRunning(descendantPid));Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
line 55why, one step back55TweaksSindre Sorhusbefore adoption698a1b8
lines 56–57why, one step back56 const {timedOut} = await assertRejects(subprocess);57 assert.equal(timedOut, true);Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
lines 58–62why, one step back5859 await Promise.race([60 setTimeout(1e4, undefined, {ref: false}),61 pollForSubprocessExit(descendantPid),62 ]);TweaksSindre Sorhusbefore adoption698a1b8
line 63why, one step back63 assert.ok(!isRunning(descendantPid));Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
lines 64–68why, one step back64});6566// On Windows, terminating the direct subprocess already terminates its descendants, so this67// only asserts the default Unix behavior of leaving descendants running.68if (!isWindows) {TweaksSindre Sorhusbefore adoption698a1b8
line 69why, one step back69 test('descendant processes are not terminated without killDescendants', async () => {Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
line 70why, one step back70 const {subprocess, descendantPid} = await spawnDescendant(false);TweaksSindre Sorhusbefore adoption698a1b8
line 71why, one step back71 assert.ok(isRunning(descendantPid));Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
lines 72–73why, one step back7273 subprocess.kill();TweaksSindre Sorhusbefore adoption698a1b8
lines 74–75why, one step back74 await assertRejects(subprocess);75 assert.ok(!isRunning(subprocess.pid));Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
line 76why, one step back76TweaksSindre Sorhusbefore adoption698a1b8
line 77why, one step back77 assert.ok(isRunning(descendantPid));Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
lines 78–80why, one step back78 process.kill(descendantPid, 'SIGKILL');79 });80TweaksSindre Sorhusbefore adoption698a1b8
line 81why, one step back81 test('timeout does not terminate descendants without killDescendants', async () => {Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
line 82why, one step back82 const {subprocess, descendantPid} = await spawnDescendant(false, {timeout: 1000});TweaksSindre Sorhusbefore adoption698a1b8
line 83why, one step back83 assert.ok(isRunning(descendantPid));Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
line 84why, one step back84TweaksSindre Sorhusbefore adoption698a1b8
lines 85–87why, one step back85 const {timedOut} = await assertRejects(subprocess);86 assert.equal(timedOut, true);87 assert.ok(isRunning(descendantPid));Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
lines 88–91why, one step back88 process.kill(descendantPid, 'SIGKILL');89 });90}91Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 92–96why, one step back92/*93The `forceKillAfterDelay` escalation happens after the subprocess exited, since that is when its termination has been noticed.94A descendant which ignores `SIGTERM` is still running then, so the escalation must still reach it.95Otherwise, since that descendant keeps the subprocess' `stdout` open, awaiting the subprocess would never settle.96*/TweaksSindre Sorhusbefore adoption698a1b8
line 97why, one step back97test('killDescendants escalates to descendants which outlive the subprocess', async () => {Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 98–103why, one step back98 const subprocess = execa('ipc-send-pid-stubborn.js', {99 ipc: true,100 killDescendants: true,101 forceKillAfterDelay: 1000,102 });103 const descendantPid = await subprocess.getOneMessage();TweaksSindre Sorhusbefore adoption698a1b8
line 104why, one step back104 assert.ok(isRunning(descendantPid));Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 105–107why, one step back105106 subprocess.kill();107 const settled = await Promise.race([TweaksSindre Sorhusbefore adoption698a1b8
line 108why, one step back108 assertRejects(subprocess).then(() => 'settled'),Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 109–110why, one step back109 setTimeout(1e4, 'pending', {ref: false}),110 ]);TweaksSindre Sorhusbefore adoption698a1b8
lines 111–112why, one step back111 assert.equal(settled, 'settled');112 assert.ok(!isRunning(descendantPid));Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 113–115why, one step back113});114115if (!isWindows) {TweaksSindre Sorhusbefore adoption698a1b8
lines 116–120why, one step back116 // The process group ID stays reserved while a descendant is running, so the descendants which outlive the subprocess can still be terminated once Execa is done with it117 test('killDescendants terminates background descendants once Execa is done with the subprocess', async () => {118 const subprocess = execa({shell: true, killDescendants: true})`sleep 100 > /dev/null 2>&1 & echo $!`;119 const {stdout} = await subprocess;120 const descendantPid = Number(stdout);Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
line 121why, one step back121TweaksSindre Sorhusbefore adoption698a1b8
lines 122–124why, one step back122 try {123 assert.ok(isRunning(descendantPid));124 assert.ok(subprocess.kill());Report `null` pipe options as a rejectionSindre Sorhusbefore adoptionecda56b
lines 125–129why, one step back125 await Promise.race([126 setTimeout(1e4, undefined, {ref: false}),127 pollForSubprocessExit(descendantPid),128 ]);129 assert.ok(!isRunning(descendantPid));TweaksSindre Sorhusbefore adoption698a1b8
lines 130–134why, one step back130 } finally {131 if (isRunning(descendantPid)) {132 process.kill(descendantPid, 'SIGKILL');133 }134 }Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 135–136why, one step back135 });136TweaksSindre Sorhusbefore adoption698a1b8
lines 137–141why, one step back137 // Once the whole process group exited, its PID is not signaled since `process.kill()` fails138 test('killDescendants returns false once the whole process group exited', async () => {139 const subprocess = execa('empty.js', {killDescendants: true});140 await subprocess;141 assert.equal(subprocess.kill(), false);Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 142–144why, one step back142 });143144 // While Execa is still waiting on the subprocess, its process group is still its ownTweaksSindre Sorhusbefore adoption698a1b8
line 145why, one step back145 test('killDescendants signals the process group while Execa is not done with the subprocess', async t => {Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 146–148why, one step back146 const subprocess = execa('forever.js', {killDescendants: true});147148 const originalKill = process.kill;TweaksSindre Sorhusbefore adoption698a1b8
line 149why, one step back149 t.after(() => {Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 150–158why, one step back150 process.kill = originalKill;151 });152153 const signaledProcesses = [];154 process.kill = (pid, signal) => {155 signaledProcesses.push([pid, signal]);156 return originalKill(pid, signal);157 };158TweaksSindre Sorhusbefore adoption698a1b8
lines 159–160why, one step back159 assert.ok(subprocess.kill('SIGTERM'));160 assert.deepEqual(signaledProcesses, [[-subprocess.pid, 'SIGTERM']]);Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
line 161why, one step back161 process.kill = originalKill;TweaksSindre Sorhusbefore adoption698a1b8
line 162why, one step back162 await assertRejects(subprocess);Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 163–165why, one step back163 });164}165TweaksSindre Sorhusbefore adoption698a1b8
lines 166–167why, one step back166test('Cannot use "killDescendants" option, sync', () => {167 assertThrows(() => {Add `killDescendants` option to also terminate descendant processes (#1256)Sindre Sorhusbefore adoption84fa0ec
lines 168–170why, one step back168 execaSync('empty.js', {killDescendants: true});169 }, {message: /The "killDescendants: true" option cannot be used/});170});Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 171why, one step back171TweaksSindre Sorhusbefore adoption698a1b8
line 172why, one step back172test('taskkill is resolved from the Windows directory when available', t => {Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 173why, one step back173 const {SystemRoot, windir} = process.env;TweaksSindre Sorhusbefore adoption698a1b8
line 174why, one step back174 t.after(() => {Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 175–180why, one step back175 restoreEnvironment('SystemRoot', SystemRoot);176 restoreEnvironment('windir', windir);177 });178179 process.env.SystemRoot = 'C:\\Windows';180 process.env.windir = 'D:\\Windows';TweaksSindre Sorhusbefore adoption698a1b8
line 181why, one step back181 assert.equal(getTaskkillFile(), path.join('C:\\Windows', 'System32', 'taskkill.exe'));Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 182–183why, one step back182183 process.env.SystemRoot = 'C:/Windows';TweaksSindre Sorhusbefore adoption698a1b8
line 184why, one step back184 assert.equal(getTaskkillFile(), path.join('C:/Windows', 'System32', 'taskkill.exe'));Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 185–186why, one step back185186 process.env.SystemRoot = 'Windows';TweaksSindre Sorhusbefore adoption698a1b8
line 187why, one step back187 assert.equal(getTaskkillFile(), path.join('D:\\Windows', 'System32', 'taskkill.exe'));Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 188–189why, one step back188189 process.env.SystemRoot = '\\Windows';TweaksSindre Sorhusbefore adoption698a1b8
line 190why, one step back190 assert.equal(getTaskkillFile(), path.join('D:\\Windows', 'System32', 'taskkill.exe'));Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 191–192why, one step back191192 delete process.env.SystemRoot;TweaksSindre Sorhusbefore adoption698a1b8
line 193why, one step back193 assert.equal(getTaskkillFile(), path.join('D:\\Windows', 'System32', 'taskkill.exe'));Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 194–195why, one step back194195 process.env.windir = 'Windows';TweaksSindre Sorhusbefore adoption698a1b8
line 196why, one step back196 assert.equal(getTaskkillFile(), undefined);Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 197–198why, one step back197198 process.env.windir = '\\Windows';TweaksSindre Sorhusbefore adoption698a1b8
line 199why, one step back199 assert.equal(getTaskkillFile(), undefined);Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 200–201why, one step back200201 process.env.windir = '\\\\server\\share\\Windows';TweaksSindre Sorhusbefore adoption698a1b8
line 202why, one step back202 assert.equal(getTaskkillFile(), undefined);Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 203–204why, one step back203204 process.env.windir = '';TweaksSindre Sorhusbefore adoption698a1b8
line 205why, one step back205 assert.equal(getTaskkillFile(), undefined);Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 206–207why, one step back206207 delete process.env.windir;TweaksSindre Sorhusbefore adoption698a1b8
line 208why, one step back208 assert.equal(getTaskkillFile(), undefined);Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 209–210why, one step back209});210Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 211–217why, one step back211/*212The `taskkill` logic only runs on Windows, so the platform, the Windows directory and `taskkill` itself are faked to test it on any OS.213`lib/terminate/kill-descendants.js` reads `process.platform` when it is loaded, so it must be re-imported once the platform has been faked.214*/215let fakeWindowsCount = 0;216217const fakeWindows = async (t, systemRoot, execFile = () => {}) => {Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 218why, one step back218 const platformDescriptor = Object.getOwnPropertyDescriptor(process, 'platform');Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
line 219why, one step back219 const originalExecFile = childProcess.execFile;Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 220why, one step back220 const {SystemRoot, windir} = process.env;TweaksSindre Sorhusbefore adoption698a1b8
line 221why, one step back221 t.after(() => {Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 222why, one step back222 Object.defineProperty(process, 'platform', platformDescriptor);Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 223–224why, one step back223 childProcess.execFile = originalExecFile;224 syncBuiltinESMExports();Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 225–229why, one step back225 restoreEnvironment('SystemRoot', SystemRoot);226 restoreEnvironment('windir', windir);227 });228229 Object.defineProperty(process, 'platform', {value: 'win32'});Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
line 230why, one step back230 process.env.SystemRoot = systemRoot;Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 231why, one step back231 delete process.env.windir;Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 232–233why, one step back232 childProcess.execFile = execFile;233 syncBuiltinESMExports();Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 234why, one step back234Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 235–241why, one step back235 fakeWindowsCount += 1;236 const {getKillFunction} = await import(`../../lib/terminate/kill-descendants.js?fake-windows=${fakeWindowsCount}`);237 return getKillFunction;238};239240// Mimics the `ChildProcess` properties used to send the signal and to detect whether the subprocess is still running241const createFakeSubprocess = ({exitCode = null, signalCode = null} = {}) => {Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 242–243why, one step back242 const subprocess = {243 pid: 123,Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 244–245why, one step back244 exitCode,245 signalCode,Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 246why, one step back246 kill(signal) {Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
line 247why, one step back247 subprocess.killedWith = signal;Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 248–250why, one step back248 return true;249 },250 };Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 251–252why, one step back251 return subprocess;252};Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 253why, one step back253TweaksSindre Sorhusbefore adoption698a1b8
line 254why, one step back254test('taskkill fallback uses direct subprocess kill when Windows directory is unavailable', async t => {Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 255–257why, one step back255 const getKillFunction = await fakeWindows(t, 'Windows');256 const subprocess = createFakeSubprocess();257TweaksSindre Sorhusbefore adoption698a1b8
lines 258–260why, one step back258 const kill = getKillFunction(subprocess, {killDescendants: true});259 assert.ok(kill('SIGTERM'));260 assert.equal(subprocess.killedWith, 'SIGTERM');Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 261–262why, one step back261});262TweaksSindre Sorhusbefore adoption698a1b8
line 263why, one step back263test('taskkill fallback uses direct subprocess kill when taskkill cannot be spawned', async t => {Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 264why, one step back264 const taskkillFailure = Promise.withResolvers();Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
line 265why, one step back265 const getKillFunction = await fakeWindows(t, 'C:\\MissingWindows', (file, arguments_, callback) => {TweaksSindre Sorhusbefore adoption698a1b8
lines 266–267why, one step back266 assert.equal(file, path.join('C:\\MissingWindows', 'System32', 'taskkill.exe'));267 assert.deepEqual(arguments_, ['/pid', '123', '/T', '/F']);Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 268–271why, one step back268 queueMicrotask(() => {269 callback(new Error('spawn failed'));270 taskkillFailure.resolve();271 });Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 272–273why, one step back272 });273 const subprocess = createFakeSubprocess();Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 274why, one step back274TweaksSindre Sorhusbefore adoption698a1b8
lines 275–277why, one step back275 const kill = getKillFunction(subprocess, {killDescendants: true});276 assert.ok(kill('SIGTERM'));277 assert.equal(subprocess.killedWith, undefined);Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 278why, one step back278Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
line 279why, one step back279 await taskkillFailure.promise;TweaksSindre Sorhusbefore adoption698a1b8
line 280why, one step back280 assert.equal(subprocess.killedWith, 'SIGTERM');Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
line 281why, one step back281});Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
line 282why, one step back282TweaksSindre Sorhusbefore adoption698a1b8
lines 283–284why, one step back283// On Windows, the PID is not reserved anymore once the subprocess exited, even while Execa is still waiting on it284test('taskkill is not spawned once the subprocess exited', async t => {Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 285–290why, one step back285 let isTaskkillSpawned = false;286 const getKillFunction = await fakeWindows(t, 'C:\\Windows', () => {287 isTaskkillSpawned = true;288 });289 const subprocess = createFakeSubprocess({exitCode: 0});290TweaksSindre Sorhusbefore adoption698a1b8
lines 291–294why, one step back291 const kill = getKillFunction(subprocess, {killDescendants: true});292 assert.equal(kill('SIGTERM'), false);293 assert.equal(isTaskkillSpawned, false);294 assert.equal(subprocess.killedWith, undefined);Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 295–297why, one step back295});296297// A subprocess which never spawned has no PID to signalTweaksSindre Sorhusbefore adoption698a1b8
line 298why, one step back298test('taskkill is not spawned when the subprocess has no PID', async t => {Fix `killDescendants` signaling unrelated processes once Execa is done with the subprocessSindre Sorhusbefore adoption9c5c71c
lines 299–305why, one step back299 let isTaskkillSpawned = false;300 const getKillFunction = await fakeWindows(t, 'C:\\Windows', () => {301 isTaskkillSpawned = true;302 });303 const subprocess = createFakeSubprocess();304 subprocess.pid = undefined;305TweaksSindre Sorhusbefore adoption698a1b8
lines 306–309why, one step back306 const kill = getKillFunction(subprocess, {killDescendants: true});307 assert.equal(kill('SIGTERM'), false);308 assert.equal(isTaskkillSpawned, false);309 assert.equal(subprocess.killedWith, undefined);Improve `taskkill` usage (#1258)Sindre Sorhusbefore adoption3d9d820
lines 310–318why, one step back310});311312const restoreEnvironment = (name, value) => {313 if (value === undefined) {314 delete process.env[name];315 } else {316 process.env[name] = value;317 }318};