@@ -30,10 +30,11 @@ test("cacheableRequest is a class", () => {
3030} ) ;
3131test ( "cacheableRequest returns an event emitter" , ( ) => {
3232 const cacheableRequest = new CacheableRequest ( request ) . request ( ) ;
33- const returnValue = cacheableRequest ( parseWithWhatwg ( s . url ) , ( ) => true ) . on (
34- "request" ,
35- ( request_ : any ) => request_ . end ( ) ,
36- ) ;
33+ const returnValue = cacheableRequest ( parseWithWhatwg ( s . url ) , ( ) => true )
34+ . on ( "error" , ( ) => {
35+ /* request-lifecycle noise — test asserts the return value, not response */
36+ } )
37+ . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
3738 expect ( returnValue instanceof EventEmitter ) . toBeTruthy ( ) ;
3839} ) ;
3940
@@ -42,34 +43,53 @@ test("cacheableRequest passes requests through if no cache option is set", () =>
4243 cacheableRequest ( parseWithWhatwg ( s . url ) , async ( response : any ) => {
4344 const body = await getStream ( response ) ;
4445 expect ( body ) . toBe ( "hi" ) ;
45- } ) . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
46+ } )
47+ . on ( "error" , ( ) => {
48+ /* request-lifecycle noise */
49+ } )
50+ . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
4651} ) ;
4752test ( "cacheableRequest accepts url as string" , ( ) => {
4853 const cacheableRequest = new CacheableRequest ( request ) . request ( ) ;
4954 cacheableRequest ( s . url , async ( response : any ) => {
5055 const body = await getStream ( response ) ;
5156 expect ( body ) . toBe ( "hi" ) ;
52- } ) . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
57+ } )
58+ . on ( "error" , ( ) => {
59+ /* request-lifecycle noise */
60+ } )
61+ . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
5362} ) ;
5463test ( "cacheableRequest accepts url as URL" , ( ) => {
5564 const cacheableRequest = new CacheableRequest ( request ) . request ( ) ;
5665 cacheableRequest ( new URL ( s . url ) , async ( response : any ) => {
5766 const body = await getStream ( response ) ;
5867 expect ( body ) . toBe ( "hi" ) ;
59- } ) . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
68+ } )
69+ . on ( "error" , ( ) => {
70+ /* request-lifecycle noise */
71+ } )
72+ . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
6073} ) ;
6174test ( "cacheableRequest handles no callback parameter" , ( ) => {
6275 const cacheableRequest = new CacheableRequest ( request ) . request ( ) ;
63- cacheableRequest ( parseWithWhatwg ( s . url ) ) . on ( "request" , ( request_ : any ) => {
64- request_ . end ( ) ;
65- request_ . on ( "response" , ( response : any ) => {
66- expect ( response . statusCode ) . toBe ( 200 ) ;
76+ cacheableRequest ( parseWithWhatwg ( s . url ) )
77+ . on ( "error" , ( ) => {
78+ /* request-lifecycle noise */
79+ } )
80+ . on ( "request" , ( request_ : any ) => {
81+ request_ . end ( ) ;
82+ request_ . on ( "response" , ( response : any ) => {
83+ expect ( response . statusCode ) . toBe ( 200 ) ;
84+ } ) ;
6785 } ) ;
68- } ) ;
6986} ) ;
7087test ( "cacheableRequest emits response event for network responses" , ( ) => {
7188 const cacheableRequest = new CacheableRequest ( request ) . request ( ) ;
7289 cacheableRequest ( parseWithWhatwg ( s . url ) )
90+ . on ( "error" , ( ) => {
91+ /* request-lifecycle noise */
92+ } )
7393 . on ( "request" , ( request_ : any ) => request_ . end ( ) )
7494 . on ( "response" , ( response : any ) => {
7595 expect ( response . fromCache ) . toBeFalsy ( ) ;
@@ -84,12 +104,19 @@ test("cacheableRequest emits response event for cached responses", () => {
84104 // This needs to happen in next tick so cache entry has time to be stored
85105 setImmediate ( ( ) => {
86106 cacheableRequest ( options )
107+ . on ( "error" , ( ) => {
108+ /* request-lifecycle noise */
109+ } )
87110 . on ( "request" , ( request_ : any ) => request_ . end ( ) )
88111 . on ( "response" , ( response : any ) => {
89112 expect ( response . fromCache ) . toBeTruthy ( ) ;
90113 } ) ;
91114 } ) ;
92- } ) . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
115+ } )
116+ . on ( "error" , ( ) => {
117+ /* request-lifecycle noise */
118+ } )
119+ . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
93120} ) ;
94121test ( "cacheableRequest emits CacheError if cache adapter connection errors" , ( ) => {
95122 const cacheableRequest = new CacheableRequest (
@@ -176,7 +203,11 @@ test("cacheableRequest emits CacheError if cache.delete errors", () => {
176203 } )
177204 . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
178205 } ) ;
179- } ) . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
206+ } )
207+ . on ( "error" , ( ) => {
208+ /* request-lifecycle noise */
209+ } )
210+ . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
180211 } ) ( ) ;
181212} ) ;
182213test ( "cacheableRequest emits Error if request function throws" , ( ) => {
@@ -202,21 +233,29 @@ test("cacheableRequest does not cache response if request is aborted before rece
202233 // biome-ignore lint/style/noNonNullAssertion: legacy
203234 const options = parseWithWhatwg ( s . url ! ) ;
204235 options . path = "/delay-start" ;
205- cacheableRequest ( options ) . on ( "request" , ( request_ : any ) => {
206- request_ . end ( ) ;
207- setTimeout ( ( ) => {
208- /* do nothing */
209- } , 20 ) ;
210- setTimeout ( ( ) => {
211- cacheableRequest ( options , async ( response : any ) => {
212- request_ . abort ( ) ;
213- expect ( response . fromCache ) . toBe ( false ) ;
214- const body = await getStream ( response ) ;
215- expect ( body ) . toBe ( "hi" ) ;
216- await s . close ( ) ;
217- } ) . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
218- } , 100 ) ;
219- } ) ;
236+ cacheableRequest ( options )
237+ . on ( "error" , ( ) => {
238+ /* swallow abort-induced ECONNRESET on Node 24 */
239+ } )
240+ . on ( "request" , ( request_ : any ) => {
241+ request_ . end ( ) ;
242+ setTimeout ( ( ) => {
243+ /* do nothing */
244+ } , 20 ) ;
245+ setTimeout ( ( ) => {
246+ cacheableRequest ( options , async ( response : any ) => {
247+ request_ . abort ( ) ;
248+ expect ( response . fromCache ) . toBe ( false ) ;
249+ const body = await getStream ( response ) ;
250+ expect ( body ) . toBe ( "hi" ) ;
251+ await s . close ( ) ;
252+ } )
253+ . on ( "error" , ( ) => {
254+ /* request-lifecycle noise */
255+ } )
256+ . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
257+ } , 100 ) ;
258+ } ) ;
220259 } ) ;
221260} ) ;
222261test ( "cacheableRequest does not cache response if request is aborted after receiving part of the response" , ( ) => {
@@ -233,19 +272,27 @@ test("cacheableRequest does not cache response if request is aborted after recei
233272 // biome-ignore lint/style/noNonNullAssertion: legacy
234273 const options = parseWithWhatwg ( s . url ! ) ;
235274 options . path = "/delay-partial" ;
236- cacheableRequest ( options ) . on ( "request" , ( request_ : any ) => {
237- setTimeout ( ( ) => {
238- request_ . abort ( ) ;
239- } , 20 ) ;
240- setTimeout ( ( ) => {
241- cacheableRequest ( options , async ( response : any ) => {
242- expect ( response . fromCache ) . toBeFalsy ( ) ;
243- const body = await getStream ( response ) ;
244- expect ( body ) . toBe ( "hi" ) ;
245- await s . close ( ) ;
246- } ) . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
247- } , 100 ) ;
248- } ) ;
275+ cacheableRequest ( options )
276+ . on ( "error" , ( ) => {
277+ /* swallow abort-induced ECONNRESET on Node 24 */
278+ } )
279+ . on ( "request" , ( request_ : any ) => {
280+ setTimeout ( ( ) => {
281+ request_ . abort ( ) ;
282+ } , 20 ) ;
283+ setTimeout ( ( ) => {
284+ cacheableRequest ( options , async ( response : any ) => {
285+ expect ( response . fromCache ) . toBeFalsy ( ) ;
286+ const body = await getStream ( response ) ;
287+ expect ( body ) . toBe ( "hi" ) ;
288+ await s . close ( ) ;
289+ } )
290+ . on ( "error" , ( ) => {
291+ /* request-lifecycle noise */
292+ } )
293+ . on ( "request" , ( request_ : any ) => request_ . end ( ) ) ;
294+ } , 100 ) ;
295+ } ) ;
249296 } ) ;
250297} ) ;
251298test ( "cacheableRequest makes request even if initial DB connection fails (when opts.automaticFailover is enabled)" , async ( ) => {
0 commit comments