Skip to content

Commit f03ece3

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

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

test/common/tmpdir.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,27 @@ 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';
9+
const { escapePOSIXShell } = require('./index.js');
810

911
function rmSync(pathname, useSpawn) {
1012
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-
);
13+
if (isUnixLike) {
14+
for (let i = 0; i < 3; i++) {
15+
const { status } = spawnSync(...escapePOSIXShell`rm -rf "${pathname}"`);
16+
if (status === 0) {
17+
break;
18+
}
19+
}
20+
} else {
21+
spawnSync(
22+
process.execPath,
23+
[
24+
'-e',
25+
`fs.rmSync(${JSON.stringify(pathname)}, { maxRetries: 3, recursive: true, force: true });`,
26+
],
27+
);
28+
}
1929
} else {
2030
fs.rmSync(pathname, { maxRetries: 3, recursive: true, force: true });
2131
}

0 commit comments

Comments
 (0)