3
3
'use strict' ;
4
4
5
5
/**
6
- * This wrapper executable checks for known node flags and appends them when found, before invoking the "real" _mocha(1) executable.
6
+ * This wrapper executable checks for known node flags and appends them when found,
7
+ * before invoking the "real" executable (`lib/cli/cli.js`)
7
8
*
8
9
* @module bin/mocha
9
10
* @private
10
11
*/
11
12
12
13
const { deprecate, warn} = require ( '../lib/utils' ) ;
13
- const { spawn} = require ( 'child_process' ) ;
14
14
const { loadOptions} = require ( '../lib/cli/options' ) ;
15
15
const {
16
16
unparseNodeFlags,
@@ -22,7 +22,6 @@ const debug = require('debug')('mocha:cli:mocha');
22
22
const { aliases} = require ( '../lib/cli/run-option-metadata' ) ;
23
23
const nodeEnv = require ( 'node-environment-flags' ) ;
24
24
25
- const mochaPath = require . resolve ( './_mocha' ) ;
26
25
const mochaArgs = { } ;
27
26
const nodeArgs = { } ;
28
27
@@ -118,32 +117,39 @@ if (nodeArgs.gc) {
118
117
delete nodeArgs . gc ;
119
118
}
120
119
121
- debug ( 'final node args' , nodeArgs ) ;
120
+ if ( Object . keys ( nodeArgs ) . length ) {
121
+ const { spawn} = require ( 'child_process' ) ;
122
+ const mochaPath = require . resolve ( '../lib/cli/cli.js' ) ;
122
123
123
- const args = [ ] . concat (
124
- unparseNodeFlags ( nodeArgs ) ,
125
- mochaPath ,
126
- unparse ( mochaArgs , { alias : aliases } )
127
- ) ;
124
+ debug ( 'final node args' , nodeArgs ) ;
128
125
129
- debug ( `exec ${ process . execPath } w/ args:` , args ) ;
126
+ const args = [ ] . concat (
127
+ unparseNodeFlags ( nodeArgs ) ,
128
+ mochaPath ,
129
+ unparse ( mochaArgs , { alias : aliases } )
130
+ ) ;
130
131
131
- const proc = spawn ( process . execPath , args , {
132
- stdio : 'inherit'
133
- } ) ;
132
+ debug ( `exec ${ process . execPath } w/ args:` , args ) ;
134
133
135
- proc . on ( 'exit' , ( code , signal ) => {
136
- process . on ( 'exit' , ( ) => {
137
- if ( signal ) {
138
- process . kill ( process . pid , signal ) ;
139
- } else {
140
- process . exit ( code ) ;
141
- }
134
+ const proc = spawn ( process . execPath , args , {
135
+ stdio : 'inherit'
142
136
} ) ;
143
- } ) ;
144
137
145
- // terminate children.
146
- process . on ( 'SIGINT' , ( ) => {
147
- proc . kill ( 'SIGINT' ) ; // calls runner.abort()
148
- proc . kill ( 'SIGTERM' ) ; // if that didn't work, we're probably in an infinite loop, so make it die.
149
- } ) ;
138
+ proc . on ( 'exit' , ( code , signal ) => {
139
+ process . on ( 'exit' , ( ) => {
140
+ if ( signal ) {
141
+ process . kill ( process . pid , signal ) ;
142
+ } else {
143
+ process . exit ( code ) ;
144
+ }
145
+ } ) ;
146
+ } ) ;
147
+
148
+ // terminate children.
149
+ process . on ( 'SIGINT' , ( ) => {
150
+ proc . kill ( 'SIGINT' ) ; // calls runner.abort()
151
+ proc . kill ( 'SIGTERM' ) ; // if that didn't work, we're probably in an infinite loop, so make it die.
152
+ } ) ;
153
+ } else {
154
+ require ( '../lib/cli/cli' ) . main ( unparse ( mochaArgs , { alias : aliases } ) ) ;
155
+ }
0 commit comments