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 Subtest to tap protocol output #43417

Merged
merged 8 commits into from
Jun 19, 2022
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
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);
cjihrig marked this conversation as resolved.
Show resolved Hide resolved
}

// 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