tools: only add test reporter args when node:test is used

If the test does not use node:test, don't append the unnecessary
arguments to avoid cluttering the command line printed by the
test runner when the test fails.

PR-URL: https://github.com/nodejs/node/pull/60551
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Joyee Cheung 2025-11-04 16:34:35 +01:00 committed by Antoine du Hamel
parent 6e1b23dab8
commit ae91a6cc3a
No known key found for this signature in database
GPG Key ID: 20B1A390B168D356
2 changed files with 10 additions and 5 deletions

View File

@ -35,6 +35,7 @@ from io import open
FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
LS_RE = re.compile(r'^test-.*\.m?js$')
ENV_PATTERN = re.compile(r"//\s+Env:(.*)")
NODE_TEST_PATTERN = re.compile(r"('|`|\")node:test\1")
class SimpleTestCase(test.TestCase):
@ -98,6 +99,10 @@ class SimpleTestCase(test.TestCase):
else:
result += flags
if self.context.use_error_reporter and NODE_TEST_PATTERN.search(source):
result += ['--test-reporter=./test/common/test-error-reporter.js',
'--test-reporter-destination=stdout']
if self.additional_flags:
result += self.additional_flags

View File

@ -969,6 +969,7 @@ class Context(object):
self.abort_on_timeout = abort_on_timeout
self.v8_enable_inspector = True
self.node_has_crypto = True
self.use_error_reporter = False
def GetVm(self, arch, mode):
if self.vm is not None:
@ -1461,7 +1462,7 @@ def BuildOptions():
help="Type of build (simple, fips, coverage)",
default=None)
result.add_argument("--error-reporter",
help="use error reporter",
help="use error reporter if the test uses node:test",
default=True, action="store_true")
return result
@ -1679,10 +1680,6 @@ def Main():
options.node_args.append("--trace-file-names")
options.progress = "deopts"
if options.error_reporter:
options.node_args.append('--test-reporter=./test/common/test-error-reporter.js')
options.node_args.append('--test-reporter-destination=stdout')
if options.worker:
run_worker = join(workspace, "tools", "run-worker.js")
options.node_args.append(run_worker)
@ -1701,6 +1698,9 @@ def Main():
options.repeat,
options.abort_on_timeout)
if options.error_reporter:
context.use_error_reporter = True
# Get status for tests
sections = [ ]
defs = { }