chaijs / chaijs/deep-eql

Cannot reliably compare Ada-based URLs (Node.js v18.17.0 & newer)

Open
#97 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
112
Forks
45
Avg merge
2d 21h
Merged PRs (30d)
1

Description

Until recently, my team was using Node.js v18.13.0. Our CI system picked up Node.js v18.17.0 and started failing. Specifically, we started failing when using Chai to perform expect(…).to.deep.equal on URLs.

After reading the changelog for v18.17.0, I see that Ada-based URLs were backported to Node.js 18 (see here).

Narrowing down some more, it seems there is a behavior change in Node.js 18.17.0 where Symbol(query) is lazily set on URLs whenever searchParams is accessed (see here). So, if you've never accessed that property of a URL, Symbol(query) does not exist; however, once you have accessed that property, Symbol(query) does exist. This leads to the following breakage (I'm demonstrating with Mocha):

const { expect } = require('chai')

describe('URL', () => {
  it('succeeds', () => {
    const url = new URL('foo://bar')
    expect(url).to.deep.equal(new URL('foo://bar'))
  })

  // The following succeeded in Node.js < v18.17.0.
  it('fails', () => {
    const url = new URL('foo://bar')
    void url.searchParams
    expect(url).to.deep.equal(new URL('foo://bar'))
  })
})

Maybe this is working as expected, but it was an unfortunate bug we hit. We have worked around it by changing our tests to no longer expect(…).to.deep.equal on URLs.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two URL comparisons in the issue with Node.js 18.17.0 or newer, using the deep-eql behavior exercised through Chai. Compare results before and after accessing searchParams; the desired outcome and the relevant source or test files are not specified in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.