From 4fdd71d1867a38facef4a05e5750af43810bc9c2 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 13 May 2026 03:07:27 +0100 Subject: [PATCH] test: dedupe transport ready mock reads --- src/infra/transport-ready.test.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/infra/transport-ready.test.ts b/src/infra/transport-ready.test.ts index 8531ce24698..577b589b952 100644 --- a/src/infra/transport-ready.test.ts +++ b/src/infra/transport-ready.test.ts @@ -37,6 +37,18 @@ function createRuntime() { return { log: vi.fn(), error: vi.fn(), exit: vi.fn() }; } +function runtimeErrorMessageAt(runtime: ReturnType, 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): 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 () => {