-
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
assert: add default operator to assert.fail()
#22694
Conversation
This makes sure `assert.fail()` contains an operator instead of being undefined. On top of that it also fixes the `err.generatedMessage` property. Before, it was not always set correct.
|
Is there a reason to expose |
@Trott the |
PTAL @nodejs/util |
@nodejs/testing |
I see that I bring this up because I'd rather |
@Trott I am not sure anymore since when that is the case. I think since v8 or v9. Using e.g., |
@BridgeAR Thanks. Just to be clear: Not objecting. Just surprised. :-D |
PTAL this could use some reviews. |
lib/assert.js
Outdated
actual, | ||
expected, | ||
message, | ||
operator, | ||
operator: operator || '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.
Does Node have a consistent way of checking for optional params or default params?
In this case the falsey check means that users can't specify it as null
or ""
.
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.
No, it's often mixed and fasly values are often set to a default while in other cases only undefined is set to a default.
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 method has a mix of deprecated/legacy and new/different functionality. Would moving the operator juggle into a argLength < 2
branch with the other argLen
checks be doable? That way it touches less of the overlapping code paths.
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.
That was done on purpose since I believe it is best to just properly do this for all cases.
Shall I maybe change the check to: operator === undefined ? 'fail' : operator
?
PTAL |
@@ -106,13 +107,23 @@ function fail(actual, expected, message, operator, stackStartFn) { | |||
operator = '!='; | |||
} | |||
|
|||
innerFail({ | |||
if (message instanceof Error) throw message; | |||
|
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.
☝️ Should use the util for isError
(internal reference) for this since it avoids the error of errors from other realms.
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.
Only changing this here is likely not the best way. It would have to be changed throughout assert in total or not at all. It is also sad that the util function is not a safe check as the Symbol.toStringTag
could be set and isError
would happily return true in some weird cases.
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.
Only changing this here is likely not the best way.
Ah, didn't know this was consistent with the rest of assert
. A follow up would be best.
It is also sad that the util function is not a safe check as the Symbol.toStringTag could be set and isError would happily return true in some weird cases.
Oh I thought the new isNativeError
was more robust.
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.
Oh, I missed the isNativeError
somehow. We have multiple places in core where we should likely switch to this check.
PTAL |
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
This makes sure `assert.fail()` contains an operator instead of being undefined. On top of that it also fixes the `err.generatedMessage` property. Before, it was not always set correct. PR-URL: nodejs#22694 Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Landed in eee5adf 🎉 |
This makes sure `assert.fail()` contains an operator instead of being undefined. On top of that it also fixes the `err.generatedMessage` property. Before, it was not always set correct. PR-URL: #22694 Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
This makes sure `assert.fail()` contains an operator instead of being undefined. On top of that it also fixes the `err.generatedMessage` property. Before, it was not always set correct. PR-URL: #22694 Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
This makes sure `assert.fail()` contains an operator instead of being undefined. On top of that it also fixes the `err.generatedMessage` property. Before, it was not always set correct. PR-URL: #22694 Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
This makes sure
assert.fail()
contains an operator instead of beingundefined.
On top of that it also fixes the
err.generatedMessage
property.Before, it was not always set correct.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes