diff --git a/lib/internal/test_runner/reporter/tap.js b/lib/internal/test_runner/reporter/tap.js index e8cf727daede64..cd0bbe8ca53003 100644 --- a/lib/internal/test_runner/reporter/tap.js +++ b/lib/internal/test_runner/reporter/tap.js @@ -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); } diff --git a/test/fixtures/test-runner/output/junit_reporter.snapshot b/test/fixtures/test-runner/output/junit_reporter.snapshot index 562c7696cbd0ec..94d16f7205a71a 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 c14f4c7ce2baee..7146a369275980 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 f37d3495030950..95512e745fccaa 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 18f030dab361ab..dfa8b3f2df2b7a 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 3cef8f29b253b9..3bfa8cee4bf2a1 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 8f14dc7fc9bade..bfa5b61ac00137 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 a9b70560d905b2..933385e1e02161 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' }