☕️ Classic, reliable, trusted test framework for Node.js and the browser
fixes #1461: nyan-reporter now respects Base.useColors, fixed bug where Base.color would not return a string when str wasn't a string.
David da Silvae57ea6b05f71
diff --git a/lib/reporters/base.js b/lib/reporters/base.jsindex 6d51fcfd..abbeb011 100644--- a/lib/reporters/base.js+++ b/lib/reporters/base.js@@ -97,7 +97,7 @@ if ('win32' == process.platform) {*/var color = exports.color = function(type, str) {- if (!exports.useColors) return str;+ if (!exports.useColors) return String(str);return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';};diff --git a/lib/reporters/nyan.js b/lib/reporters/nyan.jsindex a8d43bf5..63056b17 100644--- a/lib/reporters/nyan.js+++ b/lib/reporters/nyan.js@@ -2,8 +2,7 @@* Module dependencies.*/-var Base = require('./base')- , color = Base.color;+var Base = require('./base');/*** Expose `Dot`.@@ -80,17 +79,16 @@ NyanCat.prototype.draw = function(){NyanCat.prototype.drawScoreboard = function(){var stats = this.stats;- var colors = Base.colors;- function draw(color, n) {+ function draw(type, n) {write(' ');- write('\u001b[' + color + 'm' + n + '\u001b[0m');+ write(Base.color(type, n));write('\n');}- draw(colors.green, stats.passes);- draw(colors.fail, stats.failures);- draw(colors.pending, stats.pending);+ draw('green', stats.passes);+ draw('fail', stats.failures);+ draw('pending', stats.pending);write('\n');this.cursorUp(this.numberOfLines);@@ -140,26 +138,26 @@ NyanCat.prototype.drawRainbow = function(){NyanCat.prototype.drawNyanCat = function() {var self = this;var startWidth = this.scoreboardWidth + this.trajectories[0].length;- var color = '\u001b[' + startWidth + 'C';+ var dist = '\u001b[' + startWidth + 'C';var padding = '';- write(color);+ write(dist);write('_,------,');write('\n');- write(color);+ write(dist);padding = self.tick ? ' ' : ' ';write('_|' + padding + '/\\_/\\ ');write('\n');- write(color);+ write(dist);padding = self.tick ? '_' : '__';var tail = self.tick ? '~' : '^';var face;write(tail + '|' + padding + this.face() + ' ');write('\n');- write(color);+ write(dist);padding = self.tick ? ' ' : ' ';write(padding + '"" "" ');write('\n');@@ -240,6 +238,8 @@ NyanCat.prototype.generateColors = function(){*/NyanCat.prototype.rainbowify = function(str){+ if (!Base.useColors)+ return str;var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];this.colorIndex += 1;return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';