@@ -543,10 +543,9 @@ describe("paths.mjs exports", () => {
543543 expect ( callCount ) . toBe ( 1 ) // Only initial attempt, no retries
544544 } )
545545
546- it ( "should throw undefined when retries is negative (loop never executes )" , async ( ) => {
546+ it ( "should clamp negative retries to 0 (only initial attempt )" , async ( ) => {
547547 let callCount = 0
548- // With retries: -1, loop condition (0 <= -1) is false, so loop never runs
549- // lastError is undefined, so it throws undefined
548+ // With retries: -1, sanitized to 0, so only initial attempt runs
550549 await expect (
551550 retryOnTransientError (
552551 ( ) => {
@@ -556,11 +555,11 @@ describe("paths.mjs exports", () => {
556555 } ,
557556 { retries : - 1 } ,
558557 ) ,
559- ) . rejects . toBeUndefined ( )
560- expect ( callCount ) . toBe ( 0 ) // Loop never runs
558+ ) . rejects . toThrow ( "EAGAIN" )
559+ expect ( callCount ) . toBe ( 1 ) // Only initial attempt
561560 } )
562561
563- it ( "should throw undefined when retries is -5 (loop never executes )" , async ( ) => {
562+ it ( "should clamp retries -5 to 0 (only initial attempt )" , async ( ) => {
564563 let callCount = 0
565564 await expect (
566565 retryOnTransientError (
@@ -571,8 +570,8 @@ describe("paths.mjs exports", () => {
571570 } ,
572571 { retries : - 5 } ,
573572 ) ,
574- ) . rejects . toBeUndefined ( )
575- expect ( callCount ) . toBe ( 0 ) // Loop never runs
573+ ) . rejects . toThrow ( "EAGAIN" )
574+ expect ( callCount ) . toBe ( 1 ) // Only initial attempt
576575 } )
577576
578577 it ( "should handle initialDelayMs: 0 (no delay)" , async ( ) => {
@@ -615,10 +614,9 @@ describe("paths.mjs exports", () => {
615614 expect ( elapsed ) . toBeLessThan ( 50 )
616615 } )
617616
618- it ( "should throw undefined when retries is NaN (loop never executes )" , async ( ) => {
617+ it ( "should handle NaN retries (falls back to default 3 )" , async ( ) => {
619618 let callCount = 0
620- // When retries is NaN, the loop condition (attempt <= retries) is always false
621- // So the loop never runs and lastError (undefined) is thrown
619+ // When retries is NaN, it is sanitized to the default 3 retries
622620 await expect (
623621 retryOnTransientError (
624622 ( ) => {
@@ -628,8 +626,8 @@ describe("paths.mjs exports", () => {
628626 } ,
629627 { retries : Number . NaN } ,
630628 ) ,
631- ) . rejects . toBeUndefined ( )
632- expect ( callCount ) . toBe ( 0 ) // Loop never runs
629+ ) . rejects . toThrow ( "EAGAIN" )
630+ expect ( callCount ) . toBe ( 4 ) // Initial + 3 retries (default)
633631 } )
634632
635633 it ( "should handle non-numeric initialDelayMs (NaN falls back to default 100ms)" , async ( ) => {
0 commit comments