Skip to content

Commit 8451990

Browse files
authored
test_runner: add support for null and date value output
PR-URL: #51920 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 1429381 commit 8451990

File tree

8 files changed

+173
-17
lines changed

8 files changed

+173
-17
lines changed

lib/internal/test_runner/reporter/tap.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const {
33
ArrayPrototypeForEach,
44
ArrayPrototypeJoin,
55
ArrayPrototypePush,
6+
DatePrototypeToISOString,
67
ObjectEntries,
78
RegExpPrototypeSymbolReplace,
89
RegExpPrototypeSymbolSplit,
@@ -125,24 +126,28 @@ function tapEscape(input) {
125126
}
126127

127128
function jsToYaml(indent, name, value, seen) {
128-
if (value === null || value === undefined) {
129+
if (value === undefined) {
129130
return '';
130131
}
131132

132-
if (typeof value !== 'object') {
133-
const prefix = `${indent} ${name}: `;
133+
const prefix = `${indent} ${name}:`;
134+
135+
if (value === null) {
136+
return `${prefix} ~\n`;
137+
}
134138

139+
if (typeof value !== 'object') {
135140
if (typeof value !== 'string') {
136-
return `${prefix}${inspectWithNoCustomRetry(value, inspectOptions)}\n`;
141+
return `${prefix} ${inspectWithNoCustomRetry(value, inspectOptions)}\n`;
137142
}
138143

139144
const lines = RegExpPrototypeSymbolSplit(kLineBreakRegExp, value);
140145

141146
if (lines.length === 1) {
142-
return `${prefix}${inspectWithNoCustomRetry(value, inspectOptions)}\n`;
147+
return `${prefix} ${inspectWithNoCustomRetry(value, inspectOptions)}\n`;
143148
}
144149

145-
let str = `${prefix}|-\n`;
150+
let str = `${prefix} |-\n`;
146151

147152
for (let i = 0; i < lines.length; i++) {
148153
str += `${indent} ${lines[i]}\n`;
@@ -154,11 +159,16 @@ function jsToYaml(indent, name, value, seen) {
154159
seen.add(value);
155160
const entries = ObjectEntries(value);
156161
const isErrorObj = isError(value);
157-
let result = '';
158162
let propsIndent = indent;
163+
let result = '';
159164

160165
if (name != null) {
161-
result += `${indent} ${name}:\n`;
166+
result += prefix;
167+
if (internalBinding('types').isDate(value)) {
168+
// YAML uses the ISO-8601 standard to express dates.
169+
result += ' ' + DatePrototypeToISOString(value);
170+
}
171+
result += '\n';
162172
propsIndent += ' ';
163173
}
164174

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

+30-2
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,19 @@ Error [ERR_TEST_FAILURE]: bar
422422
}
423423
</failure>
424424
</testcase>
425-
<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] }}">
426-
<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] }}">
425+
<testcase name="assertion errors display actual and expected properly" time="*" classname="test" failure="Expected values to be loosely deep-equal:{ bar: 1, baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined }, boo: [ 1 ], foo: 1}should loosely deep-equal{ baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined }, boo: [ 1 ], circular: &lt;ref *1> { bar: 2, c: [Circular *1] }}">
426+
<failure type="testCodeFailure" message="Expected values to be loosely deep-equal:{ bar: 1, baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined }, boo: [ 1 ], foo: 1}should loosely deep-equal{ baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined }, 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+
baz: {
432+
date: 1970-01-01T00:00:00.000Z,
433+
null: null,
434+
number: 1,
435+
string: 'Hello',
436+
undefined: undefined
437+
},
431438
boo: [
432439
1
433440
],
@@ -437,6 +444,13 @@ Error [ERR_TEST_FAILURE]: bar
437444
should loosely deep-equal
438445

