☕️ Classic, reliable, trusted test framework for Node.js and the browser
Added basic spec reporter. Closes #26
Tj Holowaychuk599ad988af79
diff --git a/Makefile b/Makefileindex f5cceb9e..01340ca8 100644--- a/Makefile+++ b/Makefile@@ -1,6 +1,6 @@TESTS = test/unit/*.js-REPORTER = list+REPORTER = spectest: test-unitdiff --git a/lib/reporters/base.js b/lib/reporters/base.jsindex 513db035..ce0294b1 100644--- a/lib/reporters/base.js+++ b/lib/reporters/base.js@@ -33,6 +33,7 @@ exports.colors = {, 'fail': 31, 'fail message': 31, 'pending': 36+ , 'suite': '1;90', 'error title': 0, 'error message': 31, 'error stack': 90diff --git a/lib/reporters/list.js b/lib/reporters/list.jsindex b906f22c..60acc4fd 100644--- a/lib/reporters/list.js+++ b/lib/reporters/list.js@@ -41,7 +41,7 @@ function List(runner) {});runner.on('pass', function(test){- var fmt = color('checkmark', ' ✔')+ var fmt = color('checkmark', ' ✓')+ color('pass', ' %s: ')+ color(test.speed, '%dms');console.log('\r' + fmt, test.fullTitle(), test.duration);diff --git a/lib/reporters/spec.js b/lib/reporters/spec.jsnew file mode 100644index 00000000..b322fa82--- /dev/null+++ b/lib/reporters/spec.js@@ -0,0 +1,82 @@++/**+ * Module dependencies.+ */++var Base = require('./base')+ , color = Base.color;++/**+ * Expose `Spec`.+ */++exports = module.exports = Spec;++/**+ * Initialize a new `Spec` test reporter.+ *+ * @param {Runner} runner+ * @api public+ */++function Spec(runner) {+ Base.call(this, runner);++ var self = this+ , stats = this.stats+ , indents = 0+ , n = 0;++ function indent() {+ return Array(indents).join(' ')+ }++ runner.on('start', function(){+ console.log();+ });++ runner.on('suite', function(suite){+ ++indents;+ console.log(color('suite', '%s%s'), indent(), suite.title);+ });++ runner.on('suite end', function(suite){+ --indents;+ });++ runner.on('test', function(test){+ process.stdout.write(indent() + color('pass', test.title + ': '));+ });++ runner.on('pending', function(test){+ var fmt = indent() + color('pending', ' - %s');+ console.log(fmt, test.title);+ });++ runner.on('pass', function(test){+ if ('fast' == test.speed) {+ var fmt = indent()+ + color('checkmark', ' ✓')+ + color('pass', ' %s ');+ console.log('\r' + fmt, test.title);+ } else {+ var fmt = indent()+ + color('checkmark', ' ✓')+ + color('pass', ' %s ')+ + color(test.speed, '(%dms)');+ console.log('\r' + fmt, test.title, test.duration);+ }+ });++ runner.on('fail', function(test, err){+ console.log('\r' + color('fail', ' %d) %s'), n++, test.title);+ });++ runner.on('end', self.epilogue.bind(self));+}++/**+ * Inherit from `Base.prototype`.+ */++Spec.prototype.__proto__ = Base.prototype;\ No newline at end of filediff --git a/lib/runner.js b/lib/runner.jsindex 2304644e..c5877edc 100644--- a/lib/runner.js+++ b/lib/runner.js@@ -252,6 +252,7 @@ Runner.prototype.runSuite = function(suite, fn){self.suite = suite;self.hook('afterAll', function(err){if (err) return self.failHook('afterAll', err);+ self.emit('suite end', suite);fn();});}diff --git a/test/unit/fs.js b/test/unit/fs.jsindex 33b2e6cf..102b8e1e 100644--- a/test/unit/fs.js+++ b/test/unit/fs.js@@ -1,20 +1,18 @@var fs = require('fs');-describe('fs', function(){- describe('.readFile()', function(){- describe('when the file exists', function(){- it('should succeed', function(done){- fs.writeFile('/tmp/mocha', 'wahoo', done)- })+describe('fs.readFile()', function(){+ describe('when the file exists', function(){+ it('should succeed', function(done){+ fs.writeFile('/tmp/mocha', 'wahoo', done)})+ })- describe('when the file does not exist', function(){- it('should fail', function(done){- // uncomment- // fs.readFile('/tmp/does-not-exist', done);- done();- })+ describe('when the file does not exist', function(){+ it('should fail', function(done){+ // uncomment+ // fs.readFile('/tmp/does-not-exist', done);+ done();})})-})\ No newline at end of file+})diff --git a/test/unit/http.meta.js b/test/unit/http.meta.jsindex f083c46a..1a4a7ff2 100644--- a/test/unit/http.meta.js+++ b/test/unit/http.meta.js@@ -36,7 +36,7 @@ function get(url, body, header) {}}-describe('http', function(){+describe('http requests', function(){describe('GET /', function(){it('should respond with hello',get('/', 'hello'))