@@ -14,12 +14,13 @@ const {
14
14
} ,
15
15
} = require ( 'internal/errors' ) ;
16
16
const { kEmptyObject } = require ( 'internal/util' ) ;
17
- const { getOptionValue } = require ( 'internal/options' ) ;
18
17
const { 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' ) ;
20
22
const { bigint : hrtime } = process . hrtime ;
21
23
22
- const isTestRunnerCli = getOptionValue ( '--test' ) ;
23
24
const testResources = new SafeMap ( ) ;
24
25
const wasRootSetup = new SafeWeakSet ( ) ;
25
26
@@ -54,8 +55,8 @@ function createProcessEventHandler(eventName, rootTest) {
54
55
} ;
55
56
}
56
57
57
- function configureCoverage ( rootTest ) {
58
- if ( ! getOptionValue ( '--experimental-test- coverage' ) ) {
58
+ function configureCoverage ( rootTest , globalOptions ) {
59
+ if ( ! globalOptions . coverage ) {
59
60
return null ;
60
61
}
61
62
@@ -96,6 +97,11 @@ function setup(root) {
96
97
if ( wasRootSetup . has ( root ) ) {
97
98
return root ;
98
99
}
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
+
99
105
const hook = createHook ( {
100
106
init ( asyncId , type , triggerAsyncId , resource ) {
101
107
if ( resource instanceof Test ) {
@@ -120,7 +126,7 @@ function setup(root) {
120
126
createProcessEventHandler ( 'uncaughtException' , root ) ;
121
127
const rejectionHandler =
122
128
createProcessEventHandler ( 'unhandledRejection' , root ) ;
123
- const coverage = configureCoverage ( root ) ;
129
+ const coverage = configureCoverage ( root , globalOptions ) ;
124
130
const exitHandler = ( ) => {
125
131
root . coverage = collectCoverage ( root , coverage ) ;
126
132
root . postRun ( new ERR_TEST_FAILURE (
@@ -140,8 +146,8 @@ function setup(root) {
140
146
process . on ( 'uncaughtException' , exceptionHandler ) ;
141
147
process . on ( 'unhandledRejection' , rejectionHandler ) ;
142
148
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 ) {
145
151
process . on ( 'SIGINT' , terminationHandler ) ;
146
152
process . on ( 'SIGTERM' , terminationHandler ) ;
147
153
}
0 commit comments