Skip to content
Closed
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions test/parallel/test-fs-mkdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,32 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) {
});
}

// mkdirSync and mkdir require options.recursive to be a boolean.
// Anything else generates an error.
{
const pathname = path.join(tmpdir.path, nextdir());
['', 1, {}, [], null, Symbol('test'), () => {}].forEach((recursive) => {
common.expectsError(
() => fs.mkdir(pathname, { recursive }, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "recursive" argument must be of type boolean. Received ' +
`type ${typeof recursive}`
}
);
common.expectsError(
() => fs.mkdirSync(pathname, { recursive }),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "recursive" argument must be of type boolean. Received ' +
`type ${typeof recursive}`
}
);
});
}

// Keep the event loop alive so the async mkdir() requests
// have a chance to run (since they don't ref the event loop).
process.nextTick(() => {});
34 changes: 34 additions & 0 deletions test/parallel/test-fs-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ function verifyStatObject(stat) {
assert.deepStrictEqual(list, ['baz2.js', 'dir']);
await rmdir(newdir);

// mkdir when options is number.
{
const dir = path.join(tmpDir, nextdir());
await mkdir(dir, 777);
stats = await stat(dir);
assert(stats.isDirectory());
}

// mkdir when options is string.
{
const dir = path.join(tmpDir, nextdir());
await mkdir(dir, '777');
stats = await stat(dir);
assert(stats.isDirectory());
}

// mkdirp when folder does not yet exist.
{
const dir = path.join(tmpDir, nextdir(), nextdir());
Expand Down Expand Up @@ -250,6 +266,24 @@ function verifyStatObject(stat) {
assert(stats.isDirectory());
}

// mkdirp require recursive option to be a boolean.
// Anything else generates an error.
{
const dir = path.join(tmpDir, nextdir(), nextdir());
['', 1, {}, [], null, Symbol('test'), () => {}].forEach((recursive) => {
assert.rejects(
// mkdir() expects to get a boolean value for options.recursive.
async () => mkdir(dir, { recursive }),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
message: 'The "recursive" argument must be of type boolean. ' +
`Received type ${typeof recursive}`
}
);
});
}

await mkdtemp(path.resolve(tmpDir, 'FOO'));
assert.rejects(
// mkdtemp() expects to get a string prefix.
Expand Down