Skip to content

Commit 0040030

Browse files
MoLowRafaelGSS
authored andcommitted
test_runner: report tap subtest in order
PR-URL: #45220 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent eed799b commit 0040030

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

lib/internal/test_runner/test.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class TestContext {
142142
class Test extends AsyncResource {
143143
#abortController;
144144
#outerSignal;
145+
#reportedSubtest;
145146

146147
constructor(options) {
147148
super('Test');
@@ -308,7 +309,7 @@ class Test extends AsyncResource {
308309
}
309310

310311
if (i === 1 && this.parent !== null) {
311-
this.reporter.subtest(this.indent, this.name);
312+
this.reportSubtest();
312313
}
313314

314315
// Report the subtest's results and remove it from the ready map.
@@ -631,12 +632,6 @@ class Test extends AsyncResource {
631632
this.processReadySubtestRange(true);
632633

633634
// Output this test's results and update the parent's waiting counter.
634-
if (this.subtests.length > 0) {
635-
this.reporter.plan(this.subtests[0].indent, this.subtests.length);
636-
} else {
637-
this.reporter.subtest(this.indent, this.name);
638-
}
639-
640635
this.report();
641636
this.parent.waitingOn++;
642637
this.finished = true;
@@ -648,6 +643,11 @@ class Test extends AsyncResource {
648643
}
649644

650645
report() {
646+
if (this.subtests.length > 0) {
647+
this.reporter.plan(this.subtests[0].indent, this.subtests.length);
648+
} else {
649+
this.reportSubtest();
650+
}
651651
let directive;
652652

653653
if (this.skipped) {
@@ -666,6 +666,15 @@ class Test extends AsyncResource {
666666
this.reporter.diagnostic(this.indent, this.diagnostics[i]);
667667
}
668668
}
669+
670+
reportSubtest() {
671+
if (this.#reportedSubtest || this.parent === null) {
672+
return;
673+
}
674+
this.#reportedSubtest = true;
675+
this.parent.reportSubtest();
676+
this.reporter.subtest(this.indent, this.name);
677+
}
669678
}
670679

671680
class TestHook extends Test {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Flags: --no-warnings
2+
'use strict';
3+
require('../common');
4+
const { describe, it } = require('node:test');
5+
6+
describe('nested - no tests', () => {
7+
describe('nested', () => {
8+
it('nested', () => {});
9+
});
10+
});
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)