Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Load mocha.opts in _mocha for now (close #1645)

Travis Jeffery3a718587115a
diff --git a/bin/_mocha b/bin/_mocha
index e0e50a6f..5b3c0c5b 100755
--- a/bin/_mocha
+++ b/bin/_mocha
@@ -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).
@@ -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);
diff --git a/bin/mocha b/bin/mocha
index a88de857..daa8fd91 100755
--- a/bin/mocha
+++ b/bin/mocha
@@ -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];
diff --git a/bin/options.js b/bin/options.js
new file mode 100644
index 00000000..3b31798b
--- /dev/null
+++ b/bin/options.js
@@ -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
+ }
+}