Skip to content

Commit 4fdd71d

Browse files
committed
test: dedupe transport ready mock reads
1 parent 74bbac9 commit 4fdd71d

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎src/infra/transport-ready.test.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ function createRuntime() {
3737
return { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
3838
}
3939

40+
function runtimeErrorMessageAt(runtime: ReturnType<typeof createRuntime>, index: number): string {
41+
const call = runtime.error.mock.calls[index];
42+
if (!call || typeof call[0] !== "string") {
43+
throw new Error(`expected runtime error call ${index + 1}`);
44+
}
45+
return call[0];
46+
}
47+
48+
function latestRuntimeErrorMessage(runtime: ReturnType<typeof createRuntime>): string {
49+
return runtimeErrorMessageAt(runtime, runtime.error.mock.calls.length - 1);
50+
}
51+
4052
describe("waitForTransportReady", () => {
4153
beforeAll(async () => {
4254
({ waitForTransportReady } = await import("./transport-ready.js"));
@@ -152,8 +164,8 @@ describe("waitForTransportReady", () => {
152164
await asserted;
153165

154166
expect(runtime.error).toHaveBeenCalledTimes(2);
155-
expect(runtime.error.mock.calls.at(0)?.[0]).toContain("unknown error");
156-
expect(runtime.error.mock.calls.at(-1)?.[0]).toContain("not ready after 120ms");
167+
expect(runtimeErrorMessageAt(runtime, 0)).toContain("unknown error");
168+
expect(latestRuntimeErrorMessage(runtime)).toContain("not ready after 120ms");
157169
});
158170

159171
it("rethrows non-abort sleep failures", async () => {

0 commit comments

Comments
 (0)