From c5f16fb5fb441a5ae851b4d2fdcc5c22b7b4c530 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta Date: Thu, 2 Feb 2023 16:12:43 +0530 Subject: [PATCH] test_runner: top-level diagnostics not ommited when running with --test PR-URL: https://github.com/nodejs/node/pull/46441 Backport-PR-URL: https://github.com/nodejs/node/pull/46839 Fixes: https://github.com/nodejs/node/issues/45910 Reviewed-By: Moshe Atlow Reviewed-By: Benjamin Gruenbaum Reviewed-By: Antoine du Hamel --- lib/internal/test_runner/runner.js | 12 +++++++++++- test/message/test_runner_output_cli.out | 6 ++++++ test/message/test_runner_output_spec_reporter.out | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index bafffc218ced75..875cc4247262c4 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -15,6 +15,8 @@ const { SafePromiseAllSettledReturnVoid, SafeMap, SafeSet, + StringPrototypeIndexOf, + StringPrototypeSlice, StringPrototypeStartsWith, } = primordials; @@ -50,6 +52,7 @@ const { const kFilterArgs = ['--test', '--experimental-test-coverage', '--watch']; 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) { @@ -129,6 +132,13 @@ 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; @@ -182,7 +192,7 @@ class FileTest extends Test { break; case TokenKind.COMMENT: - if (nesting === 1) { + if (nesting === 1 && this.#checkNestedComment(node)) { // Ignore file top level diagnostics break; } diff --git a/test/message/test_runner_output_cli.out b/test/message/test_runner_output_cli.out index a8e2f2c5b586f4..525f8db3c885e3 100644 --- a/test/message/test_runner_output_cli.out +++ b/test/message/test_runner_output_cli.out @@ -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: * diff --git a/test/message/test_runner_output_spec_reporter.out b/test/message/test_runner_output_spec_reporter.out index f7e2b7e66d800a..cf47c7ac7e33ff 100644 --- a/test/message/test_runner_output_spec_reporter.out +++ b/test/message/test_runner_output_spec_reporter.out @@ -58,9 +58,9 @@ async assertion fail (*ms) AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: - + true !== false - + * * *