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

respect --expose-gc from mocha.opts #394

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ program
.option('-d, --debug', "enable node's debugger, synonym for node --debug")
.option('-b, --bail', "bail after first test failure")
.option('--debug-brk', "enable node's debugger breaking on the first line")
.option('--expose-gc', "expose v8's garbage collector as the gc() function")
.option('--trace-gc', "print one trace line following each v8 garbage collection")
.option('--trace-gc-verbose', "print more details following each v8 garbage collection (must be used with --trace-gc-verbose)")
.option('--globals <names>', 'allow the given comma-delimited global [names]', list, [])
.option('--ignore-leaks', 'ignore global variable leaks')
.option('--interfaces', 'display available interfaces')
Expand Down
26 changes: 24 additions & 2 deletions bin/mocha
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@

/**
* This tiny wrapper file checks for known node flags and appends them
* when found, before invoking the "real" _mocha(1) executable.
* when found, before invoking the "real" _mocha(1) executable. It will
* also respect known node flags set in mocha.opts
*/

var spawn = require('child_process').spawn
, args = [ __dirname + '/_mocha' ];
, args = [ __dirname + '/_mocha' ]
, fs = require('fs');

// mocha.opts support

try {
var opts = fs.readFileSync('test/mocha.opts', 'utf8')
.trim()
.split(/\s+/);

process.argv = process.argv
.slice(0, 2)
.concat(opts.concat(process.argv.slice(2)));
} catch (err) {
// ignore
}

process.argv.slice(2).forEach(function (arg) {
switch (arg) {
Expand All @@ -22,6 +38,12 @@ process.argv.slice(2).forEach(function (arg) {
case '--expose-gc':
args.unshift('--expose-gc');
break;
case '--trace-gc':
args.unshift('--trace-gc');
break;
case '--trace-gc-verbose':
args.unshift('--trace-gc-verbose');
break;
default:
args.push(arg);
break;
Expand Down