Skip to content

Commit

Permalink
test: fix recursive rm test to actually use tmpdir
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lundibundi authored and Trott committed Jan 10, 2020
1 parent e4bff13 commit a566c05
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions test/parallel/test-fs-rmdir-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit a566c05

Please sign in to comment.