-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
test: check parameter type of fs.mkdir() #22616
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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((i) => { | ||
assert.rejects( | ||
// mkdtemp() expects to get a string prefix. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, sorry. this is wrong copy and paste. Fixed this. |
||
async () => mkdir(dir, { recursive: i }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small oversight: it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your review. I fixed this. |
||
{ | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
name: 'TypeError [ERR_INVALID_ARG_TYPE]', | ||
message: 'The "recursive" argument must be of type boolean. ' + | ||
`Received type ${typeof i}` | ||
} | ||
); | ||
}); | ||
} | ||
|
||
await mkdtemp(path.resolve(tmpDir, 'FOO')); | ||
assert.rejects( | ||
// mkdtemp() expects to get a string prefix. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rename
i
torecursive
, and this can just be{ recursive }
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your review. Fixed this.