nodejs / nodejs/node

deepStrictEqual diff is unhelpful when prototype mismatches

Aperta
#50,397 8 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

confirmed-bug test_runner
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

Version

v20.8.0

Platform

Darwin Me.local 23.0.0 Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:34 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T8103 arm64

Subsystem

No response

What steps will reproduce the bug?

Given repo.js

import { test } from "node:test";
import { deepStrictEqual, notDeepStrictEqual } from "node:assert";

class ExtendedArray extends Array {
  constructor() {
    super();
  }
}

test("deepStrictEqual should print prototype diff", () => {
  const actual = new ExtendedArray();
  actual[0] = "hello";
  const expected = ["hello"];

  notDeepStrictEqual(
    Object.getPrototypeOf(actual),
    Object.getPrototypeOf(expected)
  );

  deepStrictEqual(actual, expected);
});

Run node --test repo.js.

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

deepStrictEquals requires actual and expected to have the same prototype, but fails to show error message describing if they are not the same.

A more helpful diff would be:

$ node --test repo.js
✖ deepStrictEqual should print prototype diff (1.581625ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
  + actual - expected
  
  + ExtendedArray(1) [
  - [
      'hello'
    ]
      at TestContext.<anonymous> (file://.../repo.js:20:3)
      at Test.runInAsyncScope (node:async_hooks:206:9)
      at Test.run (node:internal/test_runner/test:631:25)
      at Test.start (node:internal/test_runner/test:542:17)
      at startSubtest (node:internal/test_runner/harness:208:17) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual prototype: Array {}
    expected prototype: Object(0) [],
    operator: 'deepStrictEqual'
  }
What do you see instead?

Only the contents of the arrays are diffed.

$ node --test repo.js
✖ deepStrictEqual should print prototype diff (1.581625ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
  + actual - expected
  
  + ExtendedArray(1) [
  - [
      'hello'
    ]
      at TestContext.<anonymous> (file://.../repo.js:20:3)
      at Test.runInAsyncScope (node:async_hooks:206:9)
      at Test.run (node:internal/test_runner/test:631:25)
      at Test.start (node:internal/test_runner/test:542:17)
      at startSubtest (node:internal/test_runner/harness:208:17) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: [ 'hello' ],
    expected: [ 'hello' ],
    operator: 'deepStrictEqual'
  }
Additional information

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione in repo.js ed esegui node --test repo.js per osservare l’output corrente dell’asserzione. Traccia la formattazione dell’errore di node:assert deepStrictEqual e aggiungi un test di regressione; il lavoro è completo quando i prototipi non corrispondenti sono rappresentati nel diff, mentre il contenuto esistente degli array continua a essere riportato correttamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, node.js
Ambito
testing
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
65/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.