Repository: nodejs/node
Pull request: 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.

<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->


Changed files:
filename: test/testpy/__init__.py
patch: @@ -35,6 +35,7 @@
 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 @@ def GetRunConfiguration(self):
       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
 

filename: tools/test.py
patch: @@ -969,6 +969,7 @@ def __init__(self, workspace, verbose, vm, args, expect_fail,
     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 = { }