Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize 'expected' and 'actual' in isolation with regards to already seen values #51851

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/internal/test_runner/reporter/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
if (errOperator) {
result += jsToYaml(indent, 'operator', errOperator, seen);
}
Expand Down
32 changes: 24 additions & 8 deletions test/fixtures/test-runner/output/junit_reporter.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -422,35 +422,51 @@ 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',
cause: AssertionError [ERR_ASSERTION]: 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]
}
}
* {
generatedMessage: true,
Expand Down
5 changes: 3 additions & 2 deletions test/fixtures/test-runner/output/lcov_reporter.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion test/fixtures/test-runner/output/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 18 additions & 5 deletions test/fixtures/test-runner/output/output.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
*
Expand Down
23 changes: 18 additions & 5 deletions test/fixtures/test-runner/output/output_cli.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
*
Expand Down
28 changes: 22 additions & 6 deletions test/fixtures/test-runner/output/spec_reporter.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
36 changes: 26 additions & 10 deletions test/fixtures/test-runner/output/spec_reporter_cli.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down Expand Up @@ -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'
}

Expand Down