Skip to content

Commit

Permalink
test_runner: add Subtest to tap protocol output
Browse files Browse the repository at this point in the history
PR-URL: #43417
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
MoLow authored and targos committed Jul 12, 2022
1 parent 3247280 commit dda64dd
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/internal/test_runner/tap_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class TapStream extends Readable {
return `TODO${reason ? ` ${tapEscape(reason)}` : ''}`;
}

subtest(indent, name) {
this.#tryPush(`${indent}# Subtest: ${tapEscape(name)}\n`);
}

details(indent, duration, error) {
let details = `${indent} ---\n`;

Expand Down
6 changes: 6 additions & 0 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ class Test extends AsyncResource {
return;
}

if (i === 1 && this.parent !== null) {
this.reporter.subtest(this.indent, this.name);
}

// Report the subtest's results and remove it from the ready map.
subtest.finalize();
this.readySubtests.delete(i);
Expand Down Expand Up @@ -416,6 +420,8 @@ class Test extends AsyncResource {
// Output this test's results and update the parent's waiting counter.
if (this.subtests.length > 0) {
this.reporter.plan(this.subtests[0].indent, this.subtests.length);
} else {
this.reporter.subtest(this.indent, this.name);
}

this.report();
Expand Down
2 changes: 2 additions & 0 deletions test/message/test_runner_no_refs.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
TAP version 13
# Subtest: does not keep event loop alive
# Subtest: +does not keep event loop alive
not ok 1 - +does not keep event loop alive
---
duration_ms: *
Expand Down
23 changes: 23 additions & 0 deletions test/message/test_runner_only_tests.out
Original file line number Diff line number Diff line change
@@ -1,76 +1,97 @@
TAP version 13
# Subtest: only = undefined
ok 1 - only = undefined # SKIP 'only' option not set
---
duration_ms: *
...
# Subtest: only = undefined, skip = string
ok 2 - only = undefined, skip = string # SKIP 'only' option not set
---
duration_ms: *
...
# Subtest: only = undefined, skip = true
ok 3 - only = undefined, skip = true # SKIP 'only' option not set
---
duration_ms: *
...
# Subtest: only = undefined, skip = false
ok 4 - only = undefined, skip = false # SKIP 'only' option not set
---
duration_ms: *
...
# Subtest: only = false
ok 5 - only = false # SKIP 'only' option not set
---
duration_ms: *
...
# Subtest: only = false, skip = string
ok 6 - only = false, skip = string # SKIP 'only' option not set
---
duration_ms: *
...
# Subtest: only = false, skip = true
ok 7 - only = false, skip = true # SKIP 'only' option not set
---
duration_ms: *
...
# Subtest: only = false, skip = false
ok 8 - only = false, skip = false # SKIP 'only' option not set
---
duration_ms: *
...
# Subtest: only = true, skip = string
ok 9 - only = true, skip = string # SKIP skip message
---
duration_ms: *
...
# Subtest: only = true, skip = true
ok 10 - only = true, skip = true # SKIP
---
duration_ms: *
...
# Subtest: only = true, with subtests
# Subtest: running subtest 1
ok 1 - running subtest 1
---
duration_ms: *
...
# Subtest: running subtest 2
ok 2 - running subtest 2
---
duration_ms: *
...
# Subtest: skipped subtest 1
ok 3 - skipped subtest 1 # SKIP 'only' option not set
---
duration_ms: *
...
# Subtest: skipped subtest 2
ok 4 - skipped subtest 2 # SKIP 'only' option not set
---
duration_ms: *
...
# Subtest: running subtest 3
ok 5 - running subtest 3
---
duration_ms: *
...
# Subtest: running subtest 4
# Subtest: running sub-subtest 1
ok 1 - running sub-subtest 1
---
duration_ms: *
...
# Subtest: running sub-subtest 2
ok 2 - running sub-subtest 2
---
duration_ms: *
...
# Subtest: skipped sub-subtest 1
ok 3 - skipped sub-subtest 1 # SKIP 'only' option not set
---
duration_ms: *
...
# Subtest: skipped sub-subtest 2
ok 4 - skipped sub-subtest 2 # SKIP 'only' option not set
---
duration_ms: *
Expand All @@ -80,10 +101,12 @@ ok 10 - only = true, skip = true # SKIP
---
duration_ms: *
...
# Subtest: skipped subtest 3
ok 7 - skipped subtest 3 # SKIP 'only' option not set
---
duration_ms: *
...
# Subtest: skipped subtest 4
ok 8 - skipped subtest 4 # SKIP
---
duration_ms: *
Expand Down
Loading

0 comments on commit dda64dd

Please sign in to comment.