Skip to content

Commit 91c8624

Browse files
maltherichardlau
authored andcommitted
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: #51851 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
1 parent e192ba1 commit 91c8624

File tree

8 files changed

+118
-39
lines changed

8 files changed

+118
-39
lines changed

‎lib/internal/test_runner/reporter/tap.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,11 @@ function jsToYaml(indent, name, value, seen){
224224
}
225225

226226
if(errIsAssertion){
227-
result+=jsToYaml(indent,'expected',errExpected,seen);
228-
result+=jsToYaml(indent,'actual',errActual,seen);
227+
// Note that we're deliberately creating shallow copies of the `seen`
228+
// set here in order to isolate the discovery of circular references
229+
// within the expected and actual properties respectively.
230+
result+=jsToYaml(indent,'expected',errExpected,newSafeSet(seen));
231+
result+=jsToYaml(indent,'actual',errActual,newSafeSet(seen));
229232
if(errOperator){
230233
result+=jsToYaml(indent,'operator',errOperator,seen);
231234
}

‎test/fixtures/test-runner/output/junit_reporter.snapshot‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,35 +422,51 @@ Error [ERR_TEST_FAILURE]: bar
422422
}
423423
</failure>
424424
</testcase>
425-
<testcasename="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]}">
426-
<failuretype="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]}">
425+
<testcasename="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] }}">
426+
<failuretype="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] }}">
427427
[Error [ERR_TEST_FAILURE]: Expected values to be loosely deep-equal:
428428

429429
{
430430
bar: 1,
431+
boo: [
432+
1
433+
],
431434
foo: 1
432435
}
433436

434437
should loosely deep-equal
435438

436-
&lt;ref *1>{
437-
bar: 2,
438-
c: [Circular *1]
439+
{
440+
boo: [
441+
1
442+
],
443+
circular: &lt;ref *1>{
444+
bar: 2,
445+
c: [Circular *1]
446+
}
439447
}]{
440448
code: 'ERR_TEST_FAILURE',
441449
failureType: 'testCodeFailure',
442450
cause: AssertionError [ERR_ASSERTION]: Expected values to be loosely deep-equal:
443451

444452
{
445453
bar: 1,
454+
boo: [
455+
1
456+
],
446457
foo: 1
447458
}
448459

449460
should loosely deep-equal
450461

451-
&lt;ref *1>{
452-
bar: 2,
453-
c: [Circular *1]
462+
{
463+
boo: [
464+
1
465+
],
466+
circular: &lt;ref *1>{
467+
bar: 2,
468+
c: [Circular *1]
469+
}
454470
}
455471
*{
456472
generatedMessage: true,

‎test/fixtures/test-runner/output/lcov_reporter.snapshot‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ DA:388,1
694694
DA:389,1
695695
DA:390,1
696696
DA:391,1
697-
LH:389
698-
LF:391
697+
DA:392,1
698+
LH:390
699+
LF:392
699700
end_of_record

‎test/fixtures/test-runner/output/output.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,9 @@ test('assertion errors display actual and expected properly', async () =>{
382382
circular.c=circular;
383383
consttmpLimit=Error.stackTraceLimit;
384384
Error.stackTraceLimit=1;
385+
constboo=[1];
385386
try{
386-
assert.deepEqual({foo: 1,bar: 1},circular);// eslint-disable-line no-restricted-properties
387+
assert.deepEqual({foo: 1,bar: 1, boo },{ boo,circular});// eslint-disable-line no-restricted-properties
387388
}catch(err){
388389
Error.stackTraceLimit=tmpLimit;
389390
throwerr;

‎test/fixtures/test-runner/output/output.snapshot‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,23 +643,36 @@ not ok 61 - assertion errors display actual and expected properly
643643

644644
{
645645
bar: 1,
646+
boo: [
647+
1
648+
],
646649
foo: 1
647650
}
648651

649652
should loosely deep-equal
650653

651-
<ref *1>{
652-
bar: 2,
653-
c: [Circular *1]
654+
{
655+
boo: [
656+
1
657+
],
658+
circular: <ref *1>{
659+
bar: 2,
660+
c: [Circular *1]
661+
}
654662
}
655663
code: 'ERR_ASSERTION'
656664
name: 'AssertionError'
657665
expected:
658-
bar: 2
659-
c: <Circular>
666+
boo:
667+
0: 1
668+
circular:
669+
bar: 2
670+
c: <Circular>
660671
actual:
661672
foo: 1
662673
bar: 1
674+
boo:
675+
0: 1
663676
operator: 'deepEqual'
664677
stack: |-
665678
*

‎test/fixtures/test-runner/output/output_cli.snapshot‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,23 +643,36 @@ not ok 61 - assertion errors display actual and expected properly
643643

644644
{
645645
bar: 1,
646+
boo: [
647+
1
648+
],
646649
foo: 1
647650
}
648651

649652
should loosely deep-equal
650653

651-
<ref *1>{
652-
bar: 2,
653-
c: [Circular *1]
654+
{
655+
boo: [
656+
1
657+
],
658+
circular: <ref *1>{
659+
bar: 2,
660+
c: [Circular *1]
661+
}
654662
}
655663
code: 'ERR_ASSERTION'
656664
name: 'AssertionError'
657665
expected:
658-
bar: 2
659-
c: <Circular>
666+
boo:
667+
0: 1
668+
circular:
669+
bar: 2
670+
c: <Circular>
660671
actual:
661672
foo: 1
662673
bar: 1
674+
boo:
675+
0: 1
663676
operator: 'deepEqual'
664677
stack: |-
665678
*

‎test/fixtures/test-runner/output/spec_reporter.snapshot‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,22 @@
263263

264264
{
265265
bar: 1,
266+
boo: [
267+
1
268+
],
266269
foo: 1
267270
}
268271

269272
should loosely deep-equal
270273

271-
<ref *1>{
272-
bar: 2,
273-
c: [Circular *1]
274+
{
275+
boo: [
276+
1
277+
],
278+
circular: <ref *1>{
279+
bar: 2,
280+
c: [Circular *1]
281+
}
274282
}
275283
*{
276284
generatedMessage: true,
@@ -528,14 +536,22 @@
528536

529537
{
530538
bar: 1,
539+
boo: [
540+
1
541+
],
531542
foo: 1
532543
}
533544

534545
should loosely deep-equal
535546

536-
<ref *1>{
537-
bar: 2,
538-
c: [Circular *1]
547+
{
548+
boo: [
549+
1
550+
],
551+
circular: <ref *1>{
552+
bar: 2,
553+
c: [Circular *1]
554+
}
539555
}
540556
*{
541557
generatedMessage: true,

‎test/fixtures/test-runner/output/spec_reporter_cli.snapshot‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,28 @@
263263

264264
{
265265
bar: 1,
266+
boo: [
267+
1
268+
],
266269
foo: 1
267270
}
268271

269272
should loosely deep-equal
270273

271-
<ref *1>{
272-
bar: 2,
273-
c: [Circular *1]
274+
{
275+
boo: [
276+
1
277+
],
278+
circular: <ref *1>{
279+
bar: 2,
280+
c: [Circular *1]
281+
}
274282
}
275283
*{
276284
generatedMessage: true,
277285
code: 'ERR_ASSERTION',
278-
actual:{foo: 1, bar: 1 },
279-
expected: <ref *1>{bar: 2, c: [Circular *1] },
286+
actual:{foo: 1, bar: 1, boo: [ 1 ] },
287+
expected: {boo: [ 1 ], circular: <ref *1>{bar: 2, c: [Circular *1] } },
280288
operator: 'deepEqual'
281289
}
282290

@@ -528,20 +536,28 @@
528536

529537
{
530538
bar: 1,
539+
boo: [
540+
1
541+
],
531542
foo: 1
532543
}
533544

534545
should loosely deep-equal
535546

536-
<ref *1>{
537-
bar: 2,
538-
c: [Circular *1]
547+
{
548+
boo: [
549+
1
550+
],
551+
circular: <ref *1>{
552+
bar: 2,
553+
c: [Circular *1]
554+
}
539555
}
540556
*{
541557
generatedMessage: true,
542558
code: 'ERR_ASSERTION',
543-
actual:{foo: 1, bar: 1 },
544-
expected: <ref *1>{bar: 2, c: [Circular *1] },
559+
actual:{foo: 1, bar: 1, boo: [ 1 ] },
560+
expected: {boo: [ 1 ], circular: <ref *1>{bar: 2, c: [Circular *1] } },
545561
operator: 'deepEqual'
546562
}
547563

0 commit comments

Comments
(0)