Uh oh!
There was an error while loading. Please reload this page.
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…#12879andreicioromila wants to merge 3 commits into
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.
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.
I have included the suggested changes
lpinca
commented
May 7, 2017
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:URImalformed$/); |
DavidCai1111
commented
May 7, 2017
| @@ -13,8 +13,9 @@ const url = require('url'); | |||
| 0, | |||
| [], | |||
| {} | |||
| 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.
Our linter will not like this line, as it has more than 80 characters... :(
There was a problem hiding this comment.
@thefourtheye this is no longer true. Inline regex are now whitelisted.
There was a problem hiding this comment.
@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.
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.
jasnell
commented
May 10, 2017
andreicioromila
commented
May 12, 2017
Since there was an update on this PR, can everyone please review it again so it can be merged? |
| }); | ||
| 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.
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.
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.
lpinca
commented
May 12, 2017
Still LGTM. |
andreicioromila
commented
May 16, 2017
What can I do to improve this PR? |
lpinca
commented
May 16, 2017
@andreicioromila it can be merged. I'll run a new CI and if there are no surprises I'll land it. |
lpinca
commented
May 16, 2017
lpinca
commented
May 16, 2017
Landed in 7906ed5. |
Use a regex to validate the error message. PR-URL: #12879 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: David Cai <davidcai1993@yahoo.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Use a regex to validate the error message. PR-URL: nodejs#12879 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: David Cai <davidcai1993@yahoo.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
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