test_runner: serialize 'expected' and 'actual' in isolation

Previously, a value seen in 'actual' would be serialized as a circular
reference if it had also appeared in 'expected'.

PR-URL: https://github.com/nodejs/node/pull/51851
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
Malthe Borch authored and marco-ippolito committed 2024-02-29 12:54:52 +01:00
1 parent cb621863c6
commit e4d4bc6f9a
8 files changed
+118 -39

No files matched your search

+5 -2
View File
@@ -224,8 +224,11 @@ function jsToYaml(indent, name, value, seen) {
}
if (errIsAssertion) {
result += jsToYaml(indent, 'expected', errExpected, seen);
result += jsToYaml(indent, 'actual', errActual, seen);
// Note that we're deliberately creating shallow copies of the `seen`
// set here in order to isolate the discovery of circular references
// within the expected and actual properties respectively.
result += jsToYaml(indent, 'expected', errExpected, new SafeSet(seen));
result += jsToYaml(indent, 'actual', errActual, new SafeSet(seen));
if (errOperator) {
result += jsToYaml(indent, 'operator', errOperator, seen);
}
+24 -8
View File
@@ -422,20 +422,28 @@ Error [ERR_TEST_FAILURE]: bar
}
</failure>
</testcase>
<testcase name="assertion errors display actual and expected properly" time="*" classname="test" failure="Expected values to be loosely deep-equal:{ bar: 1, foo: 1}should loosely deep-equal&lt;ref *1> { bar: 2, c: [Circular *1]}">
<failure type="testCodeFailure" message="Expected values to be loosely deep-equal:{ bar: 1, foo: 1}should loosely deep-equal&lt;ref *1> { bar: 2, c: [Circular *1]}">
<testcase name="assertion errors display actual and expected properly" time="*" classname="test" failure="Expected values to be loosely deep-equal:{ bar: 1, boo: [ 1 ], foo: 1}should loosely deep-equal{ boo: [ 1 ], circular: &lt;ref *1> { bar: 2, c: [Circular *1] }}">
<failure type="testCodeFailure" message="Expected values to be loosely deep-equal:{ bar: 1, boo: [ 1 ], foo: 1}should loosely deep-equal{ boo: [ 1 ], circular: &lt;ref *1> { bar: 2, c: [Circular *1] }}">
[Error [ERR_TEST_FAILURE]: Expected values to be loosely deep-equal:
{
bar: 1,
boo: [
1
],
foo: 1
}
should loosely deep-equal
&lt;ref *1> {
bar: 2,
c: [Circular *1]
{
boo: [
1
],
circular: &lt;ref *1> {
bar: 2,
c: [Circular *1]
}
}] {
code: 'ERR_TEST_FAILURE',
failureType: 'testCodeFailure',
@@ -443,14 +451,22 @@ should loosely deep-equal
{
bar: 1,
boo: [
1
],
foo: 1
}
should loosely deep-equal
&lt;ref *1> {
bar: 2,
c: [Circular *1]
{
boo: [
1
],
circular: &lt;ref *1> {
bar: 2,
c: [Circular *1]
}
}
* {
generatedMessage: true,
+3 -2
View File
@@ -694,6 +694,7 @@ DA:388,1
DA:389,1
DA:390,1
DA:391,1
LH:389
LF:391
DA:392,1
LH:390
LF:392
end_of_record
+2 -1
View File
@@ -382,8 +382,9 @@ test('assertion errors display actual and expected properly', async () => {
circular.c = circular;
const tmpLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 1;
const boo = [1];
try {
assert.deepEqual({ foo: 1, bar: 1 }, circular); // eslint-disable-line no-restricted-properties
assert.deepEqual({ foo: 1, bar: 1, boo }, { boo, circular }); // eslint-disable-line no-restricted-properties
} catch (err) {
Error.stackTraceLimit = tmpLimit;
throw err;
+18 -5
View File
@@ -643,23 +643,36 @@ not ok 61 - assertion errors display actual and expected properly
{
bar: 1,
boo: [
1
],
foo: 1
}
should loosely deep-equal
<ref *1> {
bar: 2,
c: [Circular *1]
{
boo: [
1
],
circular: <ref *1> {
bar: 2,
c: [Circular *1]
}
}
code: 'ERR_ASSERTION'
name: 'AssertionError'
expected:
bar: 2
c: <Circular>
boo:
0: 1
circular:
bar: 2
c: <Circular>
actual:
foo: 1
bar: 1
boo:
0: 1
operator: 'deepEqual'
stack: |-
*
+18 -5
View File
@@ -643,23 +643,36 @@ not ok 61 - assertion errors display actual and expected properly
{
bar: 1,
boo: [
1
],
foo: 1
}
should loosely deep-equal
<ref *1> {
bar: 2,
c: [Circular *1]
{
boo: [
1
],
circular: <ref *1> {
bar: 2,
c: [Circular *1]
}
}
code: 'ERR_ASSERTION'
name: 'AssertionError'
expected:
bar: 2
c: <Circular>
boo:
0: 1
circular:
bar: 2
c: <Circular>
actual:
foo: 1
bar: 1
boo:
0: 1
operator: 'deepEqual'
stack: |-
*
+22 -6
View File
@@ -263,14 +263,22 @@
{
bar: 1,
boo: [
1
],
foo: 1
}
should loosely deep-equal
<ref *1> {
bar: 2,
c: [Circular *1]
{
boo: [
1
],
circular: <ref *1> {
bar: 2,
c: [Circular *1]
}
}
* {
generatedMessage: true,
@@ -528,14 +536,22 @@
{
bar: 1,
boo: [
1
],
foo: 1
}
should loosely deep-equal
<ref *1> {
bar: 2,
c: [Circular *1]
{
boo: [
1
],
circular: <ref *1> {
bar: 2,
c: [Circular *1]
}
}
* {
generatedMessage: true,
+26 -10
View File
@@ -263,20 +263,28 @@
{
bar: 1,
boo: [
1
],
foo: 1
}
should loosely deep-equal
<ref *1> {
bar: 2,
c: [Circular *1]
{
boo: [
1
],
circular: <ref *1> {
bar: 2,
c: [Circular *1]
}
}
* {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: { foo: 1, bar: 1 },
expected: <ref *1> { bar: 2, c: [Circular *1] },
actual: { foo: 1, bar: 1, boo: [ 1 ] },
expected: { boo: [ 1 ], circular: <ref *1> { bar: 2, c: [Circular *1] } },
operator: 'deepEqual'
}
@@ -528,20 +536,28 @@
{
bar: 1,
boo: [
1
],
foo: 1
}
should loosely deep-equal
<ref *1> {
bar: 2,
c: [Circular *1]
{
boo: [
1
],
circular: <ref *1> {
bar: 2,
c: [Circular *1]
}
}
* {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: { foo: 1, bar: 1 },
expected: <ref *1> { bar: 2, c: [Circular *1] },
actual: { foo: 1, bar: 1, boo: [ 1 ] },
expected: { boo: [ 1 ], circular: <ref *1> { bar: 2, c: [Circular *1] } },
operator: 'deepEqual'
}