Skip to content

armgit / mocha

Public Imported from GitHub
0

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

disable colors

Craig Taub5cd7c3ed4b64
diff --git a/test/reporters/dot.spec.js b/test/reporters/dot.spec.js
index 2764336a..5576065e 100644
--- a/test/reporters/dot.spec.js
+++ b/test/reporters/dot.spec.js
@@ -2,16 +2,13 @@
var reporters = require('../../').reporters;
var Dot = reporters.Dot;
+var Base = reporters.Base;
describe('Dot reporter', function () {
var stdout;
var stdoutWrite;
var runner;
- var ansiColorCodeReset = '\u001b[0m';
- var ansiColorCodeCyan = '\u001b[36m';
- var ansiColorCodeGrey = '\u001b[90m';
- var ansiColorCodeBrightYellow = '\u001b[93m';
- var ansiColorCodeRed = '\u001b[31m';
+ var useColors;
beforeEach(function () {
stdout = [];
@@ -20,6 +17,12 @@ describe('Dot reporter', function () {
process.stdout.write = function (string) {
stdout.push(string);
};
+ useColors = Base.useColors;
+ Base.useColors = false;
+ });
+
+ afterEach(function () {
+ Base.useColors = useColors;
});
describe('on start', function () {
@@ -38,7 +41,7 @@ describe('Dot reporter', function () {
});
});
describe('on pending', function () {
- it('should return a new line and a coma in the color cyan', function () {
+ it('should return a new line and a coma', function () {
runner.on = function (event, callback) {
if (event === 'pending') {
callback();
@@ -48,14 +51,14 @@ describe('Dot reporter', function () {
process.stdout.write = stdoutWrite;
var expectedArray = [
'\n ',
- ansiColorCodeCyan + ',' + ansiColorCodeReset
+ Base.symbols.comma
];
stdout.should.deepEqual(expectedArray);
});
});
describe('on pass', function () {
describe('if test speed is fast', function () {
- it('should return a new line and a dot in the color grey', function () {
+ it('should return a new line and a dot', function () {
var test = {
duration: 1,
slow: function () { return 2; }
@@ -69,13 +72,13 @@ describe('Dot reporter', function () {
process.stdout.write = stdoutWrite;
var expectedArray = [
'\n ',
- ansiColorCodeGrey + '․' + ansiColorCodeReset
+ Base.symbols.dot
];
stdout.should.deepEqual(expectedArray);
});
});
describe('if test speed is slow', function () {
- it('should return a new line and a dot in the color bright yellow', function () {
+ it('should return a new line and a dot', function () {
var test = {
duration: 2,
slow: function () { return 1; }
@@ -89,14 +92,14 @@ describe('Dot reporter', function () {
process.stdout.write = stdoutWrite;
var expectedArray = [
'\n ',
- ansiColorCodeBrightYellow + '․' + ansiColorCodeReset
+ Base.symbols.dot
];
stdout.should.deepEqual(expectedArray);
});
});
});
describe('on fail', function () {
- it('should return a new line and a exclamation mark in the color red', function () {
+ it('should return a new line and a exclamation mark', function () {
var test = {
test: {
err: 'some error'
@@ -111,7 +114,7 @@ describe('Dot reporter', function () {
process.stdout.write = stdoutWrite;
var expectedArray = [
'\n ',
- ansiColorCodeRed + '!' + ansiColorCodeReset
+ Base.symbols.bang
];
stdout.should.deepEqual(expectedArray);
});
diff --git a/test/reporters/spec.spec.js b/test/reporters/spec.spec.js
index 4c2dd7af..f6199ba3 100644
--- a/test/reporters/spec.spec.js
+++ b/test/reporters/spec.spec.js
@@ -2,16 +2,13 @@
var reporters = require('../../').reporters;
var Spec = reporters.Spec;
+var Base = reporters.Base;
describe('Spec reporter', function () {
var stdout;
var stdoutWrite;
var runner;
- var ansiColorCodeReset = '\u001b[0m';
- var ansiColorCodeCyan = '\u001b[36m';
- var ansiColorCodeRed = '\u001b[31m';
- var ansiColorCodeGreen = '\u001b[32m';
- var ansiColorCodeGrey = '\u001b[90m';
+ var useColors;
beforeEach(function () {
stdout = [];
@@ -20,10 +17,16 @@ describe('Spec reporter', function () {
process.stdout.write = function (string) {
stdout.push(string);
};
+ useColors = Base.useColors;
+ Base.useColors = false;
+ });
+
+ afterEach(function () {
+ Base.useColors = useColors;
});
describe('on suite', function () {
- it('should log title indented in color', function () {
+ it('should return title', function () {
var expectedTitle = 'expectedTitle';
var suite = {
title: expectedTitle
@@ -36,13 +39,13 @@ describe('Spec reporter', function () {
Spec.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
- ansiColorCodeReset + expectedTitle + ansiColorCodeReset + '\n'
+ expectedTitle + '\n'
];
stdout.should.deepEqual(expectedArray);
});
});
describe('on pending', function () {
- it('should log title indented in the color cyan', function () {
+ it('should return title', function () {
var expectedTitle = 'expectedTitle';
var suite = {
title: expectedTitle
@@ -55,14 +58,14 @@ describe('Spec reporter', function () {
Spec.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
- ansiColorCodeCyan + ' - ' + expectedTitle + ansiColorCodeReset + '\n'
+ ' - ' + expectedTitle + '\n'
];
stdout.should.deepEqual(expectedArray);
});
});
describe('on pass', function () {
describe('if test speed is slow', function () {
- it('should return expected green tick, grey title and with duration colored in red', function () {
+ it('should return expected tick, title and duration', function () {
var expectedTitle = 'expectedTitle';
var expectedDuration = 2;
var test = {
@@ -77,12 +80,12 @@ describe('Spec reporter', function () {
};
Spec.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
- var expectedString = ansiColorCodeGreen + ' ✓' + ansiColorCodeReset + ansiColorCodeGrey + ' ' + expectedTitle + ansiColorCodeReset + ansiColorCodeRed + ' (' + expectedDuration + 'ms)' + ansiColorCodeReset + '\n';
+ var expectedString = ' ' + Base.symbols.ok + ' ' + expectedTitle + ' (' + expectedDuration + 'ms)' + '\n';
stdout[0].should.equal(expectedString);
});
});
describe('if test speed is fast', function () {
- it('should return expected green tick, grey title and without a duration', function () {
+ it('should return expected tick, title and without a duration', function () {
var expectedTitle = 'expectedTitle';
var expectedDuration = 1;
var test = {
@@ -97,14 +100,15 @@ describe('Spec reporter', function () {
};
Spec.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
- var expectedString = ansiColorCodeGreen + ' ✓' + ansiColorCodeReset + ansiColorCodeGrey + ' ' + expectedTitle + ansiColorCodeReset + '\n';
+ var expectedString = ' ' + Base.symbols.ok + ' ' + expectedTitle + '\n';
stdout[0].should.equal(expectedString);
});
});
});
describe('on fail', function () {
- it('should log title indented in the color red', function () {
+ it('should return title and function count', function () {
var expectedTitle = 'expectedTitle';
+ var functionCount = 1;
var test = {
title: expectedTitle
};
@@ -116,7 +120,7 @@ describe('Spec reporter', function () {
Spec.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
- ansiColorCodeRed + ' 1) ' + expectedTitle + ansiColorCodeReset + '\n'
+ ' ' + functionCount + ') ' + expectedTitle + '\n'
];
stdout.should.deepEqual(expectedArray);
});