diff --git a/lib/internal/test_runner/reporter/tap.js b/lib/internal/test_runner/reporter/tap.js index cd0bbe8ca53003..ed8c3f836d4694 100644 --- a/lib/internal/test_runner/reporter/tap.js +++ b/lib/internal/test_runner/reporter/tap.js @@ -3,6 +3,7 @@ const { ArrayPrototypeForEach, ArrayPrototypeJoin, ArrayPrototypePush, + DatePrototypeToISOString, ObjectEntries, RegExpPrototypeSymbolReplace, RegExpPrototypeSymbolSplit, @@ -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`; @@ -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 += ' '; } diff --git a/test/fixtures/test-runner/output/junit_reporter.snapshot b/test/fixtures/test-runner/output/junit_reporter.snapshot index 94d16f7205a71a..c7136d18e6c3df 100644 --- a/test/fixtures/test-runner/output/junit_reporter.snapshot +++ b/test/fixtures/test-runner/output/junit_reporter.snapshot @@ -422,12 +422,19 @@ Error [ERR_TEST_FAILURE]: bar } - - + + [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 ], @@ -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 ], @@ -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 ], @@ -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 ], diff --git a/test/fixtures/test-runner/output/lcov_reporter.snapshot b/test/fixtures/test-runner/output/lcov_reporter.snapshot index 7146a369275980..11b2bc10394cb9 100644 --- a/test/fixtures/test-runner/output/lcov_reporter.snapshot +++ b/test/fixtures/test-runner/output/lcov_reporter.snapshot @@ -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 diff --git a/test/fixtures/test-runner/output/output.js b/test/fixtures/test-runner/output/output.js index 95512e745fccaa..1557b4da4ee7d9 100644 --- a/test/fixtures/test-runner/output/output.js +++ b/test/fixtures/test-runner/output/output.js @@ -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; diff --git a/test/fixtures/test-runner/output/output.snapshot b/test/fixtures/test-runner/output/output.snapshot index dfa8b3f2df2b7a..0e6cab8549d4b2 100644 --- a/test/fixtures/test-runner/output/output.snapshot +++ b/test/fixtures/test-runner/output/output.snapshot @@ -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 ], @@ -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 ], @@ -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: @@ -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: |- * diff --git a/test/fixtures/test-runner/output/output_cli.snapshot b/test/fixtures/test-runner/output/output_cli.snapshot index 3bfa8cee4bf2a1..cd2be499a3b7de 100644 --- a/test/fixtures/test-runner/output/output_cli.snapshot +++ b/test/fixtures/test-runner/output/output_cli.snapshot @@ -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 ], @@ -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 ], @@ -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: @@ -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: |- * diff --git a/test/fixtures/test-runner/output/spec_reporter.snapshot b/test/fixtures/test-runner/output/spec_reporter.snapshot index bfa5b61ac00137..5af5f4750569bc 100644 --- a/test/fixtures/test-runner/output/spec_reporter.snapshot +++ b/test/fixtures/test-runner/output/spec_reporter.snapshot @@ -263,6 +263,13 @@ { bar: 1, + baz: { + date: 1970-01-01T00:00:00.000Z, + null: null, + number: 1, + string: 'Hello', + undefined: undefined + }, boo: [ 1 ], @@ -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 ], @@ -536,6 +550,13 @@ { bar: 1, + baz: { + date: 1970-01-01T00:00:00.000Z, + null: null, + number: 1, + string: 'Hello', + undefined: undefined + }, boo: [ 1 ], @@ -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 ], diff --git a/test/fixtures/test-runner/output/spec_reporter_cli.snapshot b/test/fixtures/test-runner/output/spec_reporter_cli.snapshot index 933385e1e02161..1321cb7321400d 100644 --- a/test/fixtures/test-runner/output/spec_reporter_cli.snapshot +++ b/test/fixtures/test-runner/output/spec_reporter_cli.snapshot @@ -263,6 +263,13 @@ { bar: 1, + baz: { + date: 1970-01-01T00:00:00.000Z, + null: null, + number: 1, + string: 'Hello', + undefined: undefined + }, boo: [ 1 ], @@ -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 ], @@ -283,8 +297,8 @@ * { generatedMessage: true, code: 'ERR_ASSERTION', - actual: { foo: 1, bar: 1, boo: [ 1 ] }, - expected: { boo: [ 1 ], circular: { 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: { bar: 2, c: [Circular *1] } }, operator: 'deepEqual' } @@ -536,6 +550,13 @@ { bar: 1, + baz: { + date: 1970-01-01T00:00:00.000Z, + null: null, + number: 1, + string: 'Hello', + undefined: undefined + }, boo: [ 1 ], @@ -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 ], @@ -556,8 +584,8 @@ * { generatedMessage: true, code: 'ERR_ASSERTION', - actual: { foo: 1, bar: 1, boo: [ 1 ] }, - expected: { boo: [ 1 ], circular: { 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: { bar: 2, c: [Circular *1] } }, operator: 'deepEqual' }