Skip to content

Commit fc0256b

Browse files
MoLowaduh95
authored andcommitted
feat: add Subtest to tap protocol output
PR-URL: nodejs/node#43417 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 39cce8a commit fc0256b

File tree

6 files changed

+111
-2
lines changed

6 files changed

+111
-2
lines changed

lib/internal/test_runner/tap_stream.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/nodejs/node/blob/1aab13cad9c800f4121c1d35b554b78c1b17bdbd/lib/internal/test_runner/tap_stream.js
1+
// https://github.com/nodejs/node/blob/5fadc389b8a9a32809adda8245ad32928623409b/lib/internal/test_runner/tap_stream.js
22

33
'use strict'
44

@@ -75,6 +75,10 @@ class TapStream extends Readable {
7575
return `TODO${reason ? ` ${tapEscape(reason)}` : ''}`
7676
}
7777

78+
subtest (indent, name) {
79+
this.#tryPush(`${indent}# Subtest: ${tapEscape(name)}\n`)
80+
}
81+
7882
details (indent, duration, error) {
7983
let details = `${indent} ---\n`
8084

lib/internal/test_runner/test.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/nodejs/node/blob/44aa46d70537d3807bd9255db77f76cd9dea5267/lib/internal/test_runner/test.js
1+
// https://github.com/nodejs/node/blob/5fadc389b8a9a32809adda8245ad32928623409b/lib/internal/test_runner/test.js
22

33
'use strict'
44

@@ -188,6 +188,10 @@ class Test extends AsyncResource {
188188
return
189189
}
190190

191+
if (i === 1 && this.parent !== null) {
192+
this.reporter.subtest(this.indent, this.name)
193+
}
194+
191195
// Report the subtest's results and remove it from the ready map.
192196
subtest.finalize()
193197
this.readySubtests.delete(i)
@@ -421,6 +425,8 @@ class Test extends AsyncResource {
421425
// Output this test's results and update the parent's waiting counter.
422426
if (this.subtests.length > 0) {
423427
this.reporter.plan(this.subtests[0].indent, this.subtests.length)
428+
} else {
429+
this.reporter.subtest(this.indent, this.name)
424430
}
425431

426432
this.report()

test/message/test_runner_no_refs.out

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
TAP version 13
2+
# Subtest: does not keep event loop alive
3+
# Subtest: +does not keep event loop alive
24
not ok 1 - +does not keep event loop alive
35
---
46
duration_ms: *

test/message/test_runner_only_tests.out

+23
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,97 @@
11
TAP version 13
2+
# Subtest: only = undefined
23
ok 1 - only = undefined # SKIP 'only' option not set
34
---
45
duration_ms: *
56
...
7+
# Subtest: only = undefined, skip = string
68
ok 2 - only = undefined, skip = string # SKIP 'only' option not set
79
---
810
duration_ms: *
911
...
12+
# Subtest: only = undefined, skip = true
1013
ok 3 - only = undefined, skip = true # SKIP 'only' option not set
1114
---
1215
duration_ms: *
1316
...
17+
# Subtest: only = undefined, skip = false
1418
ok 4 - only = undefined, skip = false # SKIP 'only' option not set
1519
---
1620
duration_ms: *
1721
...
22+
# Subtest: only = false
1823
ok 5 - only = false # SKIP 'only' option not set
1924
---
2025
duration_ms: *
2126
...
27+
# Subtest: only = false, skip = string
2228
ok 6 - only = false, skip = string # SKIP 'only' option not set
2329
---
2430
duration_ms: *
2531
...
32+
# Subtest: only = false, skip = true
2633
ok 7 - only = false, skip = true # SKIP 'only' option not set
2734
---
2835
duration_ms: *
2936
...
37+
# Subtest: only = false, skip = false
3038
ok 8 - only = false, skip = false # SKIP 'only' option not set
3139
---
3240
duration_ms: *
3341
...
42+
# Subtest: only = true, skip = string
3443
ok 9 - only = true, skip = string # SKIP skip message
3544
---
3645
duration_ms: *
3746
...
47+
# Subtest: only = true, skip = true
3848
ok 10 - only = true, skip = true # SKIP
3949
---
4050
duration_ms: *
4151
...
52+
# Subtest: only = true, with subtests
53+
# Subtest: running subtest 1
4254
ok 1 - running subtest 1
4355
---
4456
duration_ms: *
4557
...
58+
# Subtest: running subtest 2
4659
ok 2 - running subtest 2
4760
---
4861
duration_ms: *
4962
...
63+
# Subtest: skipped subtest 1
5064
ok 3 - skipped subtest 1 # SKIP 'only' option not set
5165
---
5266
duration_ms: *
5367
...
68+
# Subtest: skipped subtest 2
5469
ok 4 - skipped subtest 2 # SKIP 'only' option not set
5570
---
5671
duration_ms: *
5772
...
73+
# Subtest: running subtest 3
5874
ok 5 - running subtest 3
5975
---
6076
duration_ms: *
6177
...
78+
# Subtest: running subtest 4
79+
# Subtest: running sub-subtest 1
6280
ok 1 - running sub-subtest 1
6381
---
6482
duration_ms: *
6583
...
84+
# Subtest: running sub-subtest 2
6685
ok 2 - running sub-subtest 2
6786
---
6887
duration_ms: *
6988
...
89+
# Subtest: skipped sub-subtest 1
7090
ok 3 - skipped sub-subtest 1 # SKIP 'only' option not set
7191
---
7292
duration_ms: *
7393
...
94+
# Subtest: skipped sub-subtest 2
7495
ok 4 - skipped sub-subtest 2 # SKIP 'only' option not set
7596
---
7697
duration_ms: *
@@ -80,10 +101,12 @@ ok 10 - only = true, skip = true # SKIP
80101
---
81102
duration_ms: *
82103
...
104+
# Subtest: skipped subtest 3
83105
ok 7 - skipped subtest 3 # SKIP 'only' option not set
84106
---
85107
duration_ms: *
86108
...
109+
# Subtest: skipped subtest 4
87110
ok 8 - skipped subtest 4 # SKIP
88111
---
89112
duration_ms: *

0 commit comments

Comments
 (0)