Skip to content

Commit

Permalink
Load mocha.opts in _mocha for now (close #1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
travisjeffery committed Apr 8, 2015
1 parent 1ecda1d commit 3a71858
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 30 deletions.
25 changes: 15 additions & 10 deletions bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
* Module dependencies.
*/

var program = require('commander')
, path = require('path')
, fs = require('fs')
, resolve = path.resolve
, exists = fs.existsSync || path.existsSync
, Mocha = require('../')
, utils = Mocha.utils
, join = path.join
, cwd = process.cwd()
, mocha = new Mocha;
var program = require('commander'),
path = require('path'),
fs = require('fs'),
resolve = path.resolve,
exists = fs.existsSync || path.existsSync,
Mocha = require('../'),
utils = Mocha.utils,
join = path.join,
cwd = process.cwd(),
getOptions = require('./options'),
mocha = new Mocha;

/**
* Save timer references to avoid Sinon interfering (see GH-237).
Expand Down Expand Up @@ -175,6 +176,10 @@ program.on('require', function(mod){
requires.push(mod);
});

// load mocha.opts into process.argv

getOptions();

// parse args

program.parse(process.argv);
Expand Down
24 changes: 4 additions & 20 deletions bin/mocha
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,12 @@
var spawn = require('child_process').spawn,
path = require('path'),
fs = require('fs'),
args = [path.join(__dirname, '_mocha')];
args = [path.join(__dirname, '_mocha')],
getOptions = require('./options');

// --opts
// load mocha.opts into process.argv

var optsPath = process.argv.indexOf('--opts') !== -1
? process.argv[process.argv.indexOf('--opts') + 1]
: 'test/mocha.opts';

try {
var opts = fs.readFileSync(optsPath, 'utf8')
.trim()
.split(/\s+/)
.filter(function(value) {
return value ? true : false;
});

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

process.argv.slice(2).forEach(function(arg){
var flag = arg.split('=')[0];
Expand Down
36 changes: 36 additions & 0 deletions bin/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Dependencies.
*/

var fs = require('fs');

/**
* Export `getOptions`.
*/

module.exports = getOptions;

/**
* Get options.
*/

function getOptions() {
var optsPath = process.argv.indexOf('--opts') !== -1
? process.argv[process.argv.indexOf('--opts') + 1]
: 'test/mocha.opts';

try {
var opts = fs.readFileSync(optsPath, 'utf8')
.trim()
.split(/\s+/)
.filter(function(value) {
return value ? true : false;
});

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

0 comments on commit 3a71858

Please sign in to comment.