☕️ Classic, reliable, trusted test framework for Node.js and the browser
nyan face modify with stats
eiji.ienaga21018ae2c1f0
diff --git a/Makefile b/Makefileindex 055f7c5c..1b922c06 100644--- a/Makefile+++ b/Makefile@@ -32,7 +32,7 @@ lib-cov:test: test-unit-test-all: test-bdd test-tdd test-qunit test-exports test-unit test-grep test-jsapi test-compilers test-glob test-requires+test-all: test-bdd test-tdd test-qunit test-exports test-unit test-grep test-jsapi test-compilers test-glob test-requires test-reporterstest-jsapi:@node test/jsapi@@ -113,6 +113,11 @@ test-async-only:test-glob:@./test/acceptance/glob/glob.sh+test-reporters:+ @./bin/mocha \+ --reporter $(REPORTER) \+ test/reporters/*.js+non-tty:@./bin/mocha \--reporter dot \diff --git a/lib/reporters/nyan.js b/lib/reporters/nyan.jsindex b43e2440..bc394bac 100644--- a/lib/reporters/nyan.js+++ b/lib/reporters/nyan.js@@ -20,7 +20,6 @@ exports = module.exports = NyanCat;function NyanCat(runner) {Base.call(this, runner);-var self = this, stats = this.stats, width = Base.window.width * .75 | 0@@ -36,19 +35,19 @@ function NyanCat(runner) {runner.on('start', function(){Base.cursor.hide();- self.draw('start');+ self.draw();});runner.on('pending', function(test){- self.draw('pending');+ self.draw();});runner.on('pass', function(test){- self.draw('pass');+ self.draw();});runner.on('fail', function(test, err){- self.draw('fail');+ self.draw();});runner.on('end', function(){@@ -59,17 +58,16 @@ function NyanCat(runner) {}/**- * Draw the nyan cat with runner `status`.+ * Draw the nyan cat*- * @param {String} status* @api private*/-NyanCat.prototype.draw = function(status){+NyanCat.prototype.draw = function(){this.appendRainbow();this.drawScoreboard();this.drawRainbow();- this.drawNyanCat(status);+ this.drawNyanCat();this.tick = !this.tick;};@@ -134,44 +132,33 @@ NyanCat.prototype.drawRainbow = function(){};/**- * Draw the nyan cat with `status`.+ * Draw the nyan cat*- * @param {String} status* @api private*/-NyanCat.prototype.drawNyanCat = function(status) {+NyanCat.prototype.drawNyanCat = function() {var self = this;var startWidth = this.scoreboardWidth + this.trajectories[0].length;var color = '\u001b[' + startWidth + 'C';var padding = '';-+write(color);write('_,------,');write('\n');-+write(color);padding = self.tick ? ' ' : ' ';write('_|' + padding + '/\\_/\\ ');write('\n');-+write(color);padding = self.tick ? '_' : '__';var tail = self.tick ? '~' : '^';var face;- switch (status) {- case 'pass':- face = '( ^ .^)';- break;- case 'fail':- face = '( o .o)';- break;- default:- face = '( - .-)';- }- write(tail + '|' + padding + face + ' ');+ write(tail + '|' + padding + this.face() + ' ');write('\n');-+write(color);padding = self.tick ? ' ' : ' ';write(padding + '"" "" ');@@ -180,6 +167,19 @@ NyanCat.prototype.drawNyanCat = function(status) {this.cursorUp(this.numberOfLines);};+NyanCat.prototype.face = function() {+ var stats = this.stats;+ if (stats.failures) {+ return '( x .x)';+ } else if (stats.pending) {+ return '( o .o)';+ } else if(stats.passes) {+ return '( ^ .^)';+ } else {+ return '( - .-)';+ }+}+/*** Move cursor up `n`.*diff --git a/test/reporters/nyan.js b/test/reporters/nyan.jsnew file mode 100644index 00000000..8a544589--- /dev/null+++ b/test/reporters/nyan.js@@ -0,0 +1,30 @@+var reporters = require('../../').reporters+ , NyanCat = reporters.Nyan;+++describe('nyan face', function () {+ it('nyan face:(x .x) when "failures" at least one', function () {+ var nyanCat = new NyanCat({on: function(){}});+ nyanCat.stats = { passes: 2, pending: 1, failures: 1 };+ nyanCat.face.call(nyanCat).should.equal('( x .x)');+ });++ it('expected nyan face:(x .x) when "peinding" at least one and no failing', function () {+ var nyanCat = new NyanCat({on: function(){}});+ nyanCat.stats = { passes: 2, pending: 1, failures: 0 };+ nyanCat.face.call(nyanCat).should.equal('( o .o)');+ });++ it('expected nyan face:(^ .^) when "passing" only', function () {+ var nyanCat = new NyanCat({on: function(){}});+ nyanCat.stats = { passes: 1, pending: 0, failures: 0 };+ nyanCat.face.call(nyanCat).should.equal('( ^ .^)');+ });++ it('nyan face:(- .-) when otherwise', function (done) {+ var nyanCat = new NyanCat({on: function(){}});+ nyanCat.stats = { passes: 0, pending: 0, failures: 0 };+ nyanCat.face.call(nyanCat).should.equal('( - .-)');+ done();+ });+})