Skip to content

Commit

Permalink
disable colors
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaub committed Jan 29, 2017
1 parent 267ff66 commit 5cd7c3e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
29 changes: 16 additions & 13 deletions test/reporters/dot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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 () {
Expand All @@ -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();
Expand All @@ -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; }
Expand All @@ -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; }
Expand All @@ -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'
Expand All @@ -111,7 +114,7 @@ describe('Dot reporter', function () {
process.stdout.write = stdoutWrite;
var expectedArray = [
'\n ',
ansiColorCodeRed + '!' + ansiColorCodeReset
Base.symbols.bang
];
stdout.should.deepEqual(expectedArray);
});
Expand Down
34 changes: 19 additions & 15 deletions test/reporters/spec.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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
};
Expand All @@ -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);
});
Expand Down

0 comments on commit 5cd7c3e

Please sign in to comment.