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.53%. Comparing base (3851edf) to head (3db0829).
Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #56211      +/-   ##
==========================================
+ Coverage   88.49%   88.53%   +0.03%     
==========================================
  Files         656      657       +1     
  Lines      189261   189890     +629     
  Branches    36348    36461     +113     
==========================================
+ Hits       167493   168123     +630     
- Misses      14977    14979       +2     
+ Partials     6791     6788       -3     
Files with missing lines Coverage Δ
lib/assert.js 99.10% <100.00%> (-0.01%) ⬇️
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 38 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
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