diff --git a/scripts/test-group-report.mjs b/scripts/test-group-report.mjs index 78abc7ae31ce..29627b71cec4 100644 --- a/scripts/test-group-report.mjs +++ b/scripts/test-group-report.mjs @@ -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); } diff --git a/test/scripts/test-group-report.test.ts b/test/scripts/test-group-report.test.ts index cae4586f8267..6ae52f04801a 100644 --- a/test/scripts/test-group-report.test.ts +++ b/test/scripts/test-group-report.test.ts @@ -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;