@@ -16,12 +16,13 @@ const {
1616const { exitCodes : { kGenericUserError } } = internalBinding ( 'errors' ) ;
1717
1818const { kEmptyObject } = require ( 'internal/util' ) ;
19- const { getOptionValue } = require ( 'internal/options' ) ;
2019const { kCancelledByParent, Test, ItTest, Suite } = require ( 'internal/test_runner/test' ) ;
21- const { setupTestReporters } = require ( 'internal/test_runner/utils' ) ;
20+ const {
21+ parseCommandLine,
22+ setupTestReporters,
23+ } = require ( 'internal/test_runner/utils' ) ;
2224const { bigint : hrtime } = process . hrtime ;
2325
24- const isTestRunnerCli = getOptionValue ( '--test' ) ;
2526const testResources = new SafeMap ( ) ;
2627const wasRootSetup = new SafeWeakSet ( ) ;
2728
@@ -56,8 +57,8 @@ function createProcessEventHandler(eventName, rootTest) {
5657 } ;
5758}
5859
59- function configureCoverage ( rootTest ) {
60- if ( ! getOptionValue ( '--experimental-test- coverage' ) ) {
60+ function configureCoverage ( rootTest , globalOptions ) {
61+ if ( ! globalOptions . coverage ) {
6162 return null ;
6263 }
6364
@@ -98,6 +99,11 @@ function setup(root) {
9899 if ( wasRootSetup . has ( root ) ) {
99100 return root ;
100101 }
102+
103+ // Parse the command line options before the hook is enabled. We don't want
104+ // global input validation errors to end up in the uncaughtException handler.
105+ const globalOptions = parseCommandLine ( ) ;
106+
101107 const hook = createHook ( {
102108 init ( asyncId , type , triggerAsyncId , resource ) {
103109 if ( resource instanceof Test ) {
@@ -122,7 +128,7 @@ function setup(root) {
122128 createProcessEventHandler ( 'uncaughtException' , root ) ;
123129 const rejectionHandler =
124130 createProcessEventHandler ( 'unhandledRejection' , root ) ;
125- const coverage = configureCoverage ( root ) ;
131+ const coverage = configureCoverage ( root , globalOptions ) ;
126132 const exitHandler = ( ) => {
127133 root . coverage = collectCoverage ( root , coverage ) ;
128134 root . postRun ( new ERR_TEST_FAILURE (
@@ -142,8 +148,8 @@ function setup(root) {
142148 process . on ( 'uncaughtException' , exceptionHandler ) ;
143149 process . on ( 'unhandledRejection' , rejectionHandler ) ;
144150 process . on ( 'beforeExit' , exitHandler ) ;
145- // TODO(MoLow): Make it configurable to hook when isTestRunnerCli === false.
146- if ( isTestRunnerCli ) {
151+ // TODO(MoLow): Make it configurable to hook when isTestRunner === false.
152+ if ( globalOptions . isTestRunner ) {
147153 process . on ( 'SIGINT' , terminationHandler ) ;
148154 process . on ( 'SIGTERM' , terminationHandler ) ;
149155 }
0 commit comments