@@ -16,12 +16,13 @@ const {
16
16
const { exitCodes : { kGenericUserError } } = internalBinding ( 'errors' ) ;
17
17
18
18
const { kEmptyObject } = require ( 'internal/util' ) ;
19
- const { getOptionValue } = require ( 'internal/options' ) ;
20
19
const { 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' ) ;
22
24
const { bigint : hrtime } = process . hrtime ;
23
25
24
- const isTestRunnerCli = getOptionValue ( '--test' ) ;
25
26
const testResources = new SafeMap ( ) ;
26
27
const wasRootSetup = new SafeWeakSet ( ) ;
27
28
@@ -56,8 +57,8 @@ function createProcessEventHandler(eventName, rootTest) {
56
57
} ;
57
58
}
58
59
59
- function configureCoverage ( rootTest ) {
60
- if ( ! getOptionValue ( '--experimental-test- coverage' ) ) {
60
+ function configureCoverage ( rootTest , globalOptions ) {
61
+ if ( ! globalOptions . coverage ) {
61
62
return null ;
62
63
}
63
64
@@ -98,6 +99,11 @@ function setup(root) {
98
99
if ( wasRootSetup . has ( root ) ) {
99
100
return root ;
100
101
}
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
+
101
107
const hook = createHook ( {
102
108
init ( asyncId , type , triggerAsyncId , resource ) {
103
109
if ( resource instanceof Test ) {
@@ -122,7 +128,7 @@ function setup(root) {
122
128
createProcessEventHandler ( 'uncaughtException' , root ) ;
123
129
const rejectionHandler =
124
130
createProcessEventHandler ( 'unhandledRejection' , root ) ;
125
- const coverage = configureCoverage ( root ) ;
131
+ const coverage = configureCoverage ( root , globalOptions ) ;
126
132
const exitHandler = ( ) => {
127
133
root . coverage = collectCoverage ( root , coverage ) ;
128
134
root . postRun ( new ERR_TEST_FAILURE (
@@ -142,8 +148,8 @@ function setup(root) {
142
148
process . on ( 'uncaughtException' , exceptionHandler ) ;
143
149
process . on ( 'unhandledRejection' , rejectionHandler ) ;
144
150
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 ) {
147
153
process . on ( 'SIGINT' , terminationHandler ) ;
148
154
process . on ( 'SIGTERM' , terminationHandler ) ;
149
155
}
0 commit comments