Skip to content

Standardize colors across reporters. #412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ var updateNotifier = require('update-notifier');
var figures = require('figures');
var arrify = require('arrify');
var meow = require('meow');
var chalk = require('chalk');
var Promise = require('bluebird');
var pkgConf = require('pkg-conf');
var colors = require('./lib/colors');
var verboseReporter = require('./lib/reporters/verbose');
var miniReporter = require('./lib/reporters/mini');
var tapReporter = require('./lib/reporters/tap');
Expand Down Expand Up @@ -111,9 +111,9 @@ api.run()
})
.catch(function (err) {
if (err.name === 'AvaError') {
console.log(' ' + chalk.red(figures.cross) + ' ' + err.message);
console.log(' ' + colors.error(figures.cross) + ' ' + err.message);
} else {
console.error(err.stack);
console.error(colors.stack(err.stack));
}

logger.exit(1);
Expand Down
11 changes: 11 additions & 0 deletions lib/colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

var chalk = require('chalk');

module.exports = {
error: chalk.red,
skip: chalk.yellow,
pass: chalk.green,
duration: chalk.gray.dim,
stack: chalk.red
};
30 changes: 15 additions & 15 deletions lib/reporters/mini.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var logUpdate = require('log-update');
var chalk = require('chalk');
var colors = require('../colors');
var plur = require('plur');
var beautifyStack = require('../beautify-stack');

Expand Down Expand Up @@ -28,25 +28,25 @@ MiniReporter.prototype.test = function (test) {
var title;

if (test.skip) {
title = chalk.yellow('- ' + test.title);
title = colors.skip('- ' + test.title);
this.skipCount++;
} else if (test.error) {
title = chalk.red(test.title);
title = colors.error(test.title);
this.failCount++;
} else {
title = chalk.green(test.title);
title = colors.pass(test.title);
this.passCount++;
}

status += ' ' + title;
status += '\n\n';

if (this.passCount > 0) {
status += ' ' + chalk.green(this.passCount, 'passed');
status += ' ' + colors.pass(this.passCount, 'passed');
}

if (this.failCount > 0) {
status += ' ' + chalk.red(this.failCount, 'failed');
status += ' ' + colors.error(this.failCount, 'failed');
}

return status;
Expand All @@ -66,23 +66,23 @@ MiniReporter.prototype.finish = function () {
var status = '\n';

if (this.passCount > 0) {
status += ' ' + chalk.green(this.passCount, 'passed');
status += ' ' + colors.pass(this.passCount, 'passed');
}

if (this.skipCount > 0) {
status += ' ' + chalk.yellow(this.skipCount, 'skipped');
status += ' ' + colors.skip(this.skipCount, 'skipped');
}

if (this.failCount > 0) {
status += ' ' + chalk.red(this.failCount, 'failed');
status += ' ' + colors.error(this.failCount, 'failed');
}

if (this.rejectionCount > 0) {
status += '\n ' + chalk.red(this.rejectionCount, plur('rejection', this.rejectionCount));
status += '\n ' + colors.error(this.rejectionCount, plur('rejection', this.rejectionCount));
}

if (this.exceptionCount > 0) {
status += '\n ' + chalk.red(this.exceptionCount, plur('exception', this.exceptionCount));
status += '\n ' + colors.error(this.exceptionCount, plur('exception', this.exceptionCount));
}

var i = 0;
Expand All @@ -105,8 +105,8 @@ MiniReporter.prototype.finish = function () {
description = JSON.stringify(test);
}

status += '\n\n ' + chalk.red(i + '.', title) + '\n';
status += chalk.red(description);
status += '\n\n ' + colors.error(i + '.', title) + '\n';
status += colors.stack(description);
});
}

Expand All @@ -121,8 +121,8 @@ MiniReporter.prototype.finish = function () {
var title = err.type === 'rejection' ? 'Unhandled Rejection' : 'Uncaught Exception';
var description = err.stack ? beautifyStack(err.stack) : JSON.stringify(err);

status += '\n\n ' + chalk.red(i + '.', title) + '\n';
status += ' ' + chalk.red(description);
status += '\n\n ' + colors.error(i + '.', title) + '\n';
status += ' ' + colors.stack(description);
});
}

