Skip to content

Commit

Permalink
update tap reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
cjihrig committed Aug 8, 2023
1 parent 78e76d3 commit c735349
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/internal/test_runner/reporter/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ async function * tapReporter(source) {
yield `TAP version ${kDefaultTAPVersion}\n`;
for await (const { type, data } of source) {
switch (type) {
case 'test:fail':
case 'test:fail': {
yield reportTest(data.nesting, data.testNumber, 'not ok', data.name, data.skip, data.todo);
yield reportDetails(data.nesting, data.details);
const location = `${data.file}:${data.line}:${data.column}`;
yield reportDetails(data.nesting, data.details, location);
break;
case 'test:pass':
} case 'test:pass':
yield reportTest(data.nesting, data.testNumber, 'ok', data.name, data.skip, data.todo);
yield reportDetails(data.nesting, data.details);
yield reportDetails(data.nesting, data.details, null);
break;
case 'test:plan':
yield `${indent(data.nesting)}1..${data.count}\n`;
Expand Down Expand Up @@ -81,13 +82,18 @@ function reportTest(nesting, testNumber, status, name, skip, todo) {
return line;
}

function reportDetails(nesting, data = kEmptyObject) {
function reportDetails(nesting, data = kEmptyObject, location) {
const { error, duration_ms } = data;
const _indent = indent(nesting);
let details = `${_indent} ---\n`;

details += jsToYaml(_indent, 'duration_ms', duration_ms);
details += jsToYaml(_indent, 'type', data.type);

if (location) {
details += jsToYaml(_indent, 'location', location);
}

details += jsToYaml(_indent, null, error, new SafeSet());
details += `${_indent} ...\n`;
return details;
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/test-runner/output/abort.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ TAP version 13
not ok 5 - not ok 1
---
duration_ms: *
location: '/test/fixtures/test-runner/output/abort.js:11:7'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
Expand All @@ -32,6 +33,7 @@ TAP version 13
not ok 6 - not ok 2
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort.js:12:7'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
Expand All @@ -40,6 +42,7 @@ TAP version 13
not ok 7 - not ok 3
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort.js:13:7'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
Expand All @@ -60,6 +63,7 @@ TAP version 13
not ok 8 - not ok 4
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort.js:14:7'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
Expand All @@ -80,6 +84,7 @@ TAP version 13
not ok 9 - not ok 5
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort.js:15:7'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
Expand All @@ -100,6 +105,7 @@ TAP version 13
not ok 1 - promise timeout signal
---
duration_ms: *
location: '/test/fixtures/test-runner/output/abort.js:5:1'
failureType: 'testAborted'
error: 'The operation was aborted due to timeout'
code: 23
Expand All @@ -114,6 +120,7 @@ not ok 1 - promise timeout signal
not ok 2 - promise abort signal
---
duration_ms: *
location: '/test/fixtures/test-runner/output/abort.js:21:1'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
Expand Down Expand Up @@ -154,6 +161,7 @@ not ok 2 - promise abort signal
not ok 5 - not ok 1
---
duration_ms: *
location: '/test/fixtures/test-runner/output/abort.js:30:5'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
Expand All @@ -162,6 +170,7 @@ not ok 2 - promise abort signal
not ok 6 - not ok 2
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort.js:31:5'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
Expand All @@ -170,6 +179,7 @@ not ok 2 - promise abort signal
not ok 7 - not ok 3
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort.js:32:5'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
Expand All @@ -190,6 +200,7 @@ not ok 2 - promise abort signal
not ok 8 - not ok 4
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort.js:33:5'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
Expand All @@ -210,6 +221,7 @@ not ok 2 - promise abort signal
not ok 9 - not ok 5
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort.js:34:5'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
Expand All @@ -230,6 +242,7 @@ not ok 2 - promise abort signal
not ok 3 - callback timeout signal
---
duration_ms: *
location: '/test/fixtures/test-runner/output/abort.js:25:1'
failureType: 'testAborted'
error: 'The operation was aborted due to timeout'
code: 23
Expand All @@ -244,6 +257,7 @@ not ok 3 - callback timeout signal
not ok 4 - callback abort signal
---
duration_ms: *
location: '/test/fixtures/test-runner/output/abort.js:39:1'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/test-runner/output/abort_hooks.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ TAP version 13
not ok 1 - test 1
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort_hooks.js:11:3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
Expand All @@ -20,6 +21,7 @@ TAP version 13
not ok 2 - test 2
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort_hooks.js:14:3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
Expand All @@ -29,6 +31,7 @@ not ok 1 - 1 before describe
---
duration_ms: *
type: 'suite'
location: '/test/fixtures/test-runner/output/abort_hooks.js:4:1'
failureType: 'hookFailed'
error: 'This operation was aborted'
code: 20
Expand Down Expand Up @@ -61,6 +64,7 @@ not ok 2 - 2 after describe
---
duration_ms: *
type: 'suite'
location: '/test/fixtures/test-runner/output/abort_hooks.js:19:1'
failureType: 'hookFailed'
error: 'This operation was aborted'
code: 20
Expand All @@ -82,6 +86,7 @@ not ok 2 - 2 after describe
not ok 1 - test 1
---
duration_ms: *
location: '/test/fixtures/test-runner/output/abort_hooks.js:41:3'
failureType: 'hookFailed'
error: 'This operation was aborted'
code: 20
Expand All @@ -102,6 +107,7 @@ not ok 2 - 2 after describe
not ok 2 - test 2
---
duration_ms: *
location: '/test/fixtures/test-runner/output/abort_hooks.js:44:3'
failureType: 'hookFailed'
error: 'This operation was aborted'
code: 20
Expand All @@ -123,6 +129,7 @@ not ok 3 - 3 beforeEach describe
---
duration_ms: *
type: 'suite'
location: '/test/fixtures/test-runner/output/abort_hooks.js:34:1'
failureType: 'subtestsFailed'
error: '2 subtests failed'
code: 'ERR_TEST_FAILURE'
Expand All @@ -132,6 +139,7 @@ not ok 3 - 3 beforeEach describe
not ok 1 - test 1
---
duration_ms: *
location: '/test/fixtures/test-runner/output/abort_hooks.js:56:3'
failureType: 'hookFailed'
error: 'This operation was aborted'
code: 20
Expand All @@ -152,6 +160,7 @@ not ok 3 - 3 beforeEach describe
not ok 2 - test 2
---
duration_ms: *
location: '/test/fixtures/test-runner/output/abort_hooks.js:59:3'
failureType: 'hookFailed'
error: 'This operation was aborted'
code: 20
Expand All @@ -173,6 +182,7 @@ not ok 4 - 4 afterEach describe
---
duration_ms: *
type: 'suite'
location: '/test/fixtures/test-runner/output/abort_hooks.js:49:1'
failureType: 'subtestsFailed'
error: '2 subtests failed'
code: 'ERR_TEST_FAILURE'
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/test-runner/output/abort_suite.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ TAP version 13
not ok 5 - not ok 1
---
duration_ms: *
location: '/test/fixtures/test-runner/output/abort_suite.js:10:3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
Expand All @@ -32,6 +33,7 @@ TAP version 13
not ok 6 - not ok 2
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort_suite.js:11:3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
Expand All @@ -40,6 +42,7 @@ TAP version 13
not ok 7 - not ok 3
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort_suite.js:12:3'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
Expand All @@ -60,6 +63,7 @@ TAP version 13
not ok 8 - not ok 4
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort_suite.js:13:3'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
Expand All @@ -80,6 +84,7 @@ TAP version 13
not ok 9 - not ok 5
---
duration_ms: ZERO
location: '/test/fixtures/test-runner/output/abort_suite.js:14:3'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
Expand All @@ -101,6 +106,7 @@ not ok 1 - describe timeout signal
---
duration_ms: *
type: 'suite'
location: '/test/fixtures/test-runner/output/abort_suite.js:5:1'
failureType: 'testAborted'
error: 'The operation was aborted due to timeout'
code: 23
Expand All @@ -116,6 +122,7 @@ not ok 2 - describe abort signal
---
duration_ms: *
type: 'suite'
location: '/test/fixtures/test-runner/output/abort_suite.js:19:1'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
Expand Down
Loading

0 comments on commit c735349

Please sign in to comment.