@@ -14,12 +14,13 @@ const {
1414 } ,
1515} = require ( 'internal/errors' ) ;
1616const { kEmptyObject } = require ( 'internal/util' ) ;
17- const { getOptionValue } = require ( 'internal/options' ) ;
1817const { kCancelledByParent, Test, ItTest, Suite } = require ( 'internal/test_runner/test' ) ;
19- const { setupTestReporters } = require ( 'internal/test_runner/utils' ) ;
18+ const {
19+ parseCommandLine,
20+ setupTestReporters,
21+ } = require ( 'internal/test_runner/utils' ) ;
2022const { bigint : hrtime } = process . hrtime ;
2123
22- const isTestRunnerCli = getOptionValue ( '--test' ) ;
2324const testResources = new SafeMap ( ) ;
2425const wasRootSetup = new SafeWeakSet ( ) ;
2526
@@ -54,8 +55,8 @@ function createProcessEventHandler(eventName, rootTest) {
5455 } ;
5556}
5657
57- function configureCoverage ( rootTest ) {
58- if ( ! getOptionValue ( '--experimental-test- coverage' ) ) {
58+ function configureCoverage ( rootTest , globalOptions ) {
59+ if ( ! globalOptions . coverage ) {
5960 return null ;
6061 }
6162
@@ -96,6 +97,11 @@ function setup(root) {
9697 if ( wasRootSetup . has ( root ) ) {
9798 return root ;
9899 }
100+
101+ // Parse the command line options before the hook is enabled. We don't want
102+ // global input validation errors to end up in the uncaughtException handler.
103+ const globalOptions = parseCommandLine ( ) ;
104+
99105 const hook = createHook ( {
100106 init ( asyncId , type , triggerAsyncId , resource ) {
101107 if ( resource instanceof Test ) {
@@ -120,7 +126,7 @@ function setup(root) {
120126 createProcessEventHandler ( 'uncaughtException' , root ) ;
121127 const rejectionHandler =
122128 createProcessEventHandler ( 'unhandledRejection' , root ) ;
123- const coverage = configureCoverage ( root ) ;
129+ const coverage = configureCoverage ( root , globalOptions ) ;
124130 const exitHandler = ( ) => {
125131 root . coverage = collectCoverage ( root , coverage ) ;
126132 root . postRun ( new ERR_TEST_FAILURE (
@@ -140,8 +146,8 @@ function setup(root) {
140146 process . on ( 'uncaughtException' , exceptionHandler ) ;
141147 process . on ( 'unhandledRejection' , rejectionHandler ) ;
142148 process . on ( 'beforeExit' , exitHandler ) ;
143- // TODO(MoLow): Make it configurable to hook when isTestRunnerCli === false.
144- if ( isTestRunnerCli ) {
149+ // TODO(MoLow): Make it configurable to hook when isTestRunner === false.
150+ if ( globalOptions . isTestRunner ) {
145151 process . on ( 'SIGINT' , terminationHandler ) ;
146152 process . on ( 'SIGTERM' , terminationHandler ) ;
147153 }
0 commit comments