Skip to content

Commit 6725fa1

Browse files
cjihrigBethGriggs
authored andcommitted
test: use fs rimraf to refresh tmpdir
Now that the functionality is built into core, use it to refresh the test suite's tmpdir. PR-URL: #30569 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ben Coe <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 55c5baf commit 6725fa1

File tree

1 file changed

+1
-47
lines changed

1 file changed

+1
-47
lines changed

‎test/common/tmpdir.js‎

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -35,53 +35,7 @@ function rimrafSync(pathname,{spawn = true } ={}){
3535
}
3636
}
3737

38-
try{
39-
if(st.isDirectory())
40-
rmdirSync(pathname,null);
41-
else
42-
fs.unlinkSync(pathname);
43-
}catch(e){
44-
debug(e);
45-
switch(e.code){
46-
case'ENOENT':
47-
// It's not there anymore. Work is done. Exiting.
48-
return;
49-
50-
case'EPERM':
51-
// This can happen, try again with `rmdirSync`.
52-
break;
53-
54-
case'EISDIR':
55-
// Got 'EISDIR' even after testing `st.isDirectory()`...
56-
// Try again with `rmdirSync`.
57-
break;
58-
59-
default:
60-
throwe;
61-
}
62-
rmdirSync(pathname,e);
63-
}
64-
}
65-
66-
functionrmdirSync(p,originalEr){
67-
try{
68-
fs.rmdirSync(p);
69-
}catch(e){
70-
if(e.code==='ENOTDIR')
71-
throworiginalEr;
72-
if(e.code==='ENOTEMPTY'||e.code==='EEXIST'||e.code==='EPERM'){
73-
constenc=process.platform==='linux' ? 'buffer' : 'utf8';
74-
fs.readdirSync(p,enc).forEach((f)=>{
75-
if(finstanceofBuffer){
76-
constbuf=Buffer.concat([Buffer.from(p),Buffer.from(path.sep),f]);
77-
rimrafSync(buf);
78-
}else{
79-
rimrafSync(path.join(p,f));
80-
}
81-
});
82-
fs.rmdirSync(p);
83-
}
84-
}
38+
fs.rmdirSync(pathname,{recursive: true,maxRetries: 5});
8539
}
8640

8741
consttestRoot=process.env.NODE_TEST_DIR ?

0 commit comments

Comments
(0)