fix(testing): force taskkill group report trees on windows

This commit is contained in:
Vincent Koc
2026-06-21 07:16:31 +02:00
parent 78f30a010c
commit 3df5207389
2 changed files with 30 additions and 0 deletions

View File

@@ -263,6 +263,12 @@ export function signalTestGroupReportChild(
if (!result?.error && result?.status === 0) {
return;
}
if (signal !== "SIGKILL") {
const forceResult = runTaskkill("taskkill", [...args, "/F"], { stdio: "ignore" });
if (!forceResult?.error && forceResult?.status === 0) {
return;
}
}
}
child.kill(signal);
}

View File

@@ -636,6 +636,30 @@ describe("scripts/test-group-report child process guard", () => {
expect(child.kill).not.toHaveBeenCalled();
});
it("force-kills Windows child process trees when graceful taskkill fails", () => {
const child = {
kill: vi.fn(),
pid: 12345,
};
const runTaskkill = vi
.fn()
.mockReturnValueOnce({ error: undefined, status: 1 })
.mockReturnValueOnce({ error: undefined, status: 0 });
signalTestGroupReportChild(child, "SIGTERM", {
platform: "win32",
runTaskkill,
});
expect(runTaskkill).toHaveBeenNthCalledWith(1, "taskkill", ["/PID", "12345", "/T"], {
stdio: "ignore",
});
expect(runTaskkill).toHaveBeenNthCalledWith(2, "taskkill", ["/PID", "12345", "/T", "/F"], {
stdio: "ignore",
});
expect(child.kill).not.toHaveBeenCalled();
});
it("times out a child that ignores SIGTERM", async () => {
if (process.platform === "win32") {
return;