Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

refactored NyanCat#drawScoreboard()

TJ Holowaychuk093377e37335
diff --git a/lib/reporters/nyan.js b/lib/reporters/nyan.js
index 37621b2b..8df7681c 100644
--- a/lib/reporters/nyan.js
+++ b/lib/reporters/nyan.js
@@ -25,23 +25,18 @@ function NyanCat(runner) {
var self = this
, stats = this.stats
, width = Base.window.width * .75 | 0
- , n = 0
, rainbowColors = this.rainbowColors = self.generateColors()
, colorIndex = this.colorIndex = 0
, numerOfLines = this.numberOfLines = 4
, trajectories = this.trajectories = [[], [], [], []]
- /*
- * '_,------, '
- '_| /\\_/\\'
- '~|_( o .o) '
- ' "" "" '
- */
, nyanCatWidth = this.nyanCatWidth = 11
, trajectoryWidthMax = this.trajectoryWidthMax = (width - nyanCatWidth)
, scoreboardWidth = this.scoreboardWidth = 5
- , tick = this.tick = 0;
+ , tick = this.tick = 0
+ , n = 0;
runner.on('start', function(){
+ Base.cursor.hide();
self.draw('start');
});
@@ -58,35 +53,47 @@ function NyanCat(runner) {
});
runner.on('end', function(){
- //self.cursorDown(numberOfLines);
- for (var i = 0; i < self.numberOfLines; i++) {
- write('\n');
- }
-
+ Base.cursor.show();
+ for (var i = 0; i < self.numberOfLines; i++) write('\n');
self.epilogue();
});
}
-NyanCat.prototype.draw = function(status) {
- this.appendTrajectory();
+/**
+ * Draw the nyan cat with runner `status`.
+ *
+ * @param {String} status
+ * @api private
+ */
+NyanCat.prototype.draw = function(status){
+ this.appendTrajectory();
this.drawScoreboard();
this.drawTrajectory();
this.drawNyanCat(status);
-
this.tick = !this.tick;
};
-NyanCat.prototype.drawScoreboard = function() {
- [
- { color: Base.colors['green'], number: (this.stats.passes || 0) }
- , { color: Base.colors['fail'], number: (this.stats.failures || 0) }
- , { color: Base.colors['pending'], number: (this.stats.pending || 0) }
- ].forEach(function(element) {
+/**
+ * Draw the "scoreboard" showing the number
+ * of passes, failures and pending tests.
+ *
+ * @api private
+ */
+
+NyanCat.prototype.drawScoreboard = function(){
+ var stats = this.stats;
+ var colors = Base.colors;
+
+ function draw(color, n) {
write(' ');
- write('\033[' + element.color + 'm' + element.number + '\033[0m');
+ write('\033[' + color + 'm' + n + '\033[0m');
write('\n');
- });
+ }
+
+ draw(colors.green, stats.passes);
+ draw(colors.fail, stats.failures);
+ draw(colors.pending, stats.pending);
write('\n');
this.cursorUp(this.numberOfLines);