test_runner: flatten TAP output when running using `--test` · nodejs/node@5b3c606 · GitHub
Skip to content

Commit 5b3c606

Browse files
MoLowjuanarbol
authored andcommitted
test_runner: flatten TAP output when running using --test
PR-URL: #46440 Backport-PR-URL: #46839 Fixes: #45833 Refs: #45833 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 391ff0d commit 5b3c606

9 files changed

Lines changed: 726 additions & 697 deletions

lib/internal/test_runner/runner.js

Lines changed: 56 additions & 33 deletions

lib/internal/test_runner/test.js

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const { cpus } = require('os');
5757
const { bigint: hrtime } = process.hrtime;
5858
const kCallbackAndPromisePresent = 'callbackAndPromisePresent';
5959
const kCancelledByParent = 'cancelledByParent';
60+
const kAborted = 'testAborted';
6061
const kParentAlreadyFinished = 'parentAlreadyFinished';
6162
const kSubtestsFailed = 'subtestsFailed';
6263
const kTestCodeFailure = 'testCodeFailure';
@@ -390,10 +391,12 @@ class Test extends AsyncResource {
390391
}
391392

392393
#abortHandler = () => {
393-
this.cancel(this.#outerSignal?.reason || new AbortError('The test was aborted'));
394+
const error = this.#outerSignal?.reason || new AbortError('The test was aborted');
395+
error.failureType = kAborted;
396+
this.#cancel(error);
394397
};
395398

396-
cancel(error) {
399+
#cancel(error) {
397400
if (this.endTime !== null) {
398401
return;
399402
}
@@ -470,7 +473,7 @@ class Test extends AsyncResource {
470473
return true;
471474
}
472475
if (this.#outerSignal?.aborted) {
473-
this.cancel(this.#outerSignal.reason || new AbortError('The test was aborted'));
476+
this.#abortHandler();
474477
return true;
475478
}
476479
}
@@ -563,7 +566,7 @@ class Test extends AsyncResource {
563566
try { await afterEach(); } catch { /* test is already failing, let's the error */ }
564567
if (isTestFailureError(err)) {
565568
if (err.failureType === kTestTimeoutFailure) {
566-
this.cancel(err);
569+
this.#cancel(err);
567570
} else {
568571
this.fail(err);
569572
}
@@ -577,9 +580,31 @@ class Test extends AsyncResource {
577580
this.postRun();
578581
}
579582

580-
postRun(pendingSubtestsError) {
581-
const counters = { __proto__: null, failed: 0, passed: 0, cancelled: 0, skipped: 0, todo: 0, totalFailed: 0 };
583+
countSubtest(counters) {
584+
// Check SKIP and TODO tests first, as those should not be counted as
585+
// failures.
586+
if (this.skipped) {
587+
counters.skipped++;
588+
} else if (this.isTodo) {
589+
counters.todo++;
590+
} else if (this.cancelled) {
591+
counters.cancelled++;
592+
} else if (!this.passed) {
593+
counters.failed++;
594+
} else {
595+
counters.passed++;
596+
}
597+
598+
if (!this.passed) {
599+
counters.totalFailed++;
600+
}
601+
counters.all++;
602+
}
582603

604+
postRun(pendingSubtestsError) {
605+
const counters = {
606+
__proto__: null, all: 0, failed: 0, passed: 0, cancelled: 0, skipped: 0, todo: 0, totalFailed: 0,
607+
};
583608
// If the test was failed before it even started, then the end time will
584609
// be earlier than the start time. Correct that here.
585610
if (this.endTime < this.startTime) {
@@ -594,27 +619,10 @@ class Test extends AsyncResource {
594619
const subtest = this.subtests[i];
595620

596621
if (!subtest.finished) {
597-
subtest.cancel(pendingSubtestsError);
622+
subtest.#cancel(pendingSubtestsError);
598623
subtest.postRun(pendingSubtestsError);
599624
}
600-
601-
// Check SKIP and TODO tests first, as those should not be counted as
602-
// failures.
603-
if (subtest.skipped) {
604-
counters.skipped++;
605-
} else if (subtest.isTodo) {
606-
counters.todo++;
607-
} else if (subtest.cancelled) {
608-
counters.cancelled++;
609-
} else if (!subtest.passed) {
610-
counters.failed++;
611-
} else {
612-
counters.passed++;
613-
}
614-
615-
if (!subtest.passed) {
616-
counters.totalFailed++;
617-
}
625+
subtest.countSubtest(counters);
618626
}
619627

620628
if ((this.passed || this.parent === null) && counters.totalFailed > 0) {
@@ -634,13 +642,13 @@ class Test extends AsyncResource {
634642
this.parent.processPendingSubtests();
635643
} else if (!this.reported) {
636644
this.reported = true;
637-
this.reporter.plan(this.nesting, kFilename, this.subtests.length);
645+
this.reporter.plan(this.nesting, kFilename, counters.all);
638646

639647
for (let i = 0; i < this.diagnostics.length; i++) {
640648
this.reporter.diagnostic(this.nesting, kFilename, this.diagnostics[i]);
641649
}
642650

643-
this.reporter.diagnostic(this.nesting, kFilename, `tests ${this.subtests.length}`);
651+
this.reporter.diagnostic(this.nesting, kFilename, `tests ${counters.all}`);
644652
this.reporter.diagnostic(this.nesting, kFilename, `pass ${counters.passed}`);
645653
this.reporter.diagnostic(this.nesting, kFilename, `fail ${counters.failed}`);
646654
this.reporter.diagnostic(this.nesting, kFilename, `cancelled ${counters.cancelled}`);
@@ -825,6 +833,8 @@ module.exports = {
825833
kCancelledByParent,
826834
kSubtestsFailed,
827835
kTestCodeFailure,
836+
kTestTimeoutFailure,
837+
kAborted,
828838
kUnwrapErrors,
829839
Suite,
830840
Test,

test/message/test_runner_abort.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ TAP version 13
4040
not ok 7 - not ok 3
4141
---
4242
duration_ms: *
43+
failureType: 'testAborted'
4344
error: 'This operation was aborted'
4445
code: 20
4546
stack: |-
@@ -58,6 +59,7 @@ TAP version 13
5859
not ok 8 - not ok 4
5960
---
6061
duration_ms: *
62+
failureType: 'testAborted'
6163
error: 'This operation was aborted'
6264
code: 20
6365
stack: |-
@@ -76,6 +78,7 @@ TAP version 13
7678
not ok 9 - not ok 5
7779
---
7880
duration_ms: *
81+
failureType: 'testAborted'
7982
error: 'This operation was aborted'
8083
code: 20
8184
stack: |-
@@ -94,6 +97,7 @@ TAP version 13
9497
not ok 1 - promise timeout signal
9598
---
9699
duration_ms: *
100+
failureType: 'testAborted'
97101
error: 'The operation was aborted due to timeout'
98102
code: 23
99103
stack: |-
@@ -106,6 +110,7 @@ not ok 1 - promise timeout signal
106110
not ok 2 - promise abort signal
107111
---
108112
duration_ms: *
113+
failureType: 'testAborted'
109114
error: 'This operation was aborted'
110115
code: 20
111116
stack: |-
@@ -160,6 +165,7 @@ not ok 2 - promise abort signal
160165
not ok 7 - not ok 3
161166
---
162167
duration_ms: *
168+
failureType: 'testAborted'
163169
error: 'This operation was aborted'
164170
code: 20
165171
stack: |-
@@ -178,6 +184,7 @@ not ok 2 - promise abort signal
178184
not ok 8 - not ok 4
179185
---
180186
duration_ms: *
187+
failureType: 'testAborted'
181188
error: 'This operation was aborted'
182189
code: 20
183190
stack: |-
@@ -196,6 +203,7 @@ not ok 2 - promise abort signal
196203
not ok 9 - not ok 5
197204
---
198205
duration_ms: *
206+
failureType: 'testAborted'
199207
error: 'This operation was aborted'
200208
code: 20
201209
stack: |-
@@ -214,6 +222,7 @@ not ok 2 - promise abort signal
214222
not ok 3 - callback timeout signal
215223
---
216224
duration_ms: *
225+
failureType: 'testAborted'
217226
error: 'The operation was aborted due to timeout'
218227
code: 23
219228
stack: |-
@@ -226,6 +235,7 @@ not ok 3 - callback timeout signal
226235
not ok 4 - callback abort signal
227236
---
228237
duration_ms: *
238+
failureType: 'testAborted'
229239
error: 'This operation was aborted'
230240
code: 20
231241
stack: |-

test/message/test_runner_abort_suite.out

Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)