Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove reference to test before afterAll hook runs #2028

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}