-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: extended test to makeCallback cb type check #12140
Conversation
assert.throws(test(/foo/), cbTypeError); | ||
assert.throws(test([]), cbTypeError); | ||
assert.throws(test({}), cbTypeError); | ||
function invalidCallbackThowsTests() { |
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.
s/Thows/Throws/ ?
return function() { | ||
// fs.stat() calls makeCallback() on its second argument | ||
fs.stat(__filename, cb); | ||
fs.unlink(__filename, cb); |
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.
Doesn't this delete the file? How about using another method that calls makeCallback()
like, I don't know, fs.chmod()
?
The comment should also be updated.
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.
Good point...but any of the operations which are calling makeCallback
have an impact on the file. I would then use fs.mkdtemp
which only creates a temp dir which we can delete at the end of the test. Does it make sense to you @lpinca?
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.
Yes works for me.
// Passing undefined/nothing calls rethrow() internally, which emits a warning | ||
assert.doesNotThrow(testMakeStatsCallback()); | ||
|
||
function invalidCallbackThowsTests() { |
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.
s/Thows/Throws/ ?
83c8316
to
10a9547
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.
LGTM. One suggestion tho: the process.once('warning', ...)
bit can be replaced by a call to common.expectWarning(...)
} | ||
|
||
//invalidCallbackThrowsTests(); |
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.
Can you remove this.
|
||
function test(cb) { | ||
const tmpDir = '/tmp'; |
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 this be os.tmpdir()
? Alternatively, there is common.tmpDir
for use in tests.
424fcb6
to
21f94d7
Compare
// fs.stat() calls makeCallback() on its second argument | ||
fs.stat(__filename, cb); | ||
// fs.mkdtemp() calls makeCallback() on its third argument | ||
fs.mkdtemp(`${common.tmpDir}${sep}`, {}, cb); |
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.
This throws an error if the test is run in isolation node test/parallel/test-fs-make-callback.js
and common.tmpDir
has not been created.
I think it makes sense to run common.refreshTmpDir()
at the beginning of the test.
21f94d7
to
c0b4f0d
Compare
// Verify the case where a callback function is provided | ||
assert.doesNotThrow(testMakeStatsCallback(common.noop)); | ||
|
||
process.once('warning', common.mustCall((warning) => { |
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 use common.expectWarning()
for consistency.
makeCallback and makeStatsCallback are both tested intedependently. Fixes: nodejs#12136
c0b4f0d
to
bee1920
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.
LGTM
CI is green landing |
landed as 53828e8 |
makeCallback and makeStatsCallback are both tested intedependently. PR-URL: #12140 Fixes: #12136 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Should this be backported to |
I'm backporting this with #12270 |
makeCallback and makeStatsCallback are both tested intedependently. PR-URL: #12140 Backport-PR-URL: #13785 Fixes: #12136 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
makeCallback and makeStatsCallback are both tested intedependently. PR-URL: #12140 Backport-PR-URL: #13785 Fixes: #12136 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
makeCallback and makeStatsCallback are both tested intedependently. PR-URL: #12140 Backport-PR-URL: #13785 Fixes: #12136 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
makeCallback and makeStatsCallback are both tested intedependently. PR-URL: nodejs/node#12140 Fixes: nodejs/node#12136 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
makeCallback and makeStatsCallback are both tested intedependently.
Fixes: #12136
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test, fs