-
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: add regex #11193
test: add regex #11193
Conversation
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 change the commit message to be more informative, for example, test: verify error message from assert.ifError
? Thanks!
test/parallel/test-assert.js
Outdated
@@ -378,7 +378,7 @@ try { | |||
assert.strictEqual(true, threw, | |||
'a.doesNotThrow is not catching type matching errors'); | |||
|
|||
assert.throws(function() { assert.ifError(new Error('test error')); }); | |||
assert.throws(function() { assert.ifError(new Error('test error')), /^([A-Za-z])\w+$/}); |
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 regexp is probably too general. Since the error being thrown here is known, can you change that to /^Error: test error$/
?
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.
@joyeecheung I do not understand your request, can you please expound.
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.
In this repo we try to make the validation of the error message to be as concrete as possible. For example:
assert.throws(
() => {
throw new Error('Wrong value');
},
/^Error: Wrong value$/ // Instead of something like /Wrong value/
);
There is an ongoing PR to update our guide on this: #11150
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.
In this line, since according to the documentation of assert.ifError(value)
:
Throws value if value is truthy.
We are checking that the truthy new Error('test error')
passed to assert.ifError()
should be rethrown, hence the error message from the block should be /^Error: test error$/
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.
@joyeecheung thanks for taking your time, I now get your point.
test/parallel/test-assert.js
Outdated
@@ -378,7 +378,7 @@ try { | |||
assert.strictEqual(true, threw, | |||
'a.doesNotThrow is not catching type matching errors'); | |||
|
|||
assert.throws(function() { assert.ifError(new Error('test error')); }); | |||
assert.throws(function() { assert.ifError(new Error('test error')), /^Error: test error/}); |
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 the regular expression should come after the }
. Also, please add a $
to the end of the regex.
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.
@cjihrig thanks for pointing that out, I had missed the part that the regex is the optional argument to assert.throws()
test/parallel/test-assert.js
Outdated
@@ -378,7 +378,7 @@ try { | |||
assert.strictEqual(true, threw, | |||
'a.doesNotThrow is not catching type matching errors'); | |||
|
|||
assert.throws(function() { assert.ifError(new Error('test error')); }); | |||
assert.throws(function() { assert.ifError(new Error('test error'))}, /^Error: test error$/); |
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're going to need to add the semicolon back in.
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.
Also, please add a space before the closing curly brace for symmetry.
@abouthiroppy could you know why the tests are failing? |
Please fix this lint error. |
The long line has been fixed, but this is still returning a lint error due to indentation problems introduced in the fix for the log line. @jobala Please run |
@Trott Did you mean |
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 if CI is green.
Argh! Yeah, |
@Trott thanks for the pointer. |
Verify error message thrown from assert.ifError PR-URL: #11193 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
landed in 5f20d62 |
Verify error message thrown from assert.ifError PR-URL: #11193 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Verify error message thrown from assert.ifError PR-URL: nodejs#11193 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Verify error message thrown from assert.ifError PR-URL: nodejs#11193 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Verify error message thrown from assert.ifError PR-URL: #11193 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Needs a backport PR to land in v4 |
Verify error message thrown from assert.ifError PR-URL: #11193 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Description of task to be completed
Add a regular expression for
assert.throws
to validate the error message thrown.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes