@@ -12,7 +12,7 @@ vi.mock("../logging/subsystem.js", () => ({
1212} ) ) ;
1313
1414import { 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
1717function 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+
5076describe ( "buildTimeoutAbortSignal" , ( ) => {
5177 beforeEach ( ( ) => {
5278 warn . mockClear ( ) ;
0 commit comments