From ca51ff8981d2efef2318afd030adb0edde481901 Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Tue, 7 Jan 2020 22:34:30 +0200 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/31250 Reviewed-By: Bryan English Reviewed-By: Colin Ihrig Reviewed-By: Richard Lau Reviewed-By: Ruben Bridgewater Reviewed-By: Rich Trott Reviewed-By: Anna Henningsen --- test/parallel/test-fs-rmdir-recursive.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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.