-
Notifications
You must be signed in to change notification settings - Fork 30k
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: refactor mkdtemp test and added async #12080
test: refactor mkdtemp test and added async #12080
Conversation
|
||
function failAsync(value) { | ||
assert.throws( | ||
() => fs.mkdtemp(value, () => {}), |
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.
Nit: there is common.noop
, so I think it makes sense to use it.
6c6690f
to
278d515
Compare
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.
I'd prefer the variables are renamed. As they currently are they sound like they refer to the values that occurred during execution and are being tested rather than the expected error or test inputs.
const assert = require('assert'); | ||
const fs = require('fs'); | ||
|
||
const assertedError = /^TypeError: filename prefix is required$/; |
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 this be expectedError
?
const fs = require('fs'); | ||
|
||
const assertedError = /^TypeError: filename prefix is required$/; | ||
const assertValues = [undefined, null, 0, true, false, 1]; |
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.
prefixValues
?
278d515
to
1323058
Compare
|
||
function failAsync(value) { | ||
assert.throws( | ||
() => fs.mkdtemp(value, common.noop), |
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.
Should the callback be be () => common.fail('Async callback should not be called')
?
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.
That could work!
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.
On second thought, I'm not sure that can happen because of the throw, but it would be good insurance anyways imo
Oops, didn't mean to approve. Oh well lol |
1323058
to
b83338c
Compare
function failAsync(value) { | ||
assert.throws( | ||
() => fs.mkdtemp(value, () => { | ||
common.fail('Async callback should not be called'); |
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.
I think this can be common.mustNotCall()
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.
Semantically the two have the same result. We should probably start defining a list of guidelines to use (or maybe I just missed it) for tests.
@cjihrig I guess common.mustNotCall()
should be the right pick here, I am right?
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.
common.mustNotCall()
was added to prevent calling common.fail()
in an otherwise empty function.
b83338c
to
12cc305
Compare
This test refactored the original test for mkdtempSync prefix validation and added the test also for the async function mkdtemp.
12cc305
to
daa39cd
Compare
This test refactored the original test for mkdtempSync prefix validation and added the test also for the async function mkdtemp. PR-URL: #12080 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Landed in 085c1f8 |
This test refactored the original test for mkdtempSync prefix validation and added the test also for the async function mkdtemp. PR-URL: nodejs#12080 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This test does not pass on LTS. would you be willing to backport to v6.x-staging? |
This test refactored the original test for mkdtempSync prefix validation
and added the test also for the async function mkdtemp.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test fs