From 96efa24b22745ee94eaf6ed6a659f3c9c69947c0 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Mon, 11 Mar 2019 12:10:52 -0700 Subject: [PATCH] do not fork if no node flags present --- bin/mocha | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/bin/mocha b/bin/mocha index cec93a3366..696c883023 100755 --- a/bin/mocha +++ b/bin/mocha @@ -120,30 +120,34 @@ if (nodeArgs.gc) { debug('final node args', nodeArgs); -const args = [].concat( - unparseNodeFlags(nodeArgs), - mochaPath, - unparse(mochaArgs, {alias: aliases}) -); +if (Object.keys(nodeArgs).length) { + const args = [].concat( + unparseNodeFlags(nodeArgs), + mochaPath, + unparse(mochaArgs, {alias: aliases}) + ); -debug(`exec ${process.execPath} w/ args:`, args); + debug(`exec ${process.execPath} w/ args:`, args); -const proc = spawn(process.execPath, args, { - stdio: 'inherit' -}); + const proc = spawn(process.execPath, args, { + stdio: 'inherit' + }); -proc.on('exit', (code, signal) => { - process.on('exit', () => { - if (signal) { - process.kill(process.pid, signal); - } else { - process.exit(code); - } + proc.on('exit', (code, signal) => { + process.on('exit', () => { + if (signal) { + process.kill(process.pid, signal); + } else { + process.exit(code); + } + }); }); -}); -// terminate children. -process.on('SIGINT', () => { - proc.kill('SIGINT'); // calls runner.abort() - proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die. -}); + // terminate children. + process.on('SIGINT', () => { + proc.kill('SIGINT'); // calls runner.abort() + proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die. + }); +} else { + require('../lib/cli/cli').main(unparse(mochaArgs, {alias: aliases})); +}