Skip to content

Commit e20a528

Browse files
committed
fix: Gracefully kill child processes in tests
Ensures that child processes spawned during tests are properly killed and awaited, preventing orphaned processes in the CI environment.
1 parent aef0d6d commit e20a528

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

scripts/bin-test/test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,11 @@ async function runFileDiscovery(modulePath: string): Promise<DiscoveryResult> {
210210
stderr += chunk.toString("utf8");
211211
});
212212

213-
const timeoutId = setTimeout(() => {
214-
proc.kill(9);
213+
const timeoutId = setTimeout(async () => {
214+
if (proc.pid) {
215+
proc.kill(9);
216+
await new Promise<void>((resolve) => proc.on("exit", resolve));
217+
}
215218
resolve({ success: false, error: `File discovery timed out after ${TIMEOUT_M}ms` });
216219
}, TIMEOUT_M);
217220

0 commit comments

Comments
 (0)