Skip to content

Commit 08269c5

Browse files
committed
fix: report tap subtest in order
PR-URL: nodejs/node#45220 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> (cherry picked from commit 3e57891ee2fde0971e18fc383c25acf8f90def05)
1 parent 0bfdb77 commit 08269c5

File tree

3 files changed

+54
-8
lines changed

3 files changed

+54
-8
lines changed

lib/internal/test_runner/test.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/nodejs/node/blob/a69a30016cf3395b0bd775c1340ab6ecbac58296/lib/internal/test_runner/test.js
1+
// https://github.com/nodejs/node/blob/3e57891ee2fde0971e18fc383c25acf8f90def05/lib/internal/test_runner/test.js
22

33
'use strict'
44

@@ -146,6 +146,7 @@ class TestContext {
146146
class Test extends AsyncResource {
147147
#abortController
148148
#outerSignal
149+
#reportedSubtest
149150

150151
constructor (options) {
151152
super('Test')
@@ -312,7 +313,7 @@ class Test extends AsyncResource {
312313
}
313314

314315
if (i === 1 && this.parent !== null) {
315-
this.reporter.subtest(this.indent, this.name)
316+
this.reportSubtest()
316317
}
317318

318319
// Report the subtest's results and remove it from the ready map.
@@ -635,12 +636,6 @@ class Test extends AsyncResource {
635636
this.processReadySubtestRange(true)
636637

637638
// Output this test's results and update the parent's waiting counter.
638-
if (this.subtests.length > 0) {
639-
this.reporter.plan(this.subtests[0].indent, this.subtests.length)
640-
} else {
641-
this.reporter.subtest(this.indent, this.name)
642-
}
643-
644639
this.report()
645640
this.parent.waitingOn++
646641
this.finished = true
@@ -652,6 +647,11 @@ class Test extends AsyncResource {
652647
}
653648

654649
report () {
650+
if (this.subtests.length > 0) {
651+
this.reporter.plan(this.subtests[0].indent, this.subtests.length)
652+
} else {
653+
this.reportSubtest()
654+
}
655655
let directive
656656

657657
if (this.skipped) {
@@ -670,6 +670,15 @@ class Test extends AsyncResource {
670670
this.reporter.diagnostic(this.indent, this.diagnostics[i])
671671
}
672672
}
673+
674+
reportSubtest () {
675+
if (this.#reportedSubtest || this.parent === null) {
676+
return
677+
}
678+
this.#reportedSubtest = true
679+
this.parent.reportSubtest()
680+
this.reporter.subtest(this.indent, this.name)
681+
}
673682
}
674683

675684
class TestHook extends Test {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// https://github.com/nodejs/node/blob/3e57891ee2fde0971e18fc383c25acf8f90def05/test/message/test_runner_describe_nested.js
2+
// Flags: --no-warnings
3+
'use strict'
4+
require('../common')
5+
const { describe, it } = require('#node:test')
6+
7+
describe('nested - no tests', () => {
8+
describe('nested', () => {
9+
it('nested', () => {})
10+
})
11+
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
TAP version 13
2+
# Subtest: nested - no tests
3+
# Subtest: nested
4+
# Subtest: nested
5+
ok 1 - nested
6+
---
7+
duration_ms: *
8+
...
9+
1..1
10+
ok 1 - nested
11+
---
12+
duration_ms: *
13+
...
14+
1..1
15+
ok 1 - nested - no tests
16+
---
17+
duration_ms: *
18+
...
19+
1..1
20+
# tests 1
21+
# pass 1
22+
# fail 0
23+
# cancelled 0
24+
# skipped 0
25+
# todo 0
26+
# duration_ms *

0 commit comments

Comments
 (0)