@@ -15,33 +15,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
1515const fixture = path . join . bind ( path , __dirname , 'fixtures' ) ;
1616const binary = process . platform === 'win32' ? 'gifsicle.exe' : 'gifsicle' ;
1717
18- async function safeRemoveDir ( dir , retries = 3 ) {
19- if ( process . platform === 'win32' ) {
20- // Retry logic only for Windows
21- for ( let i = 0 ; i < retries ; i ++ ) {
22- try {
23- // eslint-disable-next-line no-await-in-loop
24- await fsP . rm ( dir , { force : true , recursive : true } ) ;
25- break ;
26- } catch ( error ) {
27- if ( error . code === 'EPERM' && i < retries - 1 ) {
28- // Wait a bit and retry
29- // eslint-disable-next-line no-await-in-loop
30- await new Promise ( resolve => {
31- setTimeout ( resolve , 100 ) ;
32- } ) ;
33- } else {
34- throw error ;
35- }
36- }
37- }
38- } else {
39- // Directly remove the directory on non-Windows platforms
40- await fsP . rm ( dir , { force : true , recursive : true } ) ;
41- }
42- }
43-
44- const removeDirs = dirs => Promise . all ( dirs . map ( dir => safeRemoveDir ( dir ) ) ) ;
18+ const removeDir = async dir => fsP . rm ( dir , { force : true , recursive : true } ) ;
4519
4620test . beforeEach ( ( ) => {
4721 nock ( 'http://foo.com' )
@@ -101,7 +75,7 @@ test('verify that a binary is working', async t => {
10175
10276 await bin . run ( ) ;
10377 t . true ( await pathExists ( bin . path ( ) ) ) ;
104- await removeDirs ( [ bin . dest ( ) , temporaryDir ] ) ;
78+ await removeDir ( bin . dest ( ) ) ;
10579} ) ;
10680
10781test ( 'meet the desired version' , async t => {
@@ -114,7 +88,7 @@ test('meet the desired version', async t => {
11488
11589 await bin . run ( ) ;
11690 t . true ( await pathExists ( bin . path ( ) ) ) ;
117- await removeDirs ( [ bin . dest ( ) , temporaryDir ] ) ;
91+ await removeDir ( bin . dest ( ) ) ;
11892} ) ;
11993
12094test ( 'download files even if they are not used' , async t => {
@@ -134,7 +108,7 @@ test('download files even if they are not used', async t => {
134108 t . is ( files [ 1 ] , 'gifsicle.exe' ) ;
135109 t . is ( files [ 2 ] , 'test.js' ) ;
136110
137- await removeDirs ( [ bin . dest ( ) , temporaryDir ] ) ;
111+ await removeDir ( bin . dest ( ) ) ;
138112} ) ;
139113
140114test ( 'skip running binary check' , async t => {
@@ -146,7 +120,7 @@ test('skip running binary check', async t => {
146120
147121 await bin . run ( [ '--shouldNotFailAnyway' ] ) ;
148122 t . true ( await pathExists ( bin . path ( ) ) ) ;
149- await removeDirs ( [ bin . dest ( ) , temporaryDir ] ) ;
123+ await removeDir ( bin . dest ( ) ) ;
150124} ) ;
151125
152126test ( 'error if no binary is found and no source is provided' , async t => {
@@ -160,7 +134,7 @@ test('error if no binary is found and no source is provided', async t => {
160134 undefined ,
161135 'No binary found matching your system. It\'s probably not supported.' ,
162136 ) ;
163- await removeDirs ( [ temporaryDir ] ) ;
137+ await removeDir ( temporaryDir ) ;
164138} ) ;
165139
166140test ( 'downloaded files are set to be executable' , async t => {
@@ -177,5 +151,5 @@ test('downloaded files are set to be executable', async t => {
177151 const files = fs . readdirSync ( bin . dest ( ) ) ;
178152
179153 await t . true ( files . every ( async file => isexe ( path . join ( bin . dest ( ) , file ) ) ) ) ;
180- await removeDirs ( [ temporaryDir ] ) ;
154+ await removeDir ( temporaryDir ) ;
181155} ) ;
0 commit comments