Skip to content

Commit 03ea532

Browse files
committed
fixup! refactor: remove tree-kill dependency and refactor killAllProcesses to use native childProc.kill with retries.
1 parent 57de940 commit 03ea532

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

tests/e2e/utils/process.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export async function waitForAnyProcessOutputToMatch(
254254
return matchingProcess;
255255
}
256256

257-
async function killProcess(pid: number, signal: string): Promise<void> {
257+
async function killProcess(pid: number, signal: NodeJS.Signals): Promise<void> {
258258
if (process.platform === 'win32') {
259259
// /T kills child processes, /F forces it
260260
await exec(`taskkill /pid ${pid} /T /F`);
@@ -266,23 +266,20 @@ async function killProcess(pid: number, signal: string): Promise<void> {
266266
/**
267267
* Kills all tracked processes
268268
*/
269-
export async function killAllProcesses(signal: NodeJS.Signals = 'SIGTERM'): Promise<void> {
270-
let attempts = 0;
271-
while (_processes.length > 0) {
272-
attempts++;
273-
274-
// Iterate backwards so we can remove elements while looping if needed.
275-
for (let i = _processes.length - 1; i >= 0; i--) {
276-
const childProc = _processes[i];
277269

278-
if (!childProc || childProc.killed || !childProc.pid) {
279-
_processes.splice(i, 1);
280-
continue;
281-
}
270+
export async function killAllProcesses(signal: NodeJS.Signals = 'SIGTERM'): Promise<void> {
271+
const processesToKill: Promise<void>[] = [];
282272

283-
await killProcess(childProc.pid, signal);
273+
while (_processes.length) {
274+
const childProc = _processes.pop();
275+
if (!childProc || childProc.pid === undefined || childProc.killed) {
276+
continue;
284277
}
278+
279+
processesToKill.push(killProcess(childProc.pid, signal));
285280
}
281+
282+
await Promise.all(processesToKill);
286283
}
287284

288285
export function exec(cmd: string, ...args: string[]) {

0 commit comments

Comments
 (0)