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

assert: show diff when doing partial comparisons with a custom message #56211

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

puskin94
Copy link
Contributor

@puskin94 puskin94 commented Dec 10, 2024

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:

const assert = require('assert');

assert.partialDeepStrictEqual([1, 2, 3, 5], [4, 5]);
image

to this
image

with a custom error message:

image

Relevant changes:

  1. enabled the diff when assert.partialDeepStrictEqual fails
  2. enabled the diff when assert.partialDeepStrictEqual fails with a custom error message
  3. added different diff style in case assert.partialDeepStrictEqual fails:
  • properties available in actual are gray
  • properties in expected but not in actual are prefixed with the classic red -
  • properties present in both actual and expected are white

@nodejs-github-bot nodejs-github-bot added assert Issues and PRs related to the assert subsystem. needs-ci PRs that need a full CI run. labels Dec 10, 2024
@BridgeAR
Copy link
Member

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.

Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.55%. Comparing base (3851edf) to head (9f449e9).
Report is 93 commits behind head on main.

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     
Files with missing lines Coverage Δ
lib/assert.js 99.37% <100.00%> (+0.27%) ⬆️
lib/internal/assert/assertion_error.js 95.44% <100.00%> (+0.07%) ⬆️
lib/internal/assert/myers_diff.js 90.05% <100.00%> (+0.23%) ⬆️

... and 70 files with indirect coverage changes

@puskin94 puskin94 marked this pull request as draft December 10, 2024 19:21
@puskin94 puskin94 force-pushed the partial-deep-strict-equal-custom-message-diff branch 2 times, most recently from e2f640c to e4b2307 Compare December 11, 2024 13:17
@puskin94 puskin94 marked this pull request as ready for review December 11, 2024 13:18
@puskin94 puskin94 force-pushed the partial-deep-strict-equal-custom-message-diff branch from e4b2307 to 3db0829 Compare December 11, 2024 13:24
@puskin94
Copy link
Contributor Author

Is there anything left to be done here?

Copy link
Member

@BridgeAR BridgeAR left a 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.

Comment on lines 22 to 25
// 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 = () => {};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 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.

@BridgeAR BridgeAR added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 21, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 21, 2024
@nodejs-github-bot
Copy link
Collaborator

@puskin94 puskin94 force-pushed the partial-deep-strict-equal-custom-message-diff branch from 3db0829 to 9f449e9 Compare December 21, 2024 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert Issues and PRs related to the assert subsystem. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants