@@ -30,12 +30,14 @@ describe("createDiscordRequestClient", () => {
3030 vi . useRealTimers ( ) ;
3131 } ) ;
3232
33- it ( "preserves the REST client's abort signal for proxied fetch calls" , async ( ) => {
33+ it ( "preserves a live REST abort signal through successful proxied fetches" , async ( ) => {
34+ let receivedSignal : AbortSignal | undefined ;
3435 const fetchSpy = vi . fn ( async ( _input : string | URL | Request , init ?: RequestInit ) => {
3536 if ( ! ( init ?. signal instanceof AbortSignal ) ) {
3637 throw new Error ( "Expected proxied fetch init to include an AbortSignal" ) ;
3738 }
3839 expect ( init . signal . aborted ) . toBe ( false ) ;
40+ receivedSignal = init . signal ;
3941 return createJsonResponse ( [ ] ) ;
4042 } ) ;
4143
@@ -46,6 +48,7 @@ describe("createDiscordRequestClient", () => {
4648
4749 await client . get ( "/channels/123/messages" ) ;
4850 expect ( fetchSpy ) . toHaveBeenCalledTimes ( 1 ) ;
51+ expect ( receivedSignal ?. aborted ) . toBe ( false ) ;
4952 } ) ;
5053
5154 it ( "lets the REST client abort hanging proxied requests after its timeout" , async ( ) => {
@@ -106,27 +109,6 @@ describe("createDiscordRequestClient", () => {
106109 expect ( abortable . receivedSignal ?. aborted ) . toBe ( true ) ;
107110 } ) ;
108111
109- it ( "provides the REST client's timeout signal even without a caller signal" , async ( ) => {
110- let receivedSignal : AbortSignal | undefined ;
111-
112- const fetchSpy = vi . fn ( async ( _input : string | URL | Request , init ?: RequestInit ) => {
113- receivedSignal = init ?. signal ?? undefined ;
114- return createJsonResponse ( { } ) ;
115- } ) ;
116-
117- const client = createDiscordRequestClient ( "Bot test-token" , {
118- fetch : fetchSpy as never ,
119- queueRequests : false ,
120- } ) ;
121-
122- await client . get ( "/channels/123/messages" ) ;
123-
124- if ( ! receivedSignal ) {
125- throw new Error ( "Expected proxied fetch to receive the REST timeout signal" ) ;
126- }
127- expect ( receivedSignal . aborted ) . toBe ( false ) ;
128- } ) ;
129-
130112 it ( "exports a reasonable timeout constant" , ( ) => {
131113 expect ( DISCORD_REST_TIMEOUT_MS ) . toBeGreaterThanOrEqual ( 5_000 ) ;
132114 expect ( DISCORD_REST_TIMEOUT_MS ) . toBeLessThanOrEqual ( 30_000 ) ;
0 commit comments