Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ca51ff8

Browse filesBrowse files
lundibundiMylesBorins
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 <bryan@bryanenglish.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 0b88c3d commit ca51ff8
Copy full SHA for ca51ff8

File tree

Expand file treeCollapse file tree

1 file changed

+9
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-10
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-fs-rmdir-recursive.js
+9-10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.