From 5c42ba69674029c4bd8a94288fe1b0fa3a0c8477 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Fri, 23 Feb 2024 14:49:48 +0100 Subject: [PATCH] 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'. --- lib/internal/test_runner/reporter/tap.js | 4 +-- .../output/junit_reporter.snapshot | 32 ++++++++++++----- .../test-runner/output/lcov_reporter.snapshot | 5 +-- test/fixtures/test-runner/output/output.js | 3 +- .../test-runner/output/output.snapshot | 23 +++++++++--- .../test-runner/output/output_cli.snapshot | 23 +++++++++--- .../test-runner/output/spec_reporter.snapshot | 28 +++++++++++---- .../output/spec_reporter_cli.snapshot | 36 +++++++++++++------ 8 files changed, 115 insertions(+), 39 deletions(-) diff --git a/lib/internal/test_runner/reporter/tap.js b/lib/internal/test_runner/reporter/tap.js index e8cf727daede64c..b345d18fc667a3f 100644 --- a/lib/internal/test_runner/reporter/tap.js +++ b/lib/internal/test_runner/reporter/tap.js @@ -224,8 +224,8 @@ function jsToYaml(indent, name, value, seen) { } if (errIsAssertion) { - result += jsToYaml(indent, 'expected', errExpected, seen); - result += jsToYaml(indent, 'actual', errActual, seen); + result += jsToYaml(indent, 'expected', errExpected, new SafeSet(seen)); + result += jsToYaml(indent, 'actual', errActual, new SafeSet(seen)); if (errOperator) { result += jsToYaml(indent, 'operator', errOperator, seen); } diff --git a/test/fixtures/test-runner/output/junit_reporter.snapshot b/test/fixtures/test-runner/output/junit_reporter.snapshot index 562c7696cbd0ec5..94d16f7205a71a5 100644 --- a/test/fixtures/test-runner/output/junit_reporter.snapshot +++ b/test/fixtures/test-runner/output/junit_reporter.snapshot @@ -422,20 +422,28 @@ Error [ERR_TEST_FAILURE]: bar } - - + + [Error [ERR_TEST_FAILURE]: Expected values to be loosely deep-equal: { 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_TEST_FAILURE', failureType: 'testCodeFailure', @@ -443,14 +451,22 @@ should loosely deep-equal { 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, diff --git a/test/fixtures/test-runner/output/lcov_reporter.snapshot b/test/fixtures/test-runner/output/lcov_reporter.snapshot index c14f4c7ce2baee6..7146a3692759809 100644 --- a/test/fixtures/test-runner/output/lcov_reporter.snapshot +++ b/test/fixtures/test-runner/output/lcov_reporter.snapshot @@ -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 diff --git a/test/fixtures/test-runner/output/output.js b/test/fixtures/test-runner/output/output.js index f37d34950309507..95512e745fccaa7 100644 --- a/test/fixtures/test-runner/output/output.js +++ b/test/fixtures/test-runner/output/output.js @@ -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; diff --git a/test/fixtures/test-runner/output/output.snapshot b/test/fixtures/test-runner/output/output.snapshot index 18f030dab361abd..dfa8b3f2df2b7ac 100644 --- a/test/fixtures/test-runner/output/output.snapshot +++ b/test/fixtures/test-runner/output/output.snapshot @@ -643,23 +643,36 @@ not ok 61 - assertion errors display actual and expected properly { bar: 1, + boo: [ + 1 + ], foo: 1 } should loosely deep-equal - { - bar: 2, - c: [Circular *1] + { + boo: [ + 1 + ], + circular: { + bar: 2, + c: [Circular *1] + } } code: 'ERR_ASSERTION' name: 'AssertionError' expected: - bar: 2 - c: + boo: + 0: 1 + circular: + bar: 2 + c: actual: foo: 1 bar: 1 + boo: + 0: 1 operator: 'deepEqual' stack: |- * diff --git a/test/fixtures/test-runner/output/output_cli.snapshot b/test/fixtures/test-runner/output/output_cli.snapshot index 3cef8f29b253b9c..3bfa8cee4bf2a1b 100644 --- a/test/fixtures/test-runner/output/output_cli.snapshot +++ b/test/fixtures/test-runner/output/output_cli.snapshot @@ -643,23 +643,36 @@ not ok 61 - assertion errors display actual and expected properly { bar: 1, + boo: [ + 1 + ], foo: 1 } should loosely deep-equal - { - bar: 2, - c: [Circular *1] + { + boo: [ + 1 + ], + circular: { + bar: 2, + c: [Circular *1] + } } code: 'ERR_ASSERTION' name: 'AssertionError' expected: - bar: 2 - c: + boo: + 0: 1 + circular: + bar: 2 + c: actual: foo: 1 bar: 1 + boo: + 0: 1 operator: 'deepEqual' stack: |- * diff --git a/test/fixtures/test-runner/output/spec_reporter.snapshot b/test/fixtures/test-runner/output/spec_reporter.snapshot index 8f14dc7fc9bade7..bfa5b61ac001377 100644 --- a/test/fixtures/test-runner/output/spec_reporter.snapshot +++ b/test/fixtures/test-runner/output/spec_reporter.snapshot @@ -263,14 +263,22 @@ { bar: 1, + boo: [ + 1 + ], foo: 1 } should loosely deep-equal - { - bar: 2, - c: [Circular *1] + { + boo: [ + 1 + ], + circular: { + bar: 2, + c: [Circular *1] + } } * { generatedMessage: true, @@ -528,14 +536,22 @@ { bar: 1, + boo: [ + 1 + ], foo: 1 } should loosely deep-equal - { - bar: 2, - c: [Circular *1] + { + boo: [ + 1 + ], + circular: { + bar: 2, + c: [Circular *1] + } } * { generatedMessage: true, diff --git a/test/fixtures/test-runner/output/spec_reporter_cli.snapshot b/test/fixtures/test-runner/output/spec_reporter_cli.snapshot index a9b70560d905b22..933385e1e021619 100644 --- a/test/fixtures/test-runner/output/spec_reporter_cli.snapshot +++ b/test/fixtures/test-runner/output/spec_reporter_cli.snapshot @@ -263,20 +263,28 @@ { bar: 1, + boo: [ + 1 + ], foo: 1 } should loosely deep-equal - { - bar: 2, - c: [Circular *1] + { + boo: [ + 1 + ], + circular: { + bar: 2, + c: [Circular *1] + } } * { generatedMessage: true, code: 'ERR_ASSERTION', - actual: { foo: 1, bar: 1 }, - expected: { bar: 2, c: [Circular *1] }, + actual: { foo: 1, bar: 1, boo: [ 1 ] }, + expected: { boo: [ 1 ], circular: { bar: 2, c: [Circular *1] } }, operator: 'deepEqual' } @@ -528,20 +536,28 @@ { bar: 1, + boo: [ + 1 + ], foo: 1 } should loosely deep-equal - { - bar: 2, - c: [Circular *1] + { + boo: [ + 1 + ], + circular: { + bar: 2, + c: [Circular *1] + } } * { generatedMessage: true, code: 'ERR_ASSERTION', - actual: { foo: 1, bar: 1 }, - expected: { bar: 2, c: [Circular *1] }, + actual: { foo: 1, bar: 1, boo: [ 1 ] }, + expected: { boo: [ 1 ], circular: { bar: 2, c: [Circular *1] } }, operator: 'deepEqual' }