@@ -4,11 +4,10 @@ import {log} from 'e2ed/utils';
44import type { UserWorker } from 'autotests/types' ;
55import type { ClientFunction } from 'e2ed/types' ;
66
7- const clientGetUsers = createClientFunction (
8- ( delay : number ) =>
9- fetch ( `https://reqres.in/api/users?delay=${ delay } ` , { method : 'GET' } ) . then ( ( res ) => res . json ( ) ) ,
10- { name : 'getUsers' , timeout : 6_000 } ,
11- ) ;
7+ type GetUsersOptions = Readonly < { delay ?: number ; retries ?: number } > | undefined ;
8+
9+ let clientGetUsers : ClientFunction < [ number ] , unknown > | undefined ;
10+ let clientGetUsersRetries : number | undefined ;
1211
1312/**
1413 * Adds user-worker.
@@ -26,8 +25,20 @@ export const addUser: ClientFunction<[UserWorker, number?], Promise<object>> = c
2625/**
2726 * Get list of user-workers.
2827 */
29- export const getUsers = ( delay : number = 0 ) : Promise < unknown > => {
28+ export const getUsers = ( { delay = 0 , retries = 0 } : GetUsersOptions = { } ) : Promise < unknown > => {
3029 log ( `Send API request with delay = ${ delay } s` ) ;
3130
31+ if ( clientGetUsers === undefined || clientGetUsersRetries !== retries ) {
32+ clientGetUsersRetries = retries ;
33+
34+ clientGetUsers = createClientFunction (
35+ ( clientDelay : number ) =>
36+ fetch ( `https://reqres.in/api/users?delay=${ clientDelay } ` , { method : 'GET' } ) . then (
37+ ( res ) => res . json ( ) as unknown ,
38+ ) ,
39+ { name : 'getUsers' , retries, timeout : 6_000 } ,
40+ ) ;
41+ }
42+
3243 return clientGetUsers ( delay ) ;
3344} ;
0 commit comments