439446
{
447+
baz: {
448+
date: 1970-01-01T00:00:00.000Z,
449+
null: null,
450+
number: 1,
451+
string: 'Hello',
452+
undefined: undefined
453+
},
440454
boo: [
441455
1
442456
],
@@ -451,6 +465,13 @@ should loosely deep-equal
451465

452466
{
453467
bar: 1,
468+
baz: {
469+
date: 1970-01-01T00:00:00.000Z,
470+
null: null,
471+
number: 1,
472+
string: 'Hello',
473+
undefined: undefined
474+
},
454475
boo: [
455476
1
456477
],
@@ -460,6 +481,13 @@ should loosely deep-equal
460481
should loosely deep-equal
461482

462483
{
484+
baz: {
485+
date: 1970-01-01T00:00:00.000Z,
486+
null: null,
487+
number: 1,
488+
string: 'Hello',
489+
undefined: undefined
490+
},
463491
boo: [
464492
1
465493
],

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,13 @@ DA:389,1
695695
DA:390,1
696696
DA:391,1
697697
DA:392,1
698-
LH:390
699-
LF:392
698+
DA:393,1
699+
DA:394,1
700+
DA:395,1
701+
DA:396,1
702+
DA:397,1
703+
DA:398,1
704+
DA:399,1
705+
LH:397
706+
LF:399
700707
end_of_record

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,15 @@ test('assertion errors display actual and expected properly', async () => {
383383
const tmpLimit = Error.stackTraceLimit;
384384
Error.stackTraceLimit = 1;
385385
const boo = [1];
386+
const baz = {
387+
date: new Date(0),
388+
null: null,
389+
number: 1,
390+
string: 'Hello',
391+
undefined: undefined,
392+
}
386393
try {
387-
assert.deepEqual({ foo: 1, bar: 1, boo }, { boo, circular }); // eslint-disable-line no-restricted-properties
394+
assert.deepEqual({ foo: 1, bar: 1, boo, baz }, { boo, baz, circular }); // eslint-disable-line no-restricted-properties
388395
} catch (err) {
389396
Error.stackTraceLimit = tmpLimit;
390397
throw err;

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

+24
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,13 @@ not ok 61 - assertion errors display actual and expected properly
643643

644644
{
645645
bar: 1,
646+
baz: {
647+
date: 1970-01-01T00:00:00.000Z,
648+
null: null,
649+
number: 1,
650+
string: 'Hello',
651+
undefined: undefined
652+
},
646653
boo: [
647654
1
648655
],
@@ -652,6 +659,13 @@ not ok 61 - assertion errors display actual and expected properly
652659
should loosely deep-equal
653660

654661
{
662+
baz: {
663+
date: 1970-01-01T00:00:00.000Z,
664+
null: null,
665+
number: 1,
666+
string: 'Hello',
667+
undefined: undefined
668+
},
655669
boo: [
656670
1
657671
],
@@ -665,6 +679,11 @@ not ok 61 - assertion errors display actual and expected properly
665679
expected:
666680
boo:
667681
0: 1
682+
baz:
683+
date: 1970-01-01T00:00:00.000Z
684+
null: ~
685+
number: 1
686+
string: 'Hello'
668687
circular:
669688
bar: 2
670689
c: <Circular>
@@ -673,6 +692,11 @@ not ok 61 - assertion errors display actual and expected properly
673692
bar: 1
674693
boo:
675694
0: 1
695+
baz:
696+
date: 1970-01-01T00:00:00.000Z
697+
null: ~
698+
number: 1
699+
string: 'Hello'
676700
operator: 'deepEqual'
677701
stack: |-
678702
*

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

+24
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,13 @@ not ok 61 - assertion errors display actual and expected properly
643643

644644
{
645645
bar: 1,
646+
baz: {
647+
date: 1970-01-01T00:00:00.000Z,
648+
null: null,
649+
number: 1,
650+
string: 'Hello',
651+
undefined: undefined
652+
},
646653
boo: [
647654
1
648655
],
@@ -652,6 +659,13 @@ not ok 61 - assertion errors display actual and expected properly
652659
should loosely deep-equal
653660

654661
{
662+
baz: {
663+
date: 1970-01-01T00:00:00.000Z,
664+
null: null,
665+
number: 1,
666+
string: 'Hello',
667+
undefined: undefined
668+
},
655669
boo: [
656670
1
657671
],
@@ -665,6 +679,11 @@ not ok 61 - assertion errors display actual and expected properly
665679
expected:
666680
boo:
667681
0: 1
682+
baz:
683+
date: 1970-01-01T00:00:00.000Z
684+
null: ~
685+
number: 1
686+
string: 'Hello'
668687
circular:
669688
bar: 2
670689
c: <Circular>
@@ -673,6 +692,11 @@ not ok 61 - assertion errors display actual and expected properly
673692
bar: 1
674693
boo:
675694
0: 1
695+
baz:
696+
date: 1970-01-01T00:00:00.000Z
697+
null: ~
698+
number: 1
699+
string: 'Hello'
676700
operator: 'deepEqual'
677701
stack: |-
678702
*

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

+28
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@
263263

264264
{
265265
bar: 1,
266+
baz: {
267+
date: 1970-01-01T00:00:00.000Z,
268+
null: null,
269+
number: 1,
270+
string: 'Hello',
271+
undefined: undefined
272+
},
266273
boo: [
267274
1
268275
],
@@ -272,6 +279,13 @@
272279
should loosely deep-equal
273280

274281
{
282+
baz: {
283+
date: 1970-01-01T00:00:00.000Z,
284+
null: null,
285+
number: 1,
286+
string: 'Hello',
287+
undefined: undefined
288+
},
275289
boo: [
276290
1
277291
],
@@ -536,6 +550,13 @@
536550

537551
{
538552
bar: 1,
553+
baz: {
554+
date: 1970-01-01T00:00:00.000Z,
555+
null: null,
556+
number: 1,
557+
string: 'Hello',
558+
undefined: undefined
559+
},
539560
boo: [
540561
1
541562
],
@@ -545,6 +566,13 @@
545566
should loosely deep-equal
546567

547568
{
569+
baz: {
570+
date: 1970-01-01T00:00:00.000Z,
571+
null: null,
572+
number: 1,
573+
string: 'Hello',
574+
undefined: undefined
575+
},
548576
boo: [
549577
1
550578
],

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

+32-4
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@
263263

264264
{
265265
bar: 1,
266+
baz: {
267+
date: 1970-01-01T00:00:00.000Z,
268+
null: null,
269+
number: 1,
270+
string: 'Hello',
271+
undefined: undefined
272+
},
266273
boo: [
267274
1
268275
],
@@ -272,6 +279,13 @@
272279
should loosely deep-equal
273280

274281
{
282+
baz: {
283+
date: 1970-01-01T00:00:00.000Z,
284+
null: null,
285+
number: 1,
286+
string: 'Hello',
287+
undefined: undefined
288+
},
275289
boo: [
276290
1
277291
],
@@ -283,8 +297,8 @@
283297
* {
284298
generatedMessage: true,
285299
code: 'ERR_ASSERTION',
286-
actual: { foo: 1, bar: 1, boo: [ 1 ] },
287-
expected: { boo: [ 1 ], circular: <ref *1> { bar: 2, c: [Circular *1] } },
300+
actual: { foo: 1, bar: 1, boo: [ 1 ], baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined } },
301+
expected: { boo: [ 1 ], baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined }, circular: <ref *1> { bar: 2, c: [Circular *1] } },
288302
operator: 'deepEqual'
289303
}
290304

@@ -536,6 +550,13 @@
536550

537551
{
538552
bar: 1,
553+
baz: {
554+
date: 1970-01-01T00:00:00.000Z,
555+
null: null,
556+
number: 1,
557+
string: 'Hello',
558+
undefined: undefined
559+
},
539560
boo: [
540561
1
541562
],
@@ -545,6 +566,13 @@
545566
should loosely deep-equal
546567

547568
{
569+
baz: {
570+
date: 1970-01-01T00:00:00.000Z,
571+
null: null,
572+
number: 1,
573+
string: 'Hello',
574+
undefined: undefined
575+
},
548576
boo: [
549577
1
550578
],
@@ -556,8 +584,8 @@
556584
* {
557585
generatedMessage: true,
558586
code: 'ERR_ASSERTION',
559-
actual: { foo: 1, bar: 1, boo: [ 1 ] },
560-
expected: { boo: [ 1 ], circular: <ref *1> { bar: 2, c: [Circular *1] } },
587+
actual: { foo: 1, bar: 1, boo: [ 1 ], baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined } },
588+
expected: { boo: [ 1 ], baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined }, circular: <ref *1> { bar: 2, c: [Circular *1] } },
561589
operator: 'deepEqual'
562590
}
563591

0 commit comments

Comments
 (0)