Skip to content

Commit 31a13dc

Browse files
lundibundicodebytere
authored andcommitted
test: fix recursive rm test to actually use tmpdir
Previously folders were created in the root of the project and would therefore stay there in case of errors. This changes the test to create all directories in the temp directory (`tmpdir.path`). PR-URL: #31250 Reviewed-By: Bryan English <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 320ac13 commit 31a13dc

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

test/parallel/test-fs-rmdir-recursive.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ const assert = require('assert');
66
const fs = require('fs');
77
const path = require('path');
88
const { validateRmdirOptions } = require('internal/fs/utils');
9-
let count = 0;
109

1110
tmpdir.refresh();
1211

12+
let count = 0;
13+
const nextDirPath = (name = 'rmdir-recursive') =>
14+
path.join(tmpdir.path, `${name}-${count++}`);
15+
1316
function makeNonEmptyDirectory(depth, files, folders, dirname, createSymLinks) {
1417
fs.mkdirSync(dirname, { recursive: true });
1518
fs.writeFileSync(path.join(dirname, 'text.txt'), 'hello', 'utf8');
@@ -89,27 +92,24 @@ function removeAsync(dir) {
8992
// Test the asynchronous version
9093
{
9194
// Create a 4-level folder hierarchy including symlinks
92-
let dir = `rmdir-recursive-${count}`;
95+
let dir = nextDirPath();
9396
makeNonEmptyDirectory(4, 10, 2, dir, true);
9497
removeAsync(dir);
9598

9699
// Create a 2-level folder hierarchy without symlinks
97-
count++;
98-
dir = `rmdir-recursive-${count}`;
100+
dir = nextDirPath();
99101
makeNonEmptyDirectory(2, 10, 2, dir, false);
100102
removeAsync(dir);
101103

102104
// Create a flat folder including symlinks
103-
count++;
104-
dir = `rmdir-recursive-${count}`;
105+
dir = nextDirPath();
105106
makeNonEmptyDirectory(1, 10, 2, dir, true);
106107
removeAsync(dir);
107108
}
108109

109110
// Test the synchronous version.
110111
{
111-
count++;
112-
const dir = `rmdir-recursive-${count}`;
112+
const dir = nextDirPath();
113113
makeNonEmptyDirectory(4, 10, 2, dir, true);
114114

115115
// Removal should fail without the recursive option set to true.
@@ -132,8 +132,7 @@ function removeAsync(dir) {
132132

133133
// Test the Promises based version.
134134
(async () => {
135-
count++;
136-
const dir = `rmdir-recursive-${count}`;
135+
const dir = nextDirPath();
137136
makeNonEmptyDirectory(4, 10, 2, dir, true);
138137

139138
// Removal should fail without the recursive option set to true.

0 commit comments

Comments
 (0)