-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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: combine user and generated message #22695
assert: combine user and generated message #22695
Conversation
Seems like the documentation changes could benefit from a bit of editing. @nodejs/documentation |
What about instances where |
doc/api/deprecations.md
Outdated
|
||
Type: Runtime | ||
|
||
Instead of accessing the generatedMessage property of `AssertionErrors`, please |
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.
generatedMessage
-> `generatedMessage`
doc/api/deprecations.md
Outdated
Type: Runtime | ||
|
||
Instead of accessing the generatedMessage property of `AssertionErrors`, please | ||
check for `AssertionError#userMessage` existence instead. It contains the actual |
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.
Is double "Instead of... instead." OK in this sentence?
doc/api/assert.md
Outdated
* `operator` {string} Set to the passed in operator value. | ||
* `userMessage` {any} Contains the actual passed through message by the user. | ||
It will not be set in case the user does not provide a error 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.
a error
-> an error
The |
CITGM https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1533/
|
doc/api/assert.md
Outdated
@@ -74,6 +93,7 @@ try { | |||
assert.strictEqual(err.code, 'ERR_ASSERTION'); | |||
assert.strictEqual(err.operator, 'strictEqual'); | |||
assert.strictEqual(err.generatedMessage, true); | |||
assert.strictEuqal('userMessage' in err, false); |
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.
typo: strictEqual
PTAL This PR makes all the "remove third argument in assert calls" obsolete. Refs: #22718 |
I opened a PR to fix the fastify issues. Refs: fastify/fastify#1142 |
Might be worth pinging some mocha people (@boneskull) and code/lab people (@cjihrig, @geek) to see if this is likely to have any impact on users of their libraries. (I'm guessing not, but let's be cautious anyway.) |
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 don’t understand why this PR would cause such a breakage. That seems a very common pattern, and not something that would be specific to Fastify. I suspect this might be breaking more.
@fhinkel all semver major PRs need review by the TSC. Thus, I added the request for review. @mcollina this is indeed not specific to fastify, even tough I am pretty happy to see that CITGM did not find anything else. It is almost only an issue for the following case:
I am going to split this into smaller steps to (a) make the I am also going to check the usage with Gzemnid even tough most entries will likely be false positives and filtering them is not that easy / requires a lot of manual work. Adding the |
This won't impact code or lab. Thank you for checking though! |
So far it was difficult to tell what the actual error was about if there was only the user error. To overcome this, the user message and the auto-generated message will now be visible at the same time.
8f9d266
to
89a9f00
Compare
Closing for now. I'll open a new PR when I get to it. |
user installs of Mocha are not impacted directly by changes to |
There are lots of PRs that remove the message property assert calls. That message is actually pretty valuable and should not be removed. However, the message alone is often not that useful. In context with the auto-generated message it can be very valuable.
From now on it would also be possible to provide the actual input value to functions and similar instead of having to reconstruct what value the assertion failed upon:
Before, all values were coerced to a string and passing through a message would have resulted in
[object Object]
as output. Now the value is inspected and fully visible.There is only one values that is not accepted as input: instances of Error (those are special handled in the way that that concrete error would be thrown in case of an failed assertion. Therefore even if someone does not anticipates this case, it's always a good assertion output). I have a follow-up PR to add support for undefined as well.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes