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: nodejs/node#43417
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
MoLow authored and aduh95 committed Jul 8, 2022
1 parent ba68062 commit 28eb18d
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/internal/test_runner/tap_stream.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/1aab13cad9c800f4121c1d35b554b78c1b17bdbd/lib/internal/test_runner/tap_stream.js
// https://github.com/nodejs/node/blob/5fadc389b8a9a32809adda8245ad32928623409b/lib/internal/test_runner/tap_stream.js

'use strict'

Expand Down Expand Up @@ -75,6 +75,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
8 changes: 7 additions & 1 deletion lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/44aa46d70537d3807bd9255db77f76cd9dea5267/lib/internal/test_runner/test.js
// https://github.com/nodejs/node/blob/5fadc389b8a9a32809adda8245ad32928623409b/lib/internal/test_runner/test.js

'use strict'

Expand Down Expand Up @@ -188,6 +188,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 @@ -421,6 +425,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 28eb18d

Please sign in to comment.