diff --git a/test/parallel/test-fs-mkdir.js b/test/parallel/test-fs-mkdir.js index f5fecbe1572aaf..d07aab53769299 100644 --- a/test/parallel/test-fs-mkdir.js +++ b/test/parallel/test-fs-mkdir.js @@ -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(() => {}); diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index bcfaaf3890d377..714f1db05d5494 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -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()); @@ -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.