diff --git a/index.js b/index.js index 5042f3c..c0a7b86 100644 --- a/index.js +++ b/index.js @@ -89,14 +89,20 @@ var SpecReporter = function (baseReporterDecorator, formatError, config) { this.writeCommonMsg('\n'); } - this.writeCommonMsg((index + ') ' + failure.description + '\n').red); - this.writeCommonMsg((this.WHITESPACE + failure.suite.join(' ') + '\n').red); + this.writeCommonMsg(this.USE_COLORS ? + (index + ') ' + failure.description + '\n').red : + (index + ') ' + failure.description + '\n')); + + this.writeCommonMsg(this.USE_COLORS ? + (this.WHITESPACE + failure.suite.join(' ') + '\n').red : + (this.WHITESPACE + failure.suite.join(' ') + '\n')); failure.log.forEach(function (log) { if (reporterCfg.maxLogLines) { log = log.split('\n').slice(0, reporterCfg.maxLogLines).join('\n'); } - this.writeCommonMsg(this.WHITESPACE + formatError(log) - .replace(/\\n/g, '\n').grey); + this.writeCommonMsg(this.USE_COLORS ? + (this.WHITESPACE + formatError(log).replace(/\\n/g, '\n')).grey : + (this.WHITESPACE + formatError(log).replace(/\\n/g, '\n'))); }, this); }, this); diff --git a/test/index.spec.js b/test/index.spec.js index 254de2f..5233200 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -536,7 +536,7 @@ describe('SpecReporter', function() { return result; } - it('should write a single failure out', function() { + it('should write a single failure out and colors when colors is true', function() { var errors = [ { suite: ['A', 'B'], @@ -548,15 +548,15 @@ describe('SpecReporter', function() { '\n\n', '\u001b[31m1) should do stuff\n\u001b[39m', '\u001b[31m A B\n\u001b[39m', - ' \u001b[90mThe Error!\u001b[39m', + '\u001b[90m The Error!\u001b[39m', '\n' ]; - var specReporter = createSpecReporter(); + var specReporter = createSpecReporter({colors: true}); specReporter.logFinalErrors(errors); writtenMessages.should.eql(expected); }); - it('should truncate messages exceding maxLogLines in length', function() { + it('should truncate messages exceding maxLogLines in length and no color when colors is false', function() { var errors = [ { suite: ['A', 'B'], @@ -566,9 +566,9 @@ describe('SpecReporter', function() { ]; var expected = [ '\n\n', - '\u001b[31m1) should do stuff\n\u001b[39m', - '\u001b[31m A B\n\u001b[39m', - ' \u001b[90mThe Error!\u001b[39m', + '1) should do stuff\n', + ' A B\n', + ' The Error!', '\n' ]; var specReporter = createSpecReporter({ @@ -580,7 +580,7 @@ describe('SpecReporter', function() { writtenMessages.should.eql(expected); }); - it('should write out multiple failures', function() { + it('should write out multiple failures and colors when colors is true', function() { var errors = [ { suite: ['A', 'B'], @@ -597,14 +597,14 @@ describe('SpecReporter', function() { '\n\n', '\u001b[31m1) should do stuff\n\u001b[39m', '\u001b[31m A B\n\u001b[39m', - ' \u001b[90mThe Error!\u001b[39m', + '\u001b[90m The Error!\u001b[39m', '\n', '\u001b[31m2) should do more stuff\n\u001b[39m', '\u001b[31m C D\n\u001b[39m', - ' \u001b[90mAnother error!\u001b[39m', + '\u001b[90m Another error!\u001b[39m', '\n' ]; - var specReporter = createSpecReporter(); + var specReporter = createSpecReporter({colors: true}); specReporter.logFinalErrors(errors); writtenMessages.should.eql(expected); });