@@ -192,7 +192,7 @@ describe('Hooks E2E Tests', () => {
192192 const afterCall = afterResponseCalls [ afterResponseCalls . length - 1 ]
193193 expect ( afterCall ?. req . url ) . toContain ( '/api/hooks/hello' )
194194 expect ( afterCall ?. res . status ) . toBe ( 200 )
195- } )
195+ } , 20000 )
196196
197197 test ( 'should trigger circuit breaker hooks on successful request' , async ( ) => {
198198 const initialBeforeCount = beforeCircuitBreakerCalls . length
@@ -218,7 +218,7 @@ describe('Hooks E2E Tests', () => {
218218 expect ( afterCall ?. req . url ) . toContain ( '/api/error/health' )
219219 expect ( afterCall ?. result . state ) . toBe ( 'CLOSED' )
220220 expect ( afterCall ?. result . success ) . toBe ( true )
221- } )
221+ } , 20000 )
222222
223223 test ( 'should trigger onError hook on server error' , async ( ) => {
224224 const initialErrorCount = onErrorCalls . length
@@ -237,7 +237,7 @@ describe('Hooks E2E Tests', () => {
237237 const errorCall = onErrorCalls [ onErrorCalls . length - 1 ]
238238 expect ( errorCall ?. req . url ) . toContain ( '/api/error/error' )
239239 expect ( errorCall ?. error . message ) . toContain ( 'Server error' )
240- } )
240+ } , 20000 )
241241
242242 test ( 'should trigger onError hook on timeout' , async ( ) => {
243243 const initialErrorCount = onErrorCalls . length
@@ -256,7 +256,7 @@ describe('Hooks E2E Tests', () => {
256256 const errorCall = onErrorCalls [ onErrorCalls . length - 1 ]
257257 expect ( errorCall ?. req . url ) . toContain ( '/api/error/timeout' )
258258 expect ( errorCall ?. error . message ) . toContain ( 'timeout' )
259- } )
259+ } , 20000 )
260260
261261 test ( 'should trigger circuit breaker hooks with failure state' , async ( ) => {
262262 // Wait for circuit breaker to potentially reset
@@ -281,7 +281,7 @@ describe('Hooks E2E Tests', () => {
281281 afterCircuitBreakerCalls [ afterCircuitBreakerCalls . length - 1 ]
282282 expect ( afterCall ?. req . url ) . toContain ( '/api/error/error' )
283283 expect ( afterCall ?. result . success ) . toBe ( false )
284- } )
284+ } , 20000 )
285285
286286 test ( 'should trigger all hooks in correct order for successful request' , async ( ) => {
287287 // Reset counters
@@ -323,7 +323,7 @@ describe('Hooks E2E Tests', () => {
323323
324324 // Response should be successful
325325 expect ( afterResponse ?. res . status ) . toBe ( 200 )
326- } )
326+ } , 20000 )
327327
328328 test ( 'should trigger all hooks in correct order for failed request' , async ( ) => {
329329 // Wait for circuit breaker to potentially reset
@@ -369,7 +369,7 @@ describe('Hooks E2E Tests', () => {
369369 expect ( onError ?. error . message ) . toMatch (
370370 / S e r v e r e r r o r | C i r c u i t b r e a k e r i s O P E N / ,
371371 )
372- } )
372+ } , 20000 )
373373
374374 test ( 'should pass correct proxy configuration to beforeRequest hook' , async ( ) => {
375375 const initialCount = beforeRequestCalls . length
@@ -385,7 +385,7 @@ describe('Hooks E2E Tests', () => {
385385 expect ( beforeCall ?. opts ) . toBeDefined ( )
386386 expect ( beforeCall ?. opts . pathRewrite ) . toBeDefined ( )
387387 expect ( beforeCall ?. opts . pathRewrite [ '^/api/hooks' ] ) . toBe ( '' )
388- } )
388+ } , 20000 )
389389
390390 test ( 'should provide response body to afterResponse hook' , async ( ) => {
391391 const initialCount = afterResponseCalls . length
@@ -401,7 +401,7 @@ describe('Hooks E2E Tests', () => {
401401 expect ( afterCall ?. res . status ) . toBe ( 200 )
402402 expect ( afterCall ?. res . headers . get ( 'content-type' ) ) . toContain ( 'text/plain' )
403403 expect ( afterCall ?. body ) . toBeDefined ( )
404- } )
404+ } , 20000 )
405405
406406 test ( 'should use fallback response from onError hook when returned' , async ( ) => {
407407 // Create a new gateway with onError hook that returns a fallback response
@@ -444,6 +444,8 @@ describe('Hooks E2E Tests', () => {
444444
445445 fallbackGateway . addRoute ( fallbackRouteConfig )
446446 const fallbackServer = await fallbackGateway . listen ( fallbackGatewayPort )
447+ // Allow the server a brief moment to be fully ready in slower CI environments
448+ await new Promise ( ( resolve ) => setTimeout ( resolve , 150 ) )
447449
448450 try {
449451 const response = await fetch (
@@ -464,7 +466,7 @@ describe('Hooks E2E Tests', () => {
464466 } finally {
465467 fallbackServer . stop ( )
466468 }
467- } )
469+ } , 20000 )
468470
469471 test ( 'should use fallback response from onError hook on timeout' , async ( ) => {
470472 // Create a new gateway with onError hook that handles timeouts
@@ -516,6 +518,8 @@ describe('Hooks E2E Tests', () => {
516518
517519 timeoutGateway . addRoute ( timeoutRouteConfig )
518520 const timeoutServer = await timeoutGateway . listen ( timeoutGatewayPort )
521+ // Allow the server a brief moment to be fully ready in slower CI environments
522+ await new Promise ( ( resolve ) => setTimeout ( resolve , 150 ) )
519523
520524 try {
521525 const response = await fetch (
@@ -539,7 +543,7 @@ describe('Hooks E2E Tests', () => {
539543 } finally {
540544 timeoutServer . stop ( )
541545 }
542- } )
546+ } , 20000 )
543547
544548 test ( 'should fallback to default error handling when onError hook throws' , async ( ) => {
545549 // Create a new failing server for this test
@@ -601,6 +605,8 @@ describe('Hooks E2E Tests', () => {
601605
602606 selectiveGateway . addRoute ( selectiveRouteConfig )
603607 const selectiveServer = await selectiveGateway . listen ( selectiveGatewayPort )
608+ // Allow the server a brief moment to be fully ready in slower CI environments
609+ await new Promise ( ( resolve ) => setTimeout ( resolve , 150 ) )
604610
605611 try {
606612 // Test with timeout (should use fallback)
@@ -622,7 +628,7 @@ describe('Hooks E2E Tests', () => {
622628 selectiveServer . stop ( )
623629 selectiveFailingServer . stop ( )
624630 }
625- } )
631+ } , 20000 )
626632
627633 test ( 'should handle async fallback response generation' , async ( ) => {
628634 // Create a new failing server for this test
@@ -688,7 +694,8 @@ describe('Hooks E2E Tests', () => {
688694 asyncGateway . addRoute ( asyncRouteConfig )
689695 const asyncServer = await asyncGateway . listen ( asyncGatewayPort )
690696
691- await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) )
697+ // Allow the server a brief moment to be fully ready in slower CI environments
698+ await new Promise ( ( resolve ) => setTimeout ( resolve , 250 ) )
692699
693700 try {
694701 const testRequestId = `test-${ Date . now ( ) } `
@@ -715,5 +722,5 @@ describe('Hooks E2E Tests', () => {
715722 asyncServer . stop ( )
716723 asyncFailingServer . stop ( )
717724 }
718- } )
725+ } , 20000 )
719726} )
0 commit comments