-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: added tests for unixtimestamp generation #11886
test: added tests for unixtimestamp generation #11886
Conversation
This test checks for the different input types for the generation of UNIX timestamps.
|
||
function throws(input) { | ||
assert.throws(() => fs._toUnixTimestamp(input) | ||
, 'Error: Cannot parse time: ' + input); |
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 make the second argument a regular expression (with ^
and $
to match the whole thing).
var assert = require('assert'); | ||
var fs = require('fs'); | ||
|
||
[undefined, null, {}, []].forEach((input) => throws(input)); |
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.
You could probably just inline throws
like you did in the "does not throw" case.
'use strict'; | ||
require('../common'); | ||
var assert = require('assert'); | ||
var fs = require('fs'); |
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/var/const
|
||
function throws(input) { | ||
assert.throws(() => fs._toUnixTimestamp(input) | ||
, 'Error: Cannot parse time: ' + input); |
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.
The second argument here should be either the type of error thrown or a check function. You can use common.expectsError()
(see here)
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.
Alternatively, make this second argument a regex... new RegExp(
^Error: Cannot parse time: )
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.
@jasnell I guess the regex is going to fit better...let me push the change
Might want to add tests for |
I do have a PR read for the NaN as the current behaviour is to generate a timestamp when it should just return an error. Let me add Infinity and negative tho. |
|
||
[undefined, null, []].forEach((input) => { | ||
assert.throws(() => fs._toUnixTimestamp(input) | ||
, new RegExp('^Error: Cannot parse time: ' + input + '$')); |
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.
It passed the linter, but the comma that starts this line, and the comma starting line 12 should be moved to the preceding lines.
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 with a tiny style nit.
Landed in 6aed32c with the comma style fix I suggested. Thanks! |
This test checks for the different input types for the generation of UNIX timestamps in the fs module. PR-URL: #11886 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
This test checks for the different input types for the generation of UNIX timestamps in the fs module. PR-URL: nodejs#11886 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
This PR need backport to v7 |
This test checks for the different input types for the generation of
UNIX timestamps.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test fs