Skip to content

assert,util: handle invalid dates as equal in deep comparison #57627

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

Open
wants to merge 1 commit 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
@BridgeAR BridgeAR force-pushed the handle-invalid-dates branch from dcf51d3 to f83b6c4 Compare March 25, 2025 22:01
@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 :-)

@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.21%. Comparing base (8d603d5) to head (0702320).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57627      +/-   ##
==========================================
- Coverage   90.22%   90.21%   -0.02%     
==========================================
  Files         635      635              
  Lines      187171   187176       +5     
  Branches    36749    36748       -1     
==========================================
- Hits       168877   168852      -25     
- Misses      11069    11115      +46     
+ Partials     7225     7209      -16     
Files with missing lines Coverage Δ
lib/internal/util/comparisons.js 100.00% <100.00%> (ø)

... and 33 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.

@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 2, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 2, 2025
@nodejs-github-bot
Copy link
Collaborator

@aduh95
Copy link
Contributor

aduh95 commented Apr 5, 2025

This needs a rebase

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Lgtm

Invalid dates are now handled as equal in all deep comparisons.
@BridgeAR BridgeAR force-pushed the handle-invalid-dates branch from ca78dda to 0702320 Compare May 21, 2025 15:05
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

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.

9 participants