Skip to content

Commit

Permalink
test_runner: top-level diagnostics not ommited when running with --test
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node#46441
Fixes: nodejs/node#45910
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
(cherry picked from commit 61c65b066b098cf47f89206212864ec1cddb8782)
  • Loading branch information
pulkit-30 authored and MoLow committed Feb 7, 2023
1 parent dfca2fd commit 29d5a24
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ exports.SafeWeakSet = WeakSet
exports.String = String
exports.StringPrototypeEndsWith = (haystack, needle, index) => haystack.endsWith(needle, index)
exports.StringPrototypeIncludes = (str, needle) => str.includes(needle)
exports.StringPrototypeIndexOf = (str, needle, offset) => str.indexOf(needle, offset)
exports.StringPrototypeMatch = (str, reg) => str.match(reg)
exports.StringPrototypeRepeat = (str, times) => str.repeat(times)
exports.StringPrototypeReplace = (str, search, replacement) =>
Expand Down
15 changes: 13 additions & 2 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/9eb363a3e00dbba572756c7ed314273f17ea8e2e/lib/internal/test_runner/runner.js
// https://github.com/nodejs/node/blob/61c65b066b098cf47f89206212864ec1cddb8782/lib/internal/test_runner/runner.js
'use strict'
const {
ArrayFrom,
Expand All @@ -13,6 +13,8 @@ const {
PromisePrototypeThen,
SafePromiseAll,
SafeSet,
StringPrototypeIndexOf,
StringPrototypeSlice,
StringPrototypeStartsWith
} = require('#internal/per_context/primordials')

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

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

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

class FileTest extends Test {
#buffer = []
#checkNestedComment ({ comment }) {
const firstSpaceIndex = StringPrototypeIndexOf(comment, ' ')
if (firstSpaceIndex === -1) return false
const secondSpaceIndex = StringPrototypeIndexOf(comment, ' ', firstSpaceIndex + 1)
return secondSpaceIndex === -1 &&
ArrayPrototypeIncludes(kDiagnosticsFilterArgs, StringPrototypeSlice(comment, 0, firstSpaceIndex))
}

#handleReportItem ({ kind, node, nesting = 0 }) {
nesting += 1

Expand Down Expand Up @@ -176,7 +187,7 @@ class FileTest extends Test {
break

case TokenKind.COMMENT:
if (nesting === 1) {
if (nesting === 1 && this.#checkNestedComment(node)) {
// Ignore file top level diagnostics
break
}
Expand Down
6 changes: 6 additions & 0 deletions test/message/test_runner_output_cli.out
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ TAP version 13
*
...
1..65
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
not ok 1 - *test_runner_output.js
---
duration_ms: *
Expand Down
4 changes: 2 additions & 2 deletions test/message/test_runner_output_spec_reporter.out
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ sync pass todo (*ms)
*
async assertion fail (*ms)
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

true !== false

*
*
*
Expand Down

0 comments on commit 29d5a24

Please sign in to comment.