-
Notifications
You must be signed in to change notification settings - Fork 30k
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: show diff when doing partial comparisons with a custom message #56211
base: main
Are you sure you want to change the base?
assert: show diff when doing partial comparisons with a custom message #56211
Conversation
How to show the diff for the partial implementation has been one of my main concerns for a while and my current idea is to grey out or hide all lines that are not in the expected object. That way it would be more straight forward for the user. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #56211 +/- ##
==========================================
+ Coverage 88.49% 88.55% +0.05%
==========================================
Files 656 657 +1
Lines 189261 190405 +1144
Branches 36348 36561 +213
==========================================
+ Hits 167493 168609 +1116
- Misses 14977 14990 +13
- Partials 6791 6806 +15
|
e2f640c
to
e4b2307
Compare
e4b2307
to
3db0829
Compare
Is there anything left to be done here? |
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!
Let's see how people react to the greyed out part to gather feedback while it's experimental. I feel it is nicer than the green plus.
// TODO(puskin94): remove the emitWarning override once the partialDeepStrictEqual method is not experimental anymore | ||
// Suppress warnings, necessary otherwise the tools/pseudo-tty.py runner will fail | ||
const originalEmitWarning = process.emitWarning; | ||
process.emitWarning = () => {}; |
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.
// TODO(puskin94): remove the emitWarning override once the partialDeepStrictEqual method is not experimental anymore | |
// Suppress warnings, necessary otherwise the tools/pseudo-tty.py runner will fail | |
const originalEmitWarning = process.emitWarning; | |
process.emitWarning = () => {}; | |
// Suppress warnings, necessary otherwise the tools/pseudo-tty.py runner will fail | |
const originalEmitWarning = process.emitWarning; | |
process.emitWarning = common.mustCall(() => {}); |
That way the test would fail when it is not called anymore when removing the warning.
The same in the other files.
3db0829
to
9f449e9
Compare
following the same reasoning as this PR:
right now the method
assert.partialDeepStrictEqual
does not show the diff when the assertion fails.With this PR we go from this:
to this
with a custom error message:
Relevant changes:
assert.partialDeepStrictEqual
failsassert.partialDeepStrictEqual
fails with a custom error messageassert.partialDeepStrictEqual
fails:actual
are grayexpected
but not inactual
are prefixed with the classic red-
actual
andexpected
are white