perf(test): cut setup/import overhead in hot suites

This commit is contained in:
Peter Steinberger
2026-02-13 21:23:44 +00:00
parent 93dd51bce0
commit caebe70e9a
16 changed files with 428 additions and 426 deletions

View File

@@ -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);
});