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,util: handle invalid dates as equal in deep comparison #57627

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

BridgeAR
Copy link
Member

Invalid dates are now handled as equal in all deep comparisons.

This is more of a usability improvement than a breaking change, since all invalid dates have always thrown errors when being compared until now.

@BridgeAR BridgeAR added semver-major PRs that contain breaking changes and should be released in the next major version. needs-citgm PRs that need a CITGM CI run. labels Mar 25, 2025
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Mar 25, 2025
Invalid dates are now handled as equal in all deep comparisons.
@BridgeAR BridgeAR force-pushed the handle-invalid-dates branch from dcf51d3 to f83b6c4 Compare March 25, 2025 22:01
@@ -22,6 +22,7 @@ const primValues = {
'empty_object': {},
'regexp': /abc/i,
'date': new Date(),
'invalidDate': new Date('foo'),
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure if we want to add the entries to our benchmarks yet, since this would just always fail when comparing it with older versions.

Copy link
Member

Choose a reason for hiding this comment

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

The other option is to wait a release to include, but I don't thing is worthy, so I would keep it

@BridgeAR BridgeAR requested a review from jasnell March 25, 2025 22:17
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

what would have thrown before when comparing two invalid dates? it seems like comparing two invalid dates would have compared as false before, and now will compare as true, which does seem breaking.

@BridgeAR
Copy link
Member Author

@ljharb

> assert.deepStrictEqual(new Date('foo'), new Date('foo'))
Uncaught:
AssertionError [ERR_ASSERTION]: Values have same structure but are not reference-equal:

Invalid Date

    at REPL11:1:8  {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: Invalid Date,
  expected: Invalid Date,
  operator: 'deepStrictEqual'
}

@ljharb
Copy link
Member

ljharb commented Mar 26, 2025

ohhh right, because it's an assert api, not a predicate. fair enough :-)

@@ -22,6 +22,7 @@ const primValues = {
'empty_object': {},
'regexp': /abc/i,
'date': new Date(),
'invalidDate': new Date('foo'),
Copy link
Member

Choose a reason for hiding this comment

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

The other option is to wait a release to include, but I don't thing is worthy, so I would keep it

@H4ad H4ad added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 26, 2025
Copy link

codecov bot commented Mar 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.22%. Comparing base (a4f556f) to head (ca78dda).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57627      +/-   ##
==========================================
- Coverage   90.24%   90.22%   -0.02%     
==========================================
  Files         630      630              
  Lines      185129   185060      -69     
  Branches    36238    36223      -15     
==========================================
- Hits       167064   166967      -97     
- Misses      11045    11046       +1     
- Partials     7020     7047      +27     
Files with missing lines Coverage Δ
lib/internal/util/comparisons.js 99.63% <100.00%> (+<0.01%) ⬆️

... and 20 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. needs-ci PRs that need a full CI run. needs-citgm PRs that need a CITGM CI run. semver-major PRs that contain breaking changes and should be released in the next major version. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants