Skip to content

Commit

Permalink
Merge pull request #2028 from stonelgh/remove-reference-to-test-try2
Browse files Browse the repository at this point in the history
Remove reference to test before afterAll hook runs
  • Loading branch information
danielstjules committed Dec 29, 2015
2 parents 0d3321d + 5bb930f commit 60ff8d8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions test/integration/fixtures/hooks/before.hook.async.error.tip.js
Original file line number Diff line number Diff line change
@@ -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');
});
9 changes: 9 additions & 0 deletions test/integration/fixtures/hooks/before.hook.error.tip.js
Original file line number Diff line number Diff line change
@@ -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');
});
28 changes: 26 additions & 2 deletions test/integration/hook.err.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand All @@ -172,7 +192,7 @@ describe('hook error handling', function() {
.map(function(line) {
return line.trim();
})
.filter(onlyConsoleOutput());
.filter(outputFilter || onlyConsoleOutput());

done();
});
Expand All @@ -189,3 +209,7 @@ function onlyConsoleOutput() {
return !foundSummary && line.length > 0;
};
}

function onlyErrorTitle(line) {
return !!(/^1\)/).exec(line);
}

0 comments on commit 60ff8d8

Please sign in to comment.