-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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: update test for url.parse() to match the exact error through re… #12879
test: update test for url.parse() to match the exact error through re… #12879
Conversation
].forEach(function(val) { | ||
assert.throws(function() { url.parse(val); }, TypeError); | ||
].forEach((val) => { | ||
assert.throws(() => { url.parse(val); }, /^TypeError: Parameter "url" must be a string, not undefined|boolean|number|object$/); |
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 you want to group undefined|boolean|number|object
in parentheses, right?
And could you also wrap at the ,
(align the function and the regexp vertically)? We try to keep lines under 80 characters – for regexps that’s not always possible, but it would still be nice to try and keep lines short :)
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 have included the suggested changes
Minor request that can be ignored: can you please update the commit message?
|
FWIW: I've posted an ESlint issue concerning this case: assert.throws(() => { url.parse('http://%E0%A4%A@fail'); }, /^URIError: URI malformed$/); |
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.
Otherwise LGTM.
@@ -13,8 +13,9 @@ const url = require('url'); | |||
0, | |||
[], | |||
{} |
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.
Add symbols while at it?
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.
Solved
assert.throws(function() { url.parse(val); }, TypeError); | ||
].forEach((val) => { | ||
assert.throws(() => { url.parse(val); }, | ||
/^TypeError: Parameter "url" must be a string, not (undefined|boolean|number|object)$/); |
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.
Our linter will not like this line, as it has more than 80 characters... :(
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.
@thefourtheye this is no longer true. Inline regex are now whitelisted.
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.
@lpinca Oops, sorry then. Thanks for letting me know... Checking it now.
}); | ||
|
||
assert.throws(function() { url.parse('http://%E0%A4%A@fail'); }, /^URIError: URI malformed$/); | ||
assert.throws(() => { url.parse('http://%E0%A4%A@fail'); }, /^URIError: URI malformed$/); |
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 believe this one is still long. I'm fine with the inline regex being whitelisted, but I think if there are multiple arguments we should still try to split them by line to avoid the long lines if possible.
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.
Solved
Since there was an update on this PR, can everyone please review it again so it can be merged? |
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.
Still LGTM
}); | ||
|
||
assert.throws(function() { url.parse('http://%E0%A4%A@fail'); }, /^URIError: URI malformed$/); | ||
assert.throws(() => { url.parse('http://%E0%A4%A@fail'); }, |
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.
very minor nit: the {
and }
around the body of the arrow function here can be omitted but isn't necessary.
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 would say the braces should not be omitted. That would change it from merely running url.parse()
to returning a value. If it was { return url.parse(...); }
then omitting the braces (and the return
) would make sense. It's mostly a semantic difference, but I think it's important.
Still LGTM. |
What can I do to improve this PR? |
@andreicioromila it can be merged. I'll run a new CI and if there are no surprises I'll land it. |
Landed in 7906ed5. |
Use a regex to validate the error message. PR-URL: #12879 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: David Cai <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: James M Snell <[email protected]>
Use a regex to validate the error message. PR-URL: nodejs#12879 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: David Cai <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: James M Snell <[email protected]>
When called with invalid values, url.parse() throws a TypeError with a specific message. Update test to check that the message matches the error thrown.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test