Files
iptvnator/apps/electron-backend-e2e/src/electron-process-termination.ts
T
4gray 0ecfc06494 test(electron): fix Windows cleanup and retain packaged smoke diagnostics (#1665)
* test(electron): reap Windows process trees and retain smoke diagnostics

* test(electron): require confirmed process exit before relaunch

* test(electron): retain process handle after application exit

* test(electron): bind captured processes to application instances
2026-09-23 22:55:48 +02:00

26 lines
889 B
TypeScript

import { execFileSync, type ChildProcess } from 'node:child_process';
type ElectronProcess = Pick<ChildProcess, 'pid' | 'kill'>;
export function terminateElectronProcess(
child: ElectronProcess,
signal: NodeJS.Signals = 'SIGTERM',
platform: NodeJS.Platform = process.platform,
run: typeof execFileSync = execFileSync
): void {
// Playwright launches Electron through cmd.exe on Windows. Killing only
// that ChildProcess leaves Electron (and its profile lock) alive.
if (platform === 'win32') {
if (!Number.isSafeInteger(child.pid) || (child.pid ?? 0) <= 0) {
throw new Error('electron-process-pid-unavailable');
}
run('taskkill.exe', ['/pid', String(child.pid), '/T', '/F'], {
stdio: 'pipe',
timeout: 5000,
windowsHide: true,
});
return;
}
child.kill(signal);
}