Skip to content

armgit / mocha

Public Imported from GitHub
0

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

docs

TJ Holowaychuk48c9892c418b
diff --git a/lib/reporters/nyan.js b/lib/reporters/nyan.js
index 8df7681c..1a59d0ab 100644
--- a/lib/reporters/nyan.js
+++ b/lib/reporters/nyan.js
@@ -67,9 +67,9 @@ function NyanCat(runner) {
*/
NyanCat.prototype.draw = function(status){
- this.appendTrajectory();
+ this.appendRainbow();
this.drawScoreboard();
- this.drawTrajectory();
+ this.drawRainbow();
this.drawNyanCat(status);
this.tick = !this.tick;
};
@@ -99,26 +99,34 @@ NyanCat.prototype.drawScoreboard = function(){
this.cursorUp(this.numberOfLines);
};
-NyanCat.prototype.appendTrajectory = function() {
- var segment = (this.tick) ? '_' : '-';
+/**
+ * Append the rainbow.
+ *
+ * @api private
+ */
+
+NyanCat.prototype.appendRainbow = function(){
+ var segment = this.tick ? '_' : '-';
var rainbowified = this.rainbowify(segment);
for (var index = 0; index < this.numberOfLines; index++) {
var trajectory = this.trajectories[index];
-
- if (trajectory.length >= this.trajectoryWidthMax) {
- trajectory.shift();
- }
+ if (trajectory.length >= this.trajectoryWidthMax) trajectory.shift();
trajectory.push(rainbowified);
}
};
-NyanCat.prototype.drawTrajectory = function() {
- var that = this;
+/**
+ * Draw the rainbow.
+ *
+ * @api private
+ */
+
+NyanCat.prototype.drawRainbow = function(){
+ var self = this;
this.trajectories.forEach(function(line, index) {
- write('\033[' + that.scoreboardWidth + 'C');
-
+ write('\033[' + self.scoreboardWidth + 'C');
write(line.join(''));
write('\n');
});
@@ -126,8 +134,15 @@ NyanCat.prototype.drawTrajectory = function() {
this.cursorUp(this.numberOfLines);
};
+/**
+ * Draw the nyan cat with `status`.
+ *
+ * @param {String} status
+ * @api private
+ */
+
NyanCat.prototype.drawNyanCat = function(status) {
- var that = this;
+ var self = this;
var startWidth = this.scoreboardWidth + this.trajectories[0].length;
[0, 1, 2, 3].forEach(function(index) {
@@ -139,13 +154,13 @@ NyanCat.prototype.drawNyanCat = function(status) {
write('\n');
break;
case 1:
- var padding = (that.tick) ? ' ' : ' ';
+ var padding = self.tick ? ' ' : ' ';
write('_|' + padding + '/\\_/\\');
write('\n');
break;
case 2:
- var padding = (that.tick) ? '_' : '__';
- var tail = (that.tick) ? '~' : '^';
+ var padding = self.tick ? '_' : '__';
+ var tail = self.tick ? '~' : '^';
var face;
switch (status) {
case 'pass':
@@ -161,7 +176,7 @@ NyanCat.prototype.drawNyanCat = function(status) {
write('\n');
break;
case 3:
- var padding = (that.tick) ? ' ' : ' ';
+ var padding = self.tick ? ' ' : ' ';
write(padding + '"" ""');
write('\n');
break;
@@ -171,35 +186,68 @@ NyanCat.prototype.drawNyanCat = function(status) {
this.cursorUp(this.numberOfLines);
};
-NyanCat.prototype.cursorUp = function(value) {
- write('\033[' + value + 'A');
+/**
+ * Move cursor up `n`.
+ *
+ * @param {Number} n
+ * @api private
+ */
+
+NyanCat.prototype.cursorUp = function(n) {
+ write('\033[' + n + 'A');
};
-NyanCat.prototype.cursorDown = function(value) {
- write('\033[' + value + 'B');
+/**
+ * Move cursor down `n`.
+ *
+ * @param {Number} n
+ * @api private
+ */
+
+NyanCat.prototype.cursorDown = function(n) {
+ write('\033[' + n + 'B');
};
-NyanCat.prototype.generateColors = function() {
+/**
+ * Generate rainbow colors.
+ *
+ * @return {Array}
+ * @api private
+ */
+
+NyanCat.prototype.generateColors = function(){
var colors = [];
+
for (var i = 0; i < (6 * 7); i++) {
var pi3 = Math.floor(Math.PI / 3);
var n = (i * (1.0 / 6));
var r = Math.floor(3 * Math.sin(n) + 3);
var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
-
colors.push(36 * r + 6 * g + b + 16);
}
return colors;
};
-NyanCat.prototype.rainbowify = function(string) {
+/**
+ * Apply rainbow to the given `str`.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api private
+ */
+
+NyanCat.prototype.rainbowify = function(str){
var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
this.colorIndex += 1;
- return '\033[38;5;' + color + 'm' + string + '\033[0m';
+ return '\033[38;5;' + color + 'm' + str + '\033[0m';
};
+/**
+ * Stdout helper.
+ */
+
function write(string) {
process.stdout.write(string);
}