Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not fork if no node flags present #3827

Merged
merged 2 commits into from Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 32 additions & 26 deletions bin/mocha
Expand Up @@ -3,14 +3,14 @@
'use strict';

/**
* This wrapper executable checks for known node flags and appends them when found, before invoking the "real" _mocha(1) executable.
* This wrapper executable checks for known node flags and appends them when found,
* before invoking the "real" executable (`lib/cli/cli.js`)
*
* @module bin/mocha
* @private
*/

const {deprecate, warn} = require('../lib/utils');
const {spawn} = require('child_process');
const {loadOptions} = require('../lib/cli/options');
const {
unparseNodeFlags,
Expand All @@ -22,7 +22,6 @@ const debug = require('debug')('mocha:cli:mocha');
const {aliases} = require('../lib/cli/run-option-metadata');
const nodeEnv = require('node-environment-flags');

const mochaPath = require.resolve('./_mocha');
const mochaArgs = {};
const nodeArgs = {};

Expand Down Expand Up @@ -118,32 +117,39 @@ if (nodeArgs.gc) {
delete nodeArgs.gc;
}

debug('final node args', nodeArgs);
if (Object.keys(nodeArgs).length) {
boneskull marked this conversation as resolved.
Show resolved Hide resolved
const {spawn} = require('child_process');
const mochaPath = require.resolve('../lib/cli/cli.js');
juergba marked this conversation as resolved.
Show resolved Hide resolved

const args = [].concat(
unparseNodeFlags(nodeArgs),
mochaPath,
unparse(mochaArgs, {alias: aliases})
);
debug('final node args', nodeArgs);

debug(`exec ${process.execPath} w/ args:`, args);
const args = [].concat(
unparseNodeFlags(nodeArgs),
mochaPath,
unparse(mochaArgs, {alias: aliases})
);

const proc = spawn(process.execPath, args, {
stdio: 'inherit'
});
debug(`exec ${process.execPath} w/ args:`, args);

boneskull marked this conversation as resolved.
Show resolved Hide resolved
proc.on('exit', (code, signal) => {
process.on('exit', () => {
if (signal) {
process.kill(process.pid, signal);
} else {
process.exit(code);
}
const proc = spawn(process.execPath, args, {
stdio: 'inherit'
});
});

// 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.
});
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.
});
} else {
require('../lib/cli/cli').main(unparse(mochaArgs, {alias: aliases}));
juergba marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 2 additions & 0 deletions lib/cli/cli.js
@@ -1,3 +1,5 @@
#!/usr/bin/env node

'use strict';

/**
Expand Down