Skip to content

Commit 692cb7b

Browse files
authored
test(infra): consolidate abort relay coverage at its owner (#134266)
1 parent ce8ea4a commit 692cb7b

2 files changed

Lines changed: 27 additions & 87 deletions

File tree

‎src/infra/abort-pattern.test.ts‎

Lines changed: 0 additions & 86 deletions
This file was deleted.

‎src/utils/fetch-timeout.test.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ vi.mock("../logging/subsystem.js", () => ({
1212
}));
1313

1414
import { MAX_SAFE_TIMEOUT_DELAY_MS } from "../../packages/gateway-client/src/timeouts.js";
15-
import { buildTimeoutAbortSignal, fetchWithTimeout } from "./fetch-timeout.js";
15+
import { bindAbortRelay, buildTimeoutAbortSignal, fetchWithTimeout } from "./fetch-timeout.js";
1616

1717
function captureTimeoutLogUrl(url: string): Promise<Record<string, unknown>> {
1818
const { cleanup } = buildTimeoutAbortSignal({ timeoutMs: 25, operation: "unit-test", url });
@@ -47,6 +47,32 @@ function requireWarnRecord(callIndex: number): Record<string, unknown> {
4747
return record;
4848
}
4949

50+
describe("bindAbortRelay", () => {
51+
it("preserves the default AbortError reason when used as an event listener", () => {
52+
const parent = new AbortController();
53+
const child = new AbortController();
54+
const onAbort = bindAbortRelay(child);
55+
56+
parent.signal.addEventListener("abort", onAbort, { once: true });
57+
parent.abort();
58+
59+
expect(child.signal.aborted).toBe(true);
60+
expect(child.signal.reason).toBeInstanceOf(DOMException);
61+
expect(child.signal.reason.name).toBe("AbortError");
62+
});
63+
64+
it("removes the event listener with the saved relay reference", () => {
65+
const parent = new AbortController();
66+
const child = new AbortController();
67+
const onAbort = bindAbortRelay(child);
68+
69+
parent.signal.addEventListener("abort", onAbort);
70+
parent.signal.removeEventListener("abort", onAbort);
71+
parent.abort();
72+
expect(child.signal.aborted).toBe(false);
73+
});
74+
});
75+
5076
describe("buildTimeoutAbortSignal", () => {
5177
beforeEach(() => {
5278
warn.mockClear();

0 commit comments

Comments
 (0)