Skip to content
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

Closed
wants to merge 3 commits into from
Closed

test: update test for url.parse() to match the exact error through re… #12879

wants to merge 3 commits into from

Conversation

andreicioromila
Copy link
Contributor

@andreicioromila andreicioromila commented May 7, 2017

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), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

test

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label May 7, 2017
].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$/);
Copy link
Member

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 :)

Copy link
Contributor Author

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

@lpinca
Copy link
Member

lpinca commented May 7, 2017

Minor request that can be ignored: can you please update the commit message?
Something like this should work.

test: add regex check in test-url-parse-invalid-input

Use a regex to validate the error message.

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented May 7, 2017

FWIW: I've posted an ESlint issue concerning this case:

assert.throws(() => { url.parse('http://%E0%A4%A@fail'); }, /^URIError: URI malformed$/);

@DavidCai1111
Copy link
Member

@mscdex mscdex added the url Issues and PRs related to the legacy built-in url module. label May 7, 2017
Copy link
Member

@TimothyGu TimothyGu left a 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,
[],
{}
Copy link
Member

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?

Copy link
Contributor Author

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)$/);
Copy link
Contributor

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... :(

Copy link
Member

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.

Copy link
Contributor

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$/);
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved

@jasnell
Copy link
Member

jasnell commented May 10, 2017

@andreicioromila
Copy link
Contributor Author

Since there was an update on this PR, can everyone please review it again so it can be merged?

Copy link
Member

@jasnell jasnell left a 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'); },
Copy link
Member

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.

Copy link
Member

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.

@lpinca
Copy link
Member

lpinca commented May 12, 2017

Still LGTM.

@andreicioromila
Copy link
Contributor Author

What can I do to improve this PR?
Or can this be merged?

@lpinca
Copy link
Member

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
Copy link
Member

lpinca commented May 16, 2017

@lpinca
Copy link
Member

lpinca commented May 16, 2017

Landed in 7906ed5.

@lpinca lpinca closed this May 16, 2017
lpinca pushed a commit that referenced this pull request May 16, 2017
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>
anchnk pushed a commit to anchnk/node that referenced this pull request May 19, 2017
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>
@jasnell jasnell mentioned this pull request May 28, 2017
@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Issues and PRs related to the tests. url Issues and PRs related to the legacy built-in url module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.