Skip to content

Commit 682b29e

Browse files
committed
test: execute shell directly for refresh()
1 parent b181535 commit 682b29e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

test/common/tmpdir.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,26 @@ const fs = require('fs');
55
const path = require('path');
66
const { pathToFileURL } = require('url');
77
const { isMainThread } = require('worker_threads');
8+
const isUnixLike = process.platform !== 'win32';
89

910
function rmSync(pathname, useSpawn) {
1011
if (useSpawn) {
11-
const escapedPath = pathname.replaceAll('\\', '\\\\');
12-
spawnSync(
13-
process.execPath,
14-
[
15-
'-e',
16-
`require("fs").rmSync("${escapedPath}", { maxRetries: 3, recursive: true, force: true });`,
17-
],
18-
);
12+
if (isUnixLike) {
13+
for (let i = 0; i < 3; i++) {
14+
const { status } = spawnSync(`rm -rf ${pathname}`);
15+
if (status === 0) {
16+
break;
17+
}
18+
}
19+
} else {
20+
spawnSync(
21+
process.execPath,
22+
[
23+
'-e',
24+
`fs.rmSync(${JSON.stringify(pathname)}, { maxRetries: 3, recursive: true, force: true });`,
25+
],
26+
);
27+
}
1928
} else {
2029
fs.rmSync(pathname, { maxRetries: 3, recursive: true, force: true });
2130
}

0 commit comments

Comments
 (0)