deepStrictEqual diff is unhelpful when prototype mismatches
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.4k
- Merge trung bình
- 4 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 272
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với bản tái hiện trong repo.js và chạy node --test repo.js để quan sát đầu ra assertion hiện tại. Theo dõi cách định dạng lỗi thất bại của node:assert deepStrictEqual và thêm một regression test; hoàn thành khi các prototype không khớp được biểu diễn trong diff, đồng thời nội dung mảng hiện có vẫn được báo cáo chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, node.js
- Lĩnh vực
- testing
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 65/100