Skip to content

Conversation

@puskin
Copy link
Contributor

@puskin puskin commented Sep 4, 2024

Fixes: #48465

This PR allows some assertion methods to show the diff when 2 data are different and a custom error message is passed

From this:

image

To this:

image

@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 Sep 4, 2024
@codecov
Copy link

codecov bot commented Sep 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.61%. Comparing base (5949e16) to head (0d996bc).
Report is 326 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #54759   +/-   ##
=======================================
  Coverage   87.60%   87.61%           
=======================================
  Files         650      650           
  Lines      182829   182836    +7     
  Branches    35379    35381    +2     
=======================================
+ Hits       160173   160185   +12     
+ Misses      15928    15926    -2     
+ Partials     6728     6725    -3     
Files with missing lines Coverage Δ
lib/internal/assert/assertion_error.js 100.00% <100.00%> (ø)

... and 31 files with indirect coverage changes

@puskin puskin force-pushed the show-diff-in-comparison-with-custom-message branch from 89cb67f to 0d996bc Compare September 4, 2024 15:04
@pmarchini
Copy link
Member

pmarchini commented Sep 6, 2024

@redyetidev, do you think we should tag someone or ask for a review from the assert/test group?

Edit: Maybe @MoLow would be interested in reviewing this (I saw this #48465 (comment))

@jasnell jasnell requested review from BridgeAR and aduh95 September 7, 2024 22:55
Copy link
Member

@MoLow MoLow left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@avivkeller
Copy link
Member

CC @nodejs/assert

@puskin
Copy link
Contributor Author

puskin commented Sep 18, 2024

Any news on this? is this ready to land?

@richardlau richardlau added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 18, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 18, 2024
@nodejs-github-bot

This comment was marked as outdated.

@puskin
Copy link
Contributor Author

puskin commented Sep 24, 2024

The PR is ready but the CI is flaky

@nodejs-github-bot
Copy link
Collaborator

@jasnell
Copy link
Member

jasnell commented Sep 28, 2024

Landed in e1d8b4f

@jasnell jasnell closed this Sep 28, 2024
@aduh95 aduh95 mentioned this pull request Oct 9, 2024
@thetutlage
Copy link

The related commit introduces an issue when the actual value is computed after creating the error instance. In one of my libraries, I create AssertionError instances ahead of time and throw them later. For example:

const error = new AssertionError({
  message: `Expected prompt validation message to equal ${inspect(message)}`,
  expected: message,
  operator: 'strictEqual',
})

Throwing the above error object after some async operation.

const result = await someAsyncOperation()
error.actual = result

if (error.expected !== error.actual) {
  throw error
}

In the above case, the error.message will have the following output.

AssertionError [ERR_ASSERTION]: Expected prompt validation message to equal 'client is required'
+ actual - expected

+ undefined
- 'client is required'

@thetutlage
Copy link

On the side note: There should be a way to disable generating diffs for cases where I want to use a specific library to generate custom diffs

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.

Show diff if test fails with an assertion that has a message

9 participants