@@ -4,7 +4,7 @@ import path from 'node:path';
44import { execa } from 'execa' ;
55import test from 'ava' ;
66import delay from 'delay' ;
7- import pRetry , { AbortError } from './index.js' ;
7+ import pRetry , { makeRetriable , AbortError } from './index.js' ;
88
99const fixture = Symbol ( 'fixture' ) ;
1010const fixtureError = new Error ( 'fixture' ) ;
@@ -697,3 +697,32 @@ main();
697697 await fs . unlink ( temporaryFile ) ;
698698 }
699699} ) ;
700+
701+ test ( 'makeRetriable wraps and retries the function' , async t => {
702+ let callCount = 0 ;
703+ const function_ = async ( a , b ) => {
704+ callCount ++ ;
705+ if ( callCount < 3 ) {
706+ throw new Error ( 'fail' ) ;
707+ }
708+
709+ return a + b ;
710+ } ;
711+
712+ const retried = makeRetriable ( function_ , { retries : 5 , minTimeout : 0 } ) ;
713+ const result = await retried ( 2 , 3 ) ;
714+ t . is ( result , 5 ) ;
715+ t . is ( callCount , 3 ) ;
716+ } ) ;
717+
718+ test ( 'makeRetriable passes arguments and options' , async t => {
719+ let lastArguments ;
720+ const function_ = ( ...arguments_ ) => {
721+ lastArguments = arguments_ ;
722+ throw new Error ( 'fail' ) ;
723+ } ;
724+
725+ const retried = makeRetriable ( function_ , { retries : 1 , minTimeout : 0 } ) ;
726+ await t . throwsAsync ( ( ) => retried ( 'foo' , 42 ) ) ;
727+ t . deepEqual ( lastArguments , [ 'foo' , 42 ] ) ;
728+ } ) ;
0 commit comments