mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 14:54:46 +00:00
test: dedupe transport ready mock reads
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user