deepStrictEqual diff is unhelpful when prototype mismatches
未关闭
还没有人认领这个 Issue。
confirmed-bug
test_runner
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 repo.js 复现开始,并运行 node --test repo.js 以观察当前的断言输出。跟踪 node:assert deepStrictEqual 失败的格式化方式并添加回归测试;完成标准是:不匹配的原型会在 diff 中表示出来,同时现有数组内容仍能被正确报告。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- testing
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 65/100