@@ -10,7 +10,7 @@ import {
1010 getWorkflowRunJobSteps ,
1111 getWorkflowRunUrl ,
1212 init ,
13- retryOrDie ,
13+ retryOrTimeout ,
1414} from "./api.ts" ;
1515
1616vi . mock ( "@actions/core" ) ;
@@ -427,7 +427,7 @@ describe("API", () => {
427427 } ) ;
428428 } ) ;
429429
430- describe ( "retryOrDie " , ( ) => {
430+ describe ( "retryOrTimeout " , ( ) => {
431431 beforeEach ( ( ) => {
432432 vi . useFakeTimers ( ) ;
433433 } ) ;
@@ -436,38 +436,54 @@ describe("API", () => {
436436 vi . useRealTimers ( ) ;
437437 } ) ;
438438
439- it ( "should return a populated array" , async ( ) => {
440- const attempt = ( ) => Promise . resolve ( [ 0 ] ) ;
441- expect ( await retryOrDie ( attempt , 1000 ) ) . toHaveLength ( 1 ) ;
439+ it ( "should return a result" , async ( ) => {
440+ const attemptResult = [ 0 ] ;
441+ const attempt = ( ) => Promise . resolve ( attemptResult ) ;
442+
443+ const result = await retryOrTimeout ( attempt , 1000 ) ;
444+ if ( result . timeout ) {
445+ expect . fail ( "expected retryOrTimeout not to timeout" ) ;
446+ }
447+
448+ expect ( result . timeout ) . toStrictEqual ( false ) ;
449+ expect ( result . value ) . toStrictEqual ( attemptResult ) ;
442450 } ) ;
443451
444- it ( "should throw if the given timeout is exceeded" , async ( ) => {
452+ it ( "should return a timeout result if the given timeout is exceeded" , async ( ) => {
445453 // Never return data.
446454 const attempt = ( ) => Promise . resolve ( [ ] ) ;
447455
448- const retryOrDiePromise = retryOrDie ( attempt , 1000 ) ;
449- vi . advanceTimersByTime ( 2000 ) ;
456+ const retryOrTimeoutPromise = retryOrTimeout ( attempt , 1000 ) ;
450457 // eslint-disable-next-line @typescript-eslint/no-floating-promises
451458 vi . advanceTimersByTimeAsync ( 2000 ) ;
452459
453- await expect ( retryOrDiePromise ) . rejects . toThrow (
454- "Timed out while attempting to fetch data" ,
455- ) ;
460+ const result = await retryOrTimeoutPromise ;
461+ if ( ! result . timeout ) {
462+ expect . fail ( "expected retryOrTimeout to timeout" ) ;
463+ }
464+
465+ expect ( result . timeout ) . toStrictEqual ( true ) ;
456466 } ) ;
457467
458468 it ( "should retry to get a populated array" , async ( ) => {
469+ const attemptResult = [ 0 ] ;
459470 const attempt = vi
460471 . fn ( )
461- . mockResolvedValue ( [ 0 ] )
472+ . mockResolvedValue ( attemptResult )
462473 . mockResolvedValueOnce ( [ ] )
463474 . mockResolvedValueOnce ( [ ] ) ;
464475
465- const retryOrDiePromise = retryOrDie ( attempt , 5000 ) ;
466- vi . advanceTimersByTime ( 3000 ) ;
476+ const retryOrDiePromise = retryOrTimeout ( attempt , 5000 ) ;
467477 // eslint-disable-next-line @typescript-eslint/no-floating-promises
468478 vi . advanceTimersByTimeAsync ( 3000 ) ;
469479
470- expect ( await retryOrDiePromise ) . toHaveLength ( 1 ) ;
480+ const result = await retryOrDiePromise ;
481+ if ( result . timeout ) {
482+ expect . fail ( "expected retryOrTimeout not to timeout" ) ;
483+ }
484+
485+ expect ( result . timeout ) . toStrictEqual ( false ) ;
486+ expect ( result . value ) . toStrictEqual ( attemptResult ) ;
471487 expect ( attempt ) . toHaveBeenCalledTimes ( 3 ) ;
472488 } ) ;
473489 } ) ;
0 commit comments