Skip to content
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

fs: update tests for rmdir() #29815

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 36 additions & 8 deletions test/parallel/test-fs-rmdir-recursive.js
Expand Up @@ -10,17 +10,41 @@ let count = 0;

tmpdir.refresh();

function makeNonEmptyDirectory() {
const dirname = `rmdir-recursive-${count}`;
fs.mkdirSync(path.join(dirname, 'foo', 'bar', 'baz'), { recursive: true });
function makeNonEmptyDirectory (depth, files, folders, dirname) {
fs.mkdirSync(dirname, { recursive: true });
fs.writeFileSync(path.join(dirname, 'text.txt'), 'hello', 'utf8');
count++;
return dirname;

var o = { flag: 'wx' }
BridgeAR marked this conversation as resolved.
Show resolved Hide resolved
if (process.version.match(/^v0\.8/))
BridgeAR marked this conversation as resolved.
Show resolved Hide resolved
o = 'utf8'

for (var f = files; f > 0; f--) {
fs.writeFileSync(dirname + '/f-' + depth + '-' + f, '', o)
BridgeAR marked this conversation as resolved.
Show resolved Hide resolved
}

// valid symlink
fs.symlinkSync('f-' + depth + '-1', dirname + '/link-' + depth + '-good', 'file')

// invalid symlink
fs.symlinkSync('does-not-exist', dirname + '/link-' + depth + '-bad', 'file')

// file with a name that looks like a glob
fs.writeFileSync(dirname + '/[a-z0-9].txt', '', o)

depth--
if (depth <= 0)
return dirname;
BridgeAR marked this conversation as resolved.
Show resolved Hide resolved

for (f = folders; f > 0; f--) {
fs.mkdirSync(dirname + '/folder-' + depth + '-' + f, { recursive: true });
makeNonEmptyDirectory(depth, files, folders, dirname + '/d-' + depth + '-' + f)
}
}

// Test the asynchronous version.
{
const dir = makeNonEmptyDirectory();
const dir = `rmdir-recursive-${count}`;
makeNonEmptyDirectory(4, 10, 2, dir);

// Removal should fail without the recursive option.
fs.rmdir(dir, common.mustCall((err) => {
Expand Down Expand Up @@ -50,7 +74,9 @@ function makeNonEmptyDirectory() {

// Test the synchronous version.
{
const dir = makeNonEmptyDirectory();
count++;
const dir = `rmdir-recursive-${count}`;
makeNonEmptyDirectory(4, 10, 2, dir);

// Removal should fail without the recursive option set to true.
common.expectsError(() => {
Expand All @@ -72,7 +98,9 @@ function makeNonEmptyDirectory() {

// Test the Promises based version.
(async () => {
const dir = makeNonEmptyDirectory();
count++;
const dir = `rmdir-recursive-${count}`;
makeNonEmptyDirectory(4, 10, 2, dir);

// Removal should fail without the recursive option set to true.
assert.rejects(fs.promises.rmdir(dir), { syscall: 'rmdir' });
Expand Down