


























@@ -11,11 +11,25 @@ vi.mock("../logging/subsystem.js", () => ({
11111212import { buildTimeoutAbortSignal } from "./fetch-timeout.js";
131314-function requireWarnRecord(callIndex: number): Record<string, unknown> {
15-const record = warn.mock.calls[callIndex]?.[1] as Record<string, unknown> | undefined;
16-if (!record) {
17-throw new Error(`missing warning record ${callIndex}`);
14+function requireWarnCall(callIndex: number): [string, Record<string, unknown>] {
15+const call = warn.mock.calls.at(callIndex);
16+if (!call) {
17+throw new Error(`missing warning call ${callIndex}`);
18+}
19+const [message, record] = call;
20+if (typeof message !== "string" || !record || typeof record !== "object") {
21+throw new Error(`invalid warning call ${callIndex}`);
1822}
23+return [message, record as Record<string, unknown>];
24+}
25+26+function requireWarnMessage(callIndex: number): string {
27+const [message] = requireWarnCall(callIndex);
28+return message;
29+}
30+31+function requireWarnRecord(callIndex: number): Record<string, unknown> {
32+const [, record] = requireWarnCall(callIndex);
1933return record;
2034}
2135@@ -42,7 +56,7 @@ describe("buildTimeoutAbortSignal", () => {
4256expect((signal?.reason as Error | undefined)?.name).toBe("TimeoutError");
4357expect((signal?.reason as Error | undefined)?.message).toBe("request timed out");
4458expect(warn).toHaveBeenCalledTimes(1);
45-expect(warn.mock.calls[0]?.[0]).toBe("fetch timeout reached; aborting operation");
59+expect(requireWarnMessage(0)).toBe("fetch timeout reached; aborting operation");
4660const record = requireWarnRecord(0);
4761expect(record.timeoutMs).toBe(25);
4862expect(record.operation).toBe("unit-test");
@@ -102,7 +116,7 @@ describe("buildTimeoutAbortSignal", () => {
102116vi.setSystemTime(2_000);
103117await vi.advanceTimersByTimeAsync(25);
104118105-expect(warn.mock.calls[0]?.[0]).toBe("fetch timeout reached; aborting operation");
119+expect(requireWarnMessage(0)).toBe("fetch timeout reached; aborting operation");
106120const record = requireWarnRecord(0);
107121expect(record.timerDelayMs).toBe(2000);
108122expect(record.eventLoopDelayHint).toBe("timer delayed 2000ms, likely event-loop starvation");
@@ -122,7 +136,7 @@ describe("buildTimeoutAbortSignal", () => {
122136123137await vi.advanceTimersByTimeAsync(25);
124138125-expect(warn.mock.calls[0]?.[0]).toBe("fetch timeout reached; aborting operation");
139+expect(requireWarnMessage(0)).toBe("fetch timeout reached; aborting operation");
126140expect(requireWarnRecord(0).url).toBe("/api/responses");
127141128142cleanup();
@@ -154,7 +168,7 @@ describe("buildTimeoutAbortSignal", () => {
154168155169expect(signal?.aborted).toBe(true);
156170expect(warn).toHaveBeenCalledTimes(1);
157-const [, record] = warn.mock.calls[0] as [string, Record<string, unknown>];
171+const record = requireWarnRecord(0);
158172expect(record).not.toHaveProperty("operation");
159173expect(record).not.toHaveProperty("url");
160174expect(record.consoleMessage).toBe("fetch timeout after 25ms (elapsed 25ms)");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。