nodejs / nodejs/node

deepStrictEqual diff is unhelpful when prototype mismatches

オープン
#50,397 コメント 8 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

confirmed-bug test_runner
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

repo.js の再現コードから始め、node --test repo.js を実行して現在のアサーション出力を確認します。node:assert deepStrictEqual の失敗時のフォーマットを追跡して回帰テストを追加します。完了条件は、一致しないプロトタイプが diff に表現され、既存の配列の内容が引き続き正しく報告されることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
testing
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
65/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。