Skip to content

Commit d6f071a

Browse files
pulkit-30MoLow
authored andcommitted
fix: top-level diagnostics not ommited when running with --test
PR-URL: nodejs/node#46441 Fixes: nodejs/node#45910 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> (cherry picked from commit 61c65b066b098cf47f89206212864ec1cddb8782)
1 parent 69e4f83 commit d6f071a

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

Diff for: lib/internal/per_context/primordials.js

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ exports.SafeWeakSet = WeakSet
6565
exports.String = String
6666
exports.StringPrototypeEndsWith = (haystack, needle, index) => haystack.endsWith(needle, index)
6767
exports.StringPrototypeIncludes = (str, needle) => str.includes(needle)
68+
exports.StringPrototypeIndexOf = (str, needle, offset) => str.indexOf(needle, offset)
6869
exports.StringPrototypeMatch = (str, reg) => str.match(reg)
6970
exports.StringPrototypeRepeat = (str, times) => str.repeat(times)
7071
exports.StringPrototypeReplace = (str, search, replacement) =>

Diff for: lib/internal/test_runner/runner.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/nodejs/node/blob/9eb363a3e00dbba572756c7ed314273f17ea8e2e/lib/internal/test_runner/runner.js
1+
// https://github.com/nodejs/node/blob/61c65b066b098cf47f89206212864ec1cddb8782/lib/internal/test_runner/runner.js
22
'use strict'
33
const {
44
ArrayFrom,
@@ -13,6 +13,8 @@ const {
1313
PromisePrototypeThen,
1414
SafePromiseAll,
1515
SafeSet,
16+
StringPrototypeIndexOf,
17+
StringPrototypeSlice,
1618
StringPrototypeStartsWith
1719
} = require('#internal/per_context/primordials')
1820

@@ -43,6 +45,7 @@ const { once } = require('events')
4345

4446
const kFilterArgs = ['--test']
4547
const kFilterArgValues = ['--test-reporter', '--test-reporter-destination']
48+
const kDiagnosticsFilterArgs = ['tests', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms']
4649

4750
// TODO(cjihrig): Replace this with recursive readdir once it lands.
4851
function processPath (path, testFiles, options) {
@@ -123,6 +126,14 @@ function getRunArgs ({ path, inspectPort }) {
123126

124127
class FileTest extends Test {
125128
#buffer = []
129+
#checkNestedComment ({ comment }) {
130+
const firstSpaceIndex = StringPrototypeIndexOf(comment, ' ')
131+
if (firstSpaceIndex === -1) return false
132+
const secondSpaceIndex = StringPrototypeIndexOf(comment, ' ', firstSpaceIndex + 1)
133+
return secondSpaceIndex === -1 &&
134+
ArrayPrototypeIncludes(kDiagnosticsFilterArgs, StringPrototypeSlice(comment, 0, firstSpaceIndex))
135+
}
136+
126137
#handleReportItem ({ kind, node, nesting = 0 }) {
127138
nesting += 1
128139

@@ -176,7 +187,7 @@ class FileTest extends Test {
176187
break
177188

178189
case TokenKind.COMMENT:
179-
if (nesting === 1) {
190+
if (nesting === 1 && this.#checkNestedComment(node)) {
180191
// Ignore file top level diagnostics
181192
break
182193
}

Diff for: 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: *

Diff for: test/message/test_runner_output_spec_reporter.out

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ sync pass todo (*ms)
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)