Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Print colored output only to a tty

Jonas Dohse3bc92dead7e7
diff --git a/lib/mocha.js b/lib/mocha.js
index 73bdaf97..0835ba50 100644
--- a/lib/mocha.js
+++ b/lib/mocha.js
@@ -297,9 +297,9 @@ Mocha.prototype.globals = function(globals){
*/
Mocha.prototype.useColors = function(colors){
- this.options.useColors = arguments.length && colors != undefined
- ? colors
- : true;
+ if (colors !== undefined) {
+ this.options.useColors = colors;
+ }
return this;
};
@@ -401,7 +401,9 @@ 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;
+ if (options.useColors !== undefined) {
+ exports.reporters.Base.useColors = options.useColors;
+ }
exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
return runner.run(fn);
};
diff --git a/test/color.js b/test/color.js
new file mode 100644
index 00000000..8c7167b0
--- /dev/null
+++ b/test/color.js
@@ -0,0 +1,17 @@
+var assert = require('assert');
+var child_process = require('child_process');
+
+describe('Mocha', function() {
+ this.timeout(1000);
+
+ it('should not output colors to pipe', function(cb) {
+ var command = 'bin/mocha --grep missing-test';
+ child_process.exec(command, function(err, stdout, stderr) {
+ if (err) return cb(err);
+
+ assert(stdout.indexOf('[90m') === -1);
+
+ cb(null);
+ });
+ });
+});