10
10
* @private
11
11
*/
12
12
13
- const { deprecate} = require ( '../lib/utils' ) ;
14
13
const { loadOptions} = require ( '../lib/cli/options' ) ;
15
14
const {
16
15
unparseNodeFlags,
@@ -23,6 +22,7 @@ const {aliases} = require('../lib/cli/run-option-metadata');
23
22
24
23
const mochaArgs = { } ;
25
24
const nodeArgs = { } ;
25
+ let hasInspect = false ;
26
26
27
27
const opts = loadOptions ( process . argv . slice ( 2 ) ) ;
28
28
debug ( 'loaded opts' , opts ) ;
@@ -59,48 +59,39 @@ Object.keys(opts).forEach(opt => {
59
59
60
60
// disable 'timeout' for debugFlags
61
61
Object . keys ( nodeArgs ) . forEach ( opt => disableTimeouts ( opt ) ) ;
62
+ mochaArgs [ 'node-option' ] &&
63
+ mochaArgs [ 'node-option' ] . forEach ( opt => disableTimeouts ( opt ) ) ;
62
64
63
65
// Native debugger handling
64
66
// see https://nodejs.org/api/debugger.html#debugger_debugger
65
- // look for 'inspect' or 'debug' that would launch this debugger,
67
+ // look for 'inspect' that would launch this debugger,
66
68
// remove it from Mocha's opts and prepend it to Node's opts.
67
69
// A deprecation warning will be printed by node, if applicable.
68
70
// (mochaArgs._ are "positional" arguments, not prefixed with - or --)
69
71
if ( mochaArgs . _ ) {
70
- const i = mochaArgs . _ . findIndex ( val => val === 'inspect' || val === 'debug' ) ;
72
+ const i = mochaArgs . _ . findIndex ( val => val === 'inspect' ) ;
71
73
if ( i > - 1 ) {
72
- const [ command ] = mochaArgs . _ . splice ( i , 1 ) ;
74
+ mochaArgs . _ . splice ( i , 1 ) ;
73
75
disableTimeouts ( 'inspect' ) ;
74
- nodeArgs . _ = [ command ] ;
76
+ hasInspect = true ;
75
77
}
76
78
}
77
79
78
- // historical
79
- if ( nodeArgs . gc ) {
80
- deprecate (
81
- '"-gc" is deprecated and will be removed from a future version of Mocha. Use "--gc-global" instead.'
82
- ) ;
83
- nodeArgs [ 'gc-global' ] = nodeArgs . gc ;
84
- delete nodeArgs . gc ;
85
- }
86
-
87
- // --require/-r is treated as Mocha flag except when 'esm' is preloaded
88
- if ( mochaArgs . require && mochaArgs . require . includes ( 'esm' ) ) {
89
- nodeArgs . require = [ 'esm' ] ;
90
- mochaArgs . require = mochaArgs . require . filter ( mod => mod !== 'esm' ) ;
91
- if ( ! mochaArgs . require . length ) {
92
- delete mochaArgs . require ;
93
- }
94
- }
95
-
96
- if ( Object . keys ( nodeArgs ) . length ) {
80
+ if ( mochaArgs [ 'node-option' ] || Object . keys ( nodeArgs ) . length || hasInspect ) {
97
81
const { spawn} = require ( 'child_process' ) ;
98
82
const mochaPath = require . resolve ( '../lib/cli/cli.js' ) ;
99
83
100
- debug ( 'final node args' , nodeArgs ) ;
84
+ const nodeArgv =
85
+ ( mochaArgs [ 'node-option' ] && mochaArgs [ 'node-option' ] . map ( v => '--' + v ) ) ||
86
+ unparseNodeFlags ( nodeArgs ) ;
87
+
88
+ if ( hasInspect ) nodeArgv . unshift ( 'inspect' ) ;
89
+ delete mochaArgs [ 'node-option' ] ;
90
+
91
+ debug ( 'final node argv' , nodeArgv ) ;
101
92
102
93
const args = [ ] . concat (
103
- unparseNodeFlags ( nodeArgs ) ,
94
+ nodeArgv ,
104
95
mochaPath ,
105
96
unparse ( mochaArgs , { alias : aliases } )
106
97
) ;
@@ -147,5 +138,5 @@ if (Object.keys(nodeArgs).length) {
147
138
} ) ;
148
139
} else {
149
140
debug ( 'running Mocha in-process' ) ;
150
- require ( '../lib/cli/cli' ) . main ( unparse ( mochaArgs , { alias : aliases } ) ) ;
141
+ require ( '../lib/cli/cli' ) . main ( [ ] , mochaArgs ) ;
151
142
}
0 commit comments