diff --git a/test/parallel/test-fs-rmdir-recursive.js b/test/parallel/test-fs-rmdir-recursive.js index 0d9b9f570745f8..db8d4b14dac7cf 100644 --- a/test/parallel/test-fs-rmdir-recursive.js +++ b/test/parallel/test-fs-rmdir-recursive.js @@ -6,10 +6,13 @@ const assert = require('assert'); const fs = require('fs'); const path = require('path'); const { validateRmdirOptions } = require('internal/fs/utils'); -let count = 0; tmpdir.refresh(); +let count = 0; +const nextDirPath = (name = 'rmdir-recursive') => + path.join(tmpdir.path, `${name}-${count++}`); + function makeNonEmptyDirectory(depth, files, folders, dirname, createSymLinks) { fs.mkdirSync(dirname, { recursive: true }); fs.writeFileSync(path.join(dirname, 'text.txt'), 'hello', 'utf8'); @@ -89,27 +92,24 @@ function removeAsync(dir) { // Test the asynchronous version { // Create a 4-level folder hierarchy including symlinks - let dir = `rmdir-recursive-${count}`; + let dir = nextDirPath(); makeNonEmptyDirectory(4, 10, 2, dir, true); removeAsync(dir); // Create a 2-level folder hierarchy without symlinks - count++; - dir = `rmdir-recursive-${count}`; + dir = nextDirPath(); makeNonEmptyDirectory(2, 10, 2, dir, false); removeAsync(dir); // Create a flat folder including symlinks - count++; - dir = `rmdir-recursive-${count}`; + dir = nextDirPath(); makeNonEmptyDirectory(1, 10, 2, dir, true); removeAsync(dir); } // Test the synchronous version. { - count++; - const dir = `rmdir-recursive-${count}`; + const dir = nextDirPath(); makeNonEmptyDirectory(4, 10, 2, dir, true); // Removal should fail without the recursive option set to true. @@ -132,8 +132,7 @@ function removeAsync(dir) { // Test the Promises based version. (async () => { - count++; - const dir = `rmdir-recursive-${count}`; + const dir = nextDirPath(); makeNonEmptyDirectory(4, 10, 2, dir, true); // Removal should fail without the recursive option set to true.