From 42cb7a688ac605904b240c26883ca53bd1025a3b Mon Sep 17 00:00:00 2001 From: productdevbook Date: Sun, 3 May 2026 12:47:08 +0300 Subject: [PATCH] test(abort-reason): de-flake timeout tests using synthetic transport rejection --- test/abort-reason.test.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/abort-reason.test.ts b/test/abort-reason.test.ts index a6afcde..001ab7c 100644 --- a/test/abort-reason.test.ts +++ b/test/abort-reason.test.ts @@ -53,14 +53,16 @@ describe("abort signals — reason propagation", () => { }) it("our own timeout fires TimeoutError, not AbortError", async () => { + // The contract under test is the *shape* of the rejection (mapped to + // TimeoutError, not AbortError), not the wall-clock behavior of + // `AbortSignal.timeout`. Driving the rejection synchronously with a + // TimeoutError-named DOMException exercises the same `mapTransportError` + // path while removing the real-timer race that flaked under saturated CI + // runners (same flake class as #120 / fixed in #122). const driver = { name: "slow", - request: (req: Request) => - new Promise((_resolve, reject) => { - req.signal.addEventListener("abort", () => { - reject(req.signal.reason ?? new DOMException("aborted", "AbortError")) - }) - }), + request: (_req: Request) => + Promise.reject(new DOMException("Operation timed out", "TimeoutError")), } const m = createMisina({ driver, retry: 0, timeout: 20 })