Skip to content

Commit b471bd8

Browse files
committed
test: remove custom rimraf
Use internal recursive rmdir() in the common/tmpdir module we use in tests.
1 parent 8a5c7f6 commit b471bd8

File tree

4 files changed

+12
-48
lines changed

4 files changed

+12
-48
lines changed

test/async-hooks/test-pipeconnectwrap.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ const { checkInvocations } = require('./hook-checks');
88
const tmpdir = require('../common/tmpdir');
99
const net = require('net');
1010

11-
// Spawning messes up `async_hooks` state.
12-
tmpdir.refresh({ spawn: false });
11+
tmpdir.refresh();
1312

1413
const hooks = initHooks();
1514
hooks.enable();

test/async-hooks/test-statwatcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const path = require('path');
1111
if (!common.isMainThread)
1212
common.skip('Worker bootstrapping works differently -> different async IDs');
1313

14-
tmpdir.refresh({ spawn: false });
14+
tmpdir.refresh();
1515

1616
const file1 = path.join(tmpdir.path, 'file1');
1717
const file2 = path.join(tmpdir.path, 'file2');

test/common/README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -898,11 +898,7 @@ The `tmpdir` module supports the use of a temporary directory for testing.
898898

899899
The realpath of the testing temporary directory.
900900

901-
### refresh(\[opts\])
902-
903-
* `opts` [<Object>][] (optional) Extra options.
904-
* `spawn` [<boolean>][] (default: `true`) Indicates that `refresh` is
905-
allowed to optionally spawn a subprocess.
901+
### refresh()
906902

907903
Deletes and recreates the testing temporary directory.
908904

test/common/tmpdir.js

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,10 @@
11
/* eslint-disable node-core/require-common-first, node-core/required-modules */
22
'use strict';
33

4-
const { execSync } = require('child_process');
54
const fs = require('fs');
65
const path = require('path');
7-
const { debuglog } = require('util');
86
const { isMainThread } = require('worker_threads');
97

10-
const debug = debuglog('test/tmpdir');
11-
12-
function rimrafSync(pathname, { spawn = true } = {}) {
13-
const st = (() => {
14-
try {
15-
return fs.lstatSync(pathname);
16-
} catch (e) {
17-
if (fs.existsSync(pathname))
18-
throw new Error(`Something wonky happened rimrafing ${pathname}`);
19-
debug(e);
20-
}
21-
})();
22-
23-
// If (!st) then nothing to do.
24-
if (!st) {
25-
return;
26-
}
27-
28-
// On Windows first try to delegate rmdir to a shell.
29-
if (spawn && process.platform === 'win32' && st.isDirectory()) {
30-
try {
31-
// Try `rmdir` first.
32-
execSync(`rmdir /q /s ${pathname}`, { timeout: 1000 });
33-
} catch (e) {
34-
// Attempt failed. Log and carry on.
35-
debug(e);
36-
}
37-
}
38-
39-
fs.rmdirSync(pathname, { recursive: true, maxRetries: 5 });
40-
41-
if (fs.existsSync(pathname))
42-
throw new Error(`Unable to rimraf ${pathname}`);
43-
}
44-
458
const testRoot = process.env.NODE_TEST_DIR ?
469
fs.realpathSync(process.env.NODE_TEST_DIR) : path.resolve(__dirname, '..');
4710

@@ -52,8 +15,14 @@ const tmpdirName = '.tmp.' +
5215
const tmpPath = path.join(testRoot, tmpdirName);
5316

5417
let firstRefresh = true;
55-
function refresh(opts = {}) {
56-
rimrafSync(this.path, opts);
18+
function refresh() {
19+
try {
20+
fs.rmdirSync(this.path, { recursive: true });
21+
} catch (e) {
22+
if (e.code !== 'ENOENT') {
23+
throw e;
24+
}
25+
}
5726
fs.mkdirSync(this.path);
5827

5928
if (firstRefresh) {
@@ -70,7 +39,7 @@ function onexit() {
7039
process.chdir(testRoot);
7140

7241
try {
73-
rimrafSync(tmpPath, { spawn: false });
42+
fs.rmdirSync(tmpPath, { recursive: true });
7443
} catch (e) {
7544
console.error('Can\'t clean tmpdir:', tmpPath);
7645

0 commit comments

Comments
 (0)