






















@@ -9,7 +9,7 @@ vi.mock("../logging/subsystem.js", () => ({
99})),
1010}));
111112-import { buildTimeoutAbortSignal } from "./fetch-timeout.js";
12+import { buildTimeoutAbortSignal, fetchWithTimeout } from "./fetch-timeout.js";
13131414function requireWarnCall(callIndex: number): [string, Record<string, unknown>] {
1515const call = warn.mock.calls[callIndex];
@@ -142,6 +142,29 @@ describe("buildTimeoutAbortSignal", () => {
142142cleanup();
143143});
144144145+it("tags fetch timeout aborts so callers can distinguish them from parent aborts", async () => {
146+const fetchFn = vi.fn<typeof fetch>(
147+async (_input, init) =>
148+await new Promise<Response>((_resolve, reject) => {
149+const signal = init?.signal;
150+if (!signal) {
151+reject(new Error("missing signal"));
152+return;
153+}
154+signal.addEventListener("abort", () => reject(signal.reason), { once: true });
155+}),
156+);
157+158+const result = fetchWithTimeout("https://example.com/v1/audio", {}, 25, fetchFn);
159+const assertion = expect(result).rejects.toMatchObject({
160+name: "TimeoutError",
161+message: "request timed out",
162+});
163+await vi.advanceTimersByTimeAsync(25);
164+165+await assertion;
166+});
167+145168it("does not log when a parent signal aborts first", async () => {
146169const parent = new AbortController();
147170const { signal, cleanup } = buildTimeoutAbortSignal({
@@ -154,6 +177,7 @@ describe("buildTimeoutAbortSignal", () => {
154177await vi.advanceTimersByTimeAsync(25);
155178156179expect(signal?.aborted).toBe(true);
180+expect(signal?.reason).not.toMatchObject({ name: "TimeoutError" });
157181expect(warn).not.toHaveBeenCalled();
158182159183cleanup();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。