Skip to content

test: fix recursive rm test to actually use tmpdir #31250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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