Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Mocha options include useColors, plus setter

Roman Neuhauser805c95d2e6ec
diff --git a/bin/_mocha b/bin/_mocha
index 90709373..0244de02 100644
--- a/bin/_mocha
+++ b/bin/_mocha
@@ -13,9 +13,7 @@ var program = require('commander')
, exists = fs.existsSync || path.existsSync
, Mocha = require('../')
, utils = Mocha.utils
- , reporters = Mocha.reporters
, interfaces = Mocha.interfaces
- , Base = reporters.Base
, join = path.join
, basename = path.basename
, cwd = process.cwd()
@@ -202,13 +200,13 @@ try {
// --no-colors
-if (!program.colors) Base.useColors = false;
+if (!program.colors) mocha.useColors(false);
// --colors
if (~process.argv.indexOf('--colors') ||
~process.argv.indexOf('-c')) {
- Base.useColors = true;
+ mocha.useColors(true);
}
// --inline-diffs
diff --git a/lib/mocha.js b/lib/mocha.js
index e972cc43..62e2ecbc 100644
--- a/lib/mocha.js
+++ b/lib/mocha.js
@@ -71,6 +71,7 @@ function Mocha(options) {
this.bail(options.bail);
this.reporter(options.reporter);
if (null != options.timeout) this.timeout(options.timeout);
+ this.useColors(options.useColors)
if (options.slow) this.slow(options.slow);
}
@@ -259,6 +260,21 @@ Mocha.prototype.globals = function(globals){
return this;
};
+/**
+ * Emit color output.
+ *
+ * @param {Boolean} colors
+ * @return {Mocha}
+ * @api public
+ */
+
+Mocha.prototype.useColors = function(colors){
+ this.options.useColors = arguments.length && colors != undefined
+ ? colors
+ : true;
+ return this;
+};
+
/**
* Set the timeout in milliseconds.
*
@@ -316,5 +332,6 @@ Mocha.prototype.run = function(fn){
if (options.grep) runner.grep(options.grep, options.invert);
if (options.globals) runner.globals(options.globals);
if (options.growl) this._growl(runner, reporter);
+ exports.reporters.Base.useColors = options.useColors;
return runner.run(fn);
};