diff --git a/lib/runner.js b/lib/runner.js index c69ecaddd3..d6fdddde17 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -629,6 +629,10 @@ Runner.prototype.runSuite = function(suite, fn) { // mark that the afterAll block has been called once // and so can be skipped if there is an error in it. afterAllHookCalled = true; + + // remove reference to test + delete self.test; + self.hook('afterAll', function() { self.emit('suite end', suite); fn(errSuite); diff --git a/test/integration/fixtures/hooks/before.hook.async.error.tip.js b/test/integration/fixtures/hooks/before.hook.async.error.tip.js new file mode 100644 index 0000000000..14e114e959 --- /dev/null +++ b/test/integration/fixtures/hooks/before.hook.async.error.tip.js @@ -0,0 +1,11 @@ +describe('spec 1', function() { + it('should not blame me', function() { }); +}); +describe('spec 2', function() { + before(function(done) { + process.nextTick(function () { + throw new Error('before hook error'); + }); + }); + it('skipped'); +}); diff --git a/test/integration/fixtures/hooks/before.hook.error.tip.js b/test/integration/fixtures/hooks/before.hook.error.tip.js new file mode 100644 index 0000000000..567dfef26b --- /dev/null +++ b/test/integration/fixtures/hooks/before.hook.error.tip.js @@ -0,0 +1,9 @@ +describe('spec 1', function() { + it('should not blame me', function() { }); +}); +describe('spec 2', function() { + before(function() { + throw new Error('before hook error'); + }); + it('skipped'); +}); diff --git a/test/integration/hook.err.js b/test/integration/hook.err.js index a3727156ff..ca1a8fe1bb 100644 --- a/test/integration/hook.err.js +++ b/test/integration/hook.err.js @@ -16,6 +16,16 @@ describe('hook error handling', function() { }); }); + describe('before hook error tip', function() { + before(run('hooks/before.hook.error.tip.js', onlyErrorTitle)); + it('should verify results', function() { + assert.deepEqual( + lines, + ['1) spec 2 "before all" hook:'] + ); + }); + }); + describe('before each hook error', function() { before(run('hooks/beforeEach.hook.error.js')); it('should verify results', function() { @@ -94,6 +104,16 @@ describe('hook error handling', function() { }); }); + describe('async - before hook error tip', function() { + before(run('hooks/before.hook.async.error.tip.js', onlyErrorTitle)); + it('should verify results', function() { + assert.deepEqual( + lines, + ['1) spec 2 "before all" hook:'] + ); + }); + }); + describe('async - before each hook error', function() { before(run('hooks/beforeEach.hook.async.error.js')); it('should verify results', function() { @@ -162,7 +182,7 @@ describe('hook error handling', function() { }); }); - function run(fnPath) { + function run(fnPath, outputFilter) { return function(done) { runMocha(fnPath, [], function(err, res) { assert.ifError(err); @@ -172,7 +192,7 @@ describe('hook error handling', function() { .map(function(line) { return line.trim(); }) - .filter(onlyConsoleOutput()); + .filter(outputFilter || onlyConsoleOutput()); done(); }); @@ -189,3 +209,7 @@ function onlyConsoleOutput() { return !foundSummary && line.length > 0; }; } + +function onlyErrorTitle(line) { + return !!(/^1\)/).exec(line); +}