Skip to content

Commit

Permalink
fix(logFinalErrors): only use colors when they are set by the config,
Browse files Browse the repository at this point in the history
fixes #71
  • Loading branch information
tmcgee123 committed Dec 8, 2022
1 parent dcb1180 commit 575badb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
22 changes: 11 additions & 11 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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'],
Expand All @@ -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({
Expand All @@ -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'],
Expand All @@ -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);
});
Expand Down

0 comments on commit 575badb

Please sign in to comment.