perf(test): cut setup/import overhead in hot suites
This commit is contained in:
@@ -51,6 +51,17 @@ function canConnect(port: number): Promise<boolean> {
|
||||
});
|
||||
}
|
||||
|
||||
async function waitForPortClosed(port: number, timeoutMs = 1_000): Promise<void> {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
while (Date.now() <= deadline) {
|
||||
if (!(await canConnect(port))) {
|
||||
return;
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
}
|
||||
throw new Error("timeout waiting for port to close");
|
||||
}
|
||||
|
||||
describe("attachChildProcessBridge", () => {
|
||||
const children: Array<{ kill: (signal?: NodeJS.Signals) => boolean }> = [];
|
||||
const detachments: Array<() => void> = [];
|
||||
@@ -111,7 +122,7 @@ describe("attachChildProcessBridge", () => {
|
||||
});
|
||||
});
|
||||
|
||||
await new Promise((r) => setTimeout(r, 250));
|
||||
await waitForPortClosed(port);
|
||||
expect(await canConnect(port)).toBe(false);
|
||||
}, 20_000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user