test: dedupe transport ready mock reads

This commit is contained in:
Peter Steinberger
2026-05-13 03:07:27 +01:00
parent 74bbac994d
commit 4fdd71d186

View File

@@ -37,6 +37,18 @@ function createRuntime() {
return { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
}
function runtimeErrorMessageAt(runtime: ReturnType<typeof createRuntime>, index: number): string {
const call = runtime.error.mock.calls[index];
if (!call || typeof call[0] !== "string") {
throw new Error(`expected runtime error call ${index + 1}`);
}
return call[0];
}
function latestRuntimeErrorMessage(runtime: ReturnType<typeof createRuntime>): string {
return runtimeErrorMessageAt(runtime, runtime.error.mock.calls.length - 1);
}
describe("waitForTransportReady", () => {
beforeAll(async () => {
({ waitForTransportReady } = await import("./transport-ready.js"));
@@ -152,8 +164,8 @@ describe("waitForTransportReady", () => {
await asserted;
expect(runtime.error).toHaveBeenCalledTimes(2);
expect(runtime.error.mock.calls.at(0)?.[0]).toContain("unknown error");
expect(runtime.error.mock.calls.at(-1)?.[0]).toContain("not ready after 120ms");
expect(runtimeErrorMessageAt(runtime, 0)).toContain("unknown error");
expect(latestRuntimeErrorMessage(runtime)).toContain("not ready after 120ms");
});
it("rethrows non-abort sleep failures", async () => {