☕️ Classic, reliable, trusted test framework for Node.js and the browser
Fixed after() hook
Tj Holowaychuk8abac2b06dbb
diff --git a/Readme.md b/Readme.mdindex 9a8a42db..cc69d007 100644--- a/Readme.md+++ b/Readme.md@@ -1,7 +1,7 @@# mocha- Mocha aims to take the best of several popular JavaScript test frameworks, providing a fun, accessible, robust browser & node.js based test experience.+ Mocha aims to combine the best of several popular JavaScript test frameworks, providing a fun, accessible, robust browser & node.js based test experience.## Features@@ -9,6 +9,7 @@- auto-detects and disables coloring for non-ttys- async test timeout support- growl notification support+ - reports test durations- highlights slow tests- extensible reporting- dot matrixdiff --git a/lib/reporters/base.js b/lib/reporters/base.jsindex e77c7434..aee1cc07 100644--- a/lib/reporters/base.js+++ b/lib/reporters/base.js@@ -106,7 +106,7 @@ exports.list = function(failures){stack = stack.slice(index).replace(/^/gm, ' ');- console.error(fmt, i, test.title, msg, stack);+ console.error(fmt, i, test.fullTitle(), msg, stack);});};@@ -124,7 +124,7 @@ exports.list = function(failures){function Base(runner) {var self = this- , stats = this.stats = {}+ , stats = this.stats = { suites: 0, tests: 0, passes: 0, failures: 0 }, failures = this.failures = [];runner.on('start', function(){@@ -180,7 +180,7 @@ Base.prototype.epilogue = function(){// failureif (stats.failures) {console.error(- color('fail message', ' ✖ %d of %d tests failed')+ color('fail message', ' ✖ %d of %d tests failed:'), stats.failures, stats.tests);Base.list(this.failures);console.error();diff --git a/lib/runner.js b/lib/runner.jsindex 12e640d0..09609775 100644--- a/lib/runner.js+++ b/lib/runner.js@@ -174,7 +174,7 @@ Runner.prototype.runTests = function(suite, fn){function next(err) {// error handling- if (err) return self.fail(test, err);+ if (err) self.fail(test, err);// next testtest = tests.shift();@@ -218,21 +218,24 @@ Runner.prototype.runSuite = function(suite, fn){this.emit('suite', this.suite = suite);- function next(err) {+ function next() {var curr = suite.suites[i++];- if (!curr) return fn();+ if (!curr) return done();self.runSuite(curr, next);}+ function done() {+ self.suite = suite;+ self.hook('afterAll', function(err){+ if (err) return self.failHook('afterAll', err);+ fn();+ });+ }+this.hook('beforeAll', function(err){// TODO: use interface namesif (err) return self.failHook('beforeAll', err);- self.runTests(suite, function(err){- self.hook('afterAll', function(err){- if (err) return self.failHook('afterAll', err);- next();- });- });+ self.runTests(suite, next);});};diff --git a/test/unit/globals.js b/test/unit/globals.jsindex 8b39e7b5..f9c2ef67 100644--- a/test/unit/globals.js+++ b/test/unit/globals.js@@ -11,7 +11,7 @@ describe('global leaks', function(){// bar = 'baz';// baz = 'raz';});-+afterEach(function(){// uncomment to test// foo = 'bar'diff --git a/test/unit/hook.async.js b/test/unit/hook.async.jsindex 2ffd6c98..81abb41f 100644--- a/test/unit/hook.async.js+++ b/test/unit/hook.async.js@@ -1,18 +1,40 @@describe('async', function(){var calls = [];++ before(function(){+ calls.push('root before all');+ })+ after(function(){+ calls.push('root after all');+ calls.should.eql([+ 'root before all'+ , 'before all'+ , 'before'+ , 'one'+ , 'after'+ , 'before'+ , 'two'+ , 'after'+ , 'before'+ , 'three'+ , 'after'+ , 'after all'+ , 'root after all']);+ })+beforeEach(function(){- // not hit+ // should not be invokedcalls.push('parent before');})afterEach(function(){- // not hit+ // should not be invokedcalls.push('parent after' );})- describe('beforeEach()', function(){+ describe('hooks', function(){before(function(){calls.push('before all');});@@ -30,7 +52,8 @@ describe('async', function(){it('one', function(done){calls.should.eql([- 'before all'+ 'root before all'+ , 'before all', 'before']);calls.push('one');process.nextTick(done);@@ -38,7 +61,8 @@ describe('async', function(){it('two', function(){calls.should.eql([- 'before all'+ 'root before all'+ , 'before all', 'before', 'one', 'after'@@ -48,7 +72,8 @@ describe('async', function(){it('three', function(){calls.should.eql([- 'before all'+ 'root before all'+ , 'before all', 'before', 'one', 'after'@@ -65,20 +90,5 @@ describe('async', function(){done();})})-- after(function(){- calls.should.eql([- 'before all'- , 'before'- , 'one'- , 'after'- , 'before'- , 'two'- , 'after'- , 'before'- , 'three'- , 'after'- , 'after all']);- })})})diff --git a/test/unit/hook.sync.js b/test/unit/hook.sync.jsindex da46b798..d5ad9936 100644--- a/test/unit/hook.sync.js+++ b/test/unit/hook.sync.js@@ -12,7 +12,7 @@ describe('serial', function(){calls.push('parent after');})- describe('beforeEach()', function(){+ describe('hooks', function(){beforeEach(function(){calls.push('before');})diff --git a/test/unit/hook.sync.nested.js b/test/unit/hook.sync.nested.jsindex db7d4fc6..88fe72c8 100644--- a/test/unit/hook.sync.nested.js+++ b/test/unit/hook.sync.nested.js@@ -24,7 +24,7 @@ describe('serial', function(){, 'parent before']);})- describe('beforeEach()', function(){+ describe('hooks', function(){beforeEach(function(){calls.push('before');})