Skip to content

Commit c5f16fb

Browse files
pulkit-30juanarbol
authored andcommitted
test_runner: top-level diagnostics not ommited when running with --test
PR-URL: #46441 Backport-PR-URL: #46839 Fixes: #45910 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 32b020c commit c5f16fb

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/internal/test_runner/runner.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const {
1515
SafePromiseAllSettledReturnVoid,
1616
SafeMap,
1717
SafeSet,
18+
StringPrototypeIndexOf,
19+
StringPrototypeSlice,
1820
StringPrototypeStartsWith,
1921
} = primordials;
2022

@@ -50,6 +52,7 @@ const {
5052

5153
const kFilterArgs = ['--test', '--experimental-test-coverage', '--watch'];
5254
const kFilterArgValues = ['--test-reporter', '--test-reporter-destination'];
55+
const kDiagnosticsFilterArgs = ['tests', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms'];
5356

5457
// TODO(cjihrig): Replace this with recursive readdir once it lands.
5558
function processPath(path, testFiles, options) {
@@ -129,6 +132,13 @@ function getRunArgs({ path, inspectPort }) {
129132

130133
class FileTest extends Test {
131134
#buffer = [];
135+
#checkNestedComment({ comment }) {
136+
const firstSpaceIndex = StringPrototypeIndexOf(comment, ' ');
137+
if (firstSpaceIndex === -1) return false;
138+
const secondSpaceIndex = StringPrototypeIndexOf(comment, ' ', firstSpaceIndex + 1);
139+
return secondSpaceIndex === -1 &&
140+
ArrayPrototypeIncludes(kDiagnosticsFilterArgs, StringPrototypeSlice(comment, 0, firstSpaceIndex));
141+
}
132142
#handleReportItem({ kind, node, nesting = 0 }) {
133143
nesting += 1;
134144

@@ -182,7 +192,7 @@ class FileTest extends Test {
182192
break;
183193

184194
case TokenKind.COMMENT:
185-
if (nesting === 1) {
195+
if (nesting === 1 && this.#checkNestedComment(node)) {
186196
// Ignore file top level diagnostics
187197
break;
188198
}

test/message/test_runner_output_cli.out

+6
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,12 @@ TAP version 13
629629
*
630630
...
631631
1..65
632+
# Warning: Test "unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event.
633+
# Warning: Test "async unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from async unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event.
634+
# Warning: Test "immediate throw - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: thrown from immediate throw fail" and would have caused the test to fail, but instead triggered an uncaughtException event.
635+
# Warning: Test "immediate reject - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from immediate reject fail" and would have caused the test to fail, but instead triggered an unhandledRejection event.
636+
# Warning: Test "callback called twice in different ticks" generated asynchronous activity after the test ended. This activity created the error "Error [ERR_TEST_FAILURE]: callback invoked multiple times" and would have caused the test to fail, but instead triggered an uncaughtException event.
637+
# Warning: Test "callback async throw after done" generated asynchronous activity after the test ended. This activity created the error "Error: thrown from callback async throw after done" and would have caused the test to fail, but instead triggered an uncaughtException event.
632638
not ok 1 - *test_runner_output.js
633639
---
634640
duration_ms: *

test/message/test_runner_output_spec_reporter.out

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858

5959
async assertion fail (*ms)
6060
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
61-
61+
6262
true !== false
63-
63+
6464
*
6565
*
6666
*

0 commit comments

Comments
 (0)