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

test_runner: add support for null and date value output #51920

Merged
merged 2 commits into from
Mar 2, 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
26 changes: 18 additions & 8 deletions lib/internal/test_runner/reporter/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
ArrayPrototypeForEach,
ArrayPrototypeJoin,
ArrayPrototypePush,
DatePrototypeToISOString,
ObjectEntries,
RegExpPrototypeSymbolReplace,
RegExpPrototypeSymbolSplit,
Expand Down Expand Up @@ -125,24 +126,28 @@ function tapEscape(input) {
}

function jsToYaml(indent, name, value, seen) {
if (value === null || value === undefined) {
if (value === undefined) {
return '';
}

if (typeof value !== 'object') {
const prefix = `${indent} ${name}: `;
const prefix = `${indent} ${name}:`;

if (value === null) {
return `${prefix} ~\n`;
}

if (typeof value !== 'object') {
if (typeof value !== 'string') {
return `${prefix}${inspectWithNoCustomRetry(value, inspectOptions)}\n`;
return `${prefix} ${inspectWithNoCustomRetry(value, inspectOptions)}\n`;
}

const lines = RegExpPrototypeSymbolSplit(kLineBreakRegExp, value);

if (lines.length === 1) {
return `${prefix}${inspectWithNoCustomRetry(value, inspectOptions)}\n`;
return `${prefix} ${inspectWithNoCustomRetry(value, inspectOptions)}\n`;
}

let str = `${prefix}|-\n`;
let str = `${prefix} |-\n`;

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

if (name != null) {
result += `${indent} ${name}:\n`;
result += prefix;
if (internalBinding('types').isDate(value)) {
// YAML uses the ISO-8601 standard to express dates.
result += ' ' + DatePrototypeToISOString(value);
}
result += '\n';
propsIndent += ' ';
}

Expand Down
32 changes: 30 additions & 2 deletions test/fixtures/test-runner/output/junit_reporter.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,19 @@ 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, 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] }}">
<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] }}">
<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] }}">
[Error [ERR_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
],
Expand All @@ -437,6 +444,13 @@ Error [ERR_TEST_FAILURE]: bar
should loosely deep-equal

{
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand All @@ -451,6 +465,13 @@ should loosely deep-equal

{
bar: 1,
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand All @@ -460,6 +481,13 @@ should loosely deep-equal
should loosely deep-equal

{
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand Down
11 changes: 9 additions & 2 deletions test/fixtures/test-runner/output/lcov_reporter.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,13 @@ DA:389,1
DA:390,1
DA:391,1
DA:392,1
LH:390
LF:392
DA:393,1
DA:394,1
DA:395,1
DA:396,1
DA:397,1
DA:398,1
DA:399,1
LH:397
LF:399
end_of_record
9 changes: 8 additions & 1 deletion test/fixtures/test-runner/output/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,15 @@ test('assertion errors display actual and expected properly', async () => {
const tmpLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 1;
const boo = [1];
const baz = {
date: new Date(0),
null: null,
number: 1,
string: 'Hello',
undefined: undefined,
}
try {
assert.deepEqual({ foo: 1, bar: 1, boo }, { boo, circular }); // eslint-disable-line no-restricted-properties
assert.deepEqual({ foo: 1, bar: 1, boo, baz }, { boo, baz, circular }); // eslint-disable-line no-restricted-properties
} catch (err) {
Error.stackTraceLimit = tmpLimit;
throw err;
Expand Down
24 changes: 24 additions & 0 deletions test/fixtures/test-runner/output/output.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,13 @@ not ok 61 - assertion errors display actual and expected properly

{
bar: 1,
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand All @@ -652,6 +659,13 @@ not ok 61 - assertion errors display actual and expected properly
should loosely deep-equal

{
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand All @@ -665,6 +679,11 @@ not ok 61 - assertion errors display actual and expected properly
expected:
boo:
0: 1
baz:
date: 1970-01-01T00:00:00.000Z
null: ~
number: 1
string: 'Hello'
circular:
bar: 2
c: <Circular>
Expand All @@ -673,6 +692,11 @@ not ok 61 - assertion errors display actual and expected properly
bar: 1
boo:
0: 1
baz:
date: 1970-01-01T00:00:00.000Z
null: ~
number: 1
string: 'Hello'
operator: 'deepEqual'
stack: |-
*
Expand Down
24 changes: 24 additions & 0 deletions test/fixtures/test-runner/output/output_cli.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,13 @@ not ok 61 - assertion errors display actual and expected properly

{
bar: 1,
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand All @@ -652,6 +659,13 @@ not ok 61 - assertion errors display actual and expected properly
should loosely deep-equal

{
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand All @@ -665,6 +679,11 @@ not ok 61 - assertion errors display actual and expected properly
expected:
boo:
0: 1
baz:
date: 1970-01-01T00:00:00.000Z
null: ~
number: 1
string: 'Hello'
circular:
bar: 2
c: <Circular>
Expand All @@ -673,6 +692,11 @@ not ok 61 - assertion errors display actual and expected properly
bar: 1
boo:
0: 1
baz:
date: 1970-01-01T00:00:00.000Z
null: ~
number: 1
string: 'Hello'
operator: 'deepEqual'
stack: |-
*
Expand Down
28 changes: 28 additions & 0 deletions test/fixtures/test-runner/output/spec_reporter.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@

{
bar: 1,
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand All @@ -272,6 +279,13 @@
should loosely deep-equal

{
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand Down Expand Up @@ -536,6 +550,13 @@

{
bar: 1,
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand All @@ -545,6 +566,13 @@
should loosely deep-equal

{
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand Down
36 changes: 32 additions & 4 deletions test/fixtures/test-runner/output/spec_reporter_cli.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@

{
bar: 1,
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand All @@ -272,6 +279,13 @@
should loosely deep-equal

{
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand All @@ -283,8 +297,8 @@
* {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: { foo: 1, bar: 1, boo: [ 1 ] },
expected: { boo: [ 1 ], circular: <ref *1> { bar: 2, c: [Circular *1] } },
actual: { foo: 1, bar: 1, boo: [ 1 ], baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined } },
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] } },
operator: 'deepEqual'
}

Expand Down Expand Up @@ -536,6 +550,13 @@

{
bar: 1,
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand All @@ -545,6 +566,13 @@
should loosely deep-equal

{
baz: {
date: 1970-01-01T00:00:00.000Z,
null: null,
number: 1,
string: 'Hello',
undefined: undefined
},
boo: [
1
],
Expand All @@ -556,8 +584,8 @@
* {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: { foo: 1, bar: 1, boo: [ 1 ] },
expected: { boo: [ 1 ], circular: <ref *1> { bar: 2, c: [Circular *1] } },
actual: { foo: 1, bar: 1, boo: [ 1 ], baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined } },
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] } },
operator: 'deepEqual'
}

Expand Down