sinonjs / sinon

Test spies, stubs and mocks for JavaScript.
https://sinonjs.org/
Other
9.61k stars 769 forks source link

[Node 18.17] Same URLs are different #2527

Closed regseb closed 1 year ago

regseb commented 1 year ago

Describe the bug With Node.js 18.17.0, spied URLs are different from supplied URLs.

Files

To Reproduce Steps to reproduce the behavior:

  1. npm install

  2. node --version

    v18.17.0
  3. node index.js

    ===== FIRST =====
    ===== CONSOLE =====
    URL {
    href: 'https://baz.org/',
    origin: 'https://baz.org',
    protocol: 'https:',
    username: '',
    password: '',
    host: 'baz.org',
    hostname: 'baz.org',
    port: '',
    pathname: '/',
    search: '',
    searchParams: URLSearchParams {},
    hash: ''
    }
    ===== SECOND =====
    node:internal/process/esm_loader:97
      internalBinding('errors').triggerUncaughtException(
                                ^
    
    AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
    + actual - expected ... Lines skipped
    
    + <ref *1> URL {
    - URL {
      [Symbol(context)]: URLContext {
        hash_start: 4294967295,
    ...
        search_start: 4294967295,
        username_end: 8
    +   },
    +   [Symbol(query)]: URLSearchParams {
    +     [Symbol(context)]: [Circular *1],
    +     [Symbol(query)]: []
      }
    }
      at file:///home/regseb/testcase/index.js:18:8
      at ModuleJob.run (node:internal/modules/esm/module_job:194:25) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: <ref *1> URL {
      [Symbol(context)]: URLContext {
        href: 'https://baz.org/',
        protocol_end: 6,
        username_end: 8,
        host_start: 8,
        host_end: 15,
        pathname_start: 15,
        search_start: 4294967295,
        hash_start: 4294967295,
        port: 4294967295,
        scheme_type: 2
      },
      [Symbol(query)]: URLSearchParams {
        [Symbol(context)]: [Circular *1]
      }
    },
    expected: URL {
      [Symbol(context)]: URLContext {
        href: 'https://baz.org/',
        protocol_end: 6,
        username_end: 8,
        host_start: 8,
        host_end: 15,
        pathname_start: 15,
        search_start: 4294967295,
        hash_start: 4294967295,
        port: 4294967295,
        scheme_type: 2
      }
    },
    operator: 'deepStrictEqual'
    }
    
    Node.js v18.17.0
  4. Use previous Node.js version: npm install node@18.16.1

  5. node_modules/.bin/node --version

    v18.16.1
  6. node_modules/.bin/node index.js

    ===== FIRST =====
    ===== CONSOLE =====
    URL {
    href: 'https://baz.org/',
    origin: 'https://baz.org',
    protocol: 'https:',
    username: '',
    password: '',
    host: 'baz.org',
    hostname: 'baz.org',
    port: '',
    pathname: '/',
    search: '',
    searchParams: URLSearchParams {},
    hash: ''
    }
    ===== SECOND =====

Expected behavior I'm expecting assert to find no difference between the two URLs.

Context (please complete the following information):

Additional context

regseb commented 1 year ago

I have reproduced the problem without Sinon. The problem comes from https://github.com/nodejs/node/issues/48886

import assert from "node:assert/strict";

const link = "https://baz.org/";
const url = new URL(link);

console.log("===== FIRST =====")
assert.deepEqual(url, new URL(link));

console.log("===== CONSOLE =====")
console.log(url);

console.log("===== SECOND =====")
assert.deepEqual(url, new URL(link));