1
1
/* eslint-disable node-core/require-common-first, node-core/required-modules */
2
2
'use strict' ;
3
3
4
- const { execSync } = require ( 'child_process' ) ;
5
4
const fs = require ( 'fs' ) ;
6
5
const path = require ( 'path' ) ;
7
- const { debuglog } = require ( 'util' ) ;
8
6
9
- const debug = debuglog ( 'test/tmpdir' ) ;
10
-
11
- function rimrafSync ( pathname , { spawn = true } = { } ) {
12
- const st = ( ( ) => {
13
- try {
14
- return fs . lstatSync ( pathname ) ;
15
- } catch ( e ) {
16
- if ( fs . existsSync ( pathname ) )
17
- throw new Error ( `Something wonky happened rimrafing ${ pathname } ` ) ;
18
- debug ( e ) ;
19
- }
20
- } ) ( ) ;
21
-
22
- // If (!st) then nothing to do.
23
- if ( ! st ) {
24
- return ;
25
- }
26
-
27
- // On Windows first try to delegate rmdir to a shell.
28
- if ( spawn && process . platform === 'win32' && st . isDirectory ( ) ) {
29
- try {
30
- // Try `rmdir` first.
31
- execSync ( `rmdir /q /s ${ pathname } ` , { timeout : 1000 } ) ;
32
- } catch ( e ) {
33
- // Attempt failed. Log and carry on.
34
- debug ( e ) ;
35
- }
36
- }
37
-
38
- fs . rmdirSync ( pathname , { recursive : true , maxRetries : 5 } ) ;
7
+ function rimrafSync ( pathname ) {
8
+ fs . rmdirSync ( pathname , { maxRetries : 3 , recursive : true } ) ;
39
9
}
40
10
41
11
const testRoot = process . env . NODE_TEST_DIR ?
@@ -46,8 +16,8 @@ const testRoot = process.env.NODE_TEST_DIR ?
46
16
const tmpdirName = '.tmp.' + ( process . env . TEST_THREAD_ID || '0' ) ;
47
17
const tmpPath = path . join ( testRoot , tmpdirName ) ;
48
18
49
- function refresh ( opts = { } ) {
50
- rimrafSync ( this . path , opts ) ;
19
+ function refresh ( ) {
20
+ rimrafSync ( this . path ) ;
51
21
fs . mkdirSync ( this . path ) ;
52
22
}
53
23
0 commit comments