Expand Down
30 changes: 15 additions & 15 deletions lib/reporters/verbose.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
var prettyMs = require('pretty-ms');
var figures = require('figures');
var chalk = require('chalk');
var colors = require('../colors');
var plur = require('plur');
var beautifyStack = require('../beautify-stack');

Expand All @@ -19,11 +19,11 @@ VerboseReporter.prototype.start = function () {

VerboseReporter.prototype.test = function (test) {
if (test.error) {
return ' ' + chalk.red(figures.cross) + ' ' + test.title + ' ' + chalk.red(test.error.message);
return ' ' + colors.error(figures.cross) + ' ' + test.title + ' ' + colors.error(test.error.message);
}

if (test.skip) {
return ' ' + chalk.cyan('- ' + test.title);
return ' ' + colors.skip('- ' + test.title);
}

if (this.api.fileCount === 1 && this.api.testCount === 1 && test.title === '[anonymous]') {
Expand All @@ -32,9 +32,9 @@ VerboseReporter.prototype.test = function (test) {

// display duration only over a threshold
var threshold = 100;
var duration = test.duration > threshold ? chalk.gray.dim(' (' + prettyMs(test.duration) + ')') : '';
var duration = test.duration > threshold ? colors.duration(' (' + prettyMs(test.duration) + ')') : '';

return ' ' + chalk.green(figures.tick) + ' ' + test.title + duration;
return ' ' + colors.pass(figures.tick) + ' ' + test.title + duration;
};

VerboseReporter.prototype.unhandledError = function (err) {
Expand All @@ -43,12 +43,12 @@ VerboseReporter.prototype.unhandledError = function (err) {
exception: 'Uncaught Exception'
};

var output = chalk.red(types[err.type] + ':', err.file) + '\n';
var output = colors.error(types[err.type] + ':', err.file) + '\n';

if (err.stack) {
output += ' ' + chalk.red(beautifyStack(err.stack)) + '\n';
output += ' ' + colors.stack(beautifyStack(err.stack)) + '\n';
} else {
output += ' ' + chalk.red(JSON.stringify(err)) + '\n';
output += ' ' + colors.stack(JSON.stringify(err)) + '\n';
}

output += '\n';
Expand All @@ -60,21 +60,21 @@ VerboseReporter.prototype.finish = function () {
var output = '\n';

if (this.api.failCount > 0) {
output += ' ' + chalk.red(this.api.failCount, plur('test', this.api.failCount), 'failed') + '\n';
output += ' ' + colors.error(this.api.failCount, plur('test', this.api.failCount), 'failed') + '\n';
} else {
output += ' ' + chalk.green(this.api.passCount, plur('test', this.api.passCount), 'passed') + '\n';
output += ' ' + colors.pass(this.api.passCount, plur('test', this.api.passCount), 'passed') + '\n';
}

if (this.api.skipCount > 0) {
output += ' ' + chalk.yellow(this.api.skipCount, plur('test', this.api.skipCount), 'skipped') + '\n';
output += ' ' + colors.skip(this.api.skipCount, plur('test', this.api.skipCount), 'skipped') + '\n';
}

if (this.api.rejectionCount > 0) {
output += ' ' + chalk.red(this.api.rejectionCount, 'unhandled', plur('rejection', this.api.rejectionCount)) + '\n';
output += ' ' + colors.error(this.api.rejectionCount, 'unhandled', plur('rejection', this.api.rejectionCount)) + '\n';
}

if (this.api.exceptionCount > 0) {
output += ' ' + chalk.red(this.api.exceptionCount, 'uncaught', plur('exception', this.api.exceptionCount)) + '\n';
output += ' ' + colors.error(this.api.exceptionCount, 'uncaught', plur('exception', this.api.exceptionCount)) + '\n';
}

if (this.api.failCount > 0) {
Expand All @@ -89,8 +89,8 @@ VerboseReporter.prototype.finish = function () {

i++;

output += ' ' + chalk.red(i + '.', test.title) + '\n';
output += ' ' + chalk.red(beautifyStack(test.error.stack)) + '\n';
output += ' ' + colors.error(i + '.', test.title) + '\n';
output += ' ' + colors.stack(beautifyStack(test.error.stack)) + '\n';
});
}

Expand Down