Skip to content

Commit

Permalink
(re-)enable after each hooks to fail tests.
Browse files Browse the repository at this point in the history
In version 1.2.1, support was added to fail test in the after each hook:
> * Added `this.test.error(err)` support to after each hooks. Closes mochajs#287

While migrating from teaspoon-mocha to karma-mocha, we discovered that
in the current mocha version this isn't supported anymore (or we don't
understand how). In teaspoon this behaviour seems to be patched (running
it with the exact same mocha.js 2.2.4 file, teaspoon and karma have
different behaviour), although I couldn't quickly pinpoint the code that
does that.

This patch adds this behaviour back to the code base, but also seems to
break certain behaviour (3 tests are failing with this pull request).
But I don't understand what those test failures exactly mean. Also I
found it quite difficult to add test coverage of this behaviour. Since
there aren't any tests calling `runTests`.

Help in figuring out what we've done wrong or how we could fix this pull
request, would be appreciated. Not supporting this behaviour anymore due
to added complexity in the code, would also be fine, but adding some
documentation about dropping this functionality would be nice.
  • Loading branch information
jjoos committed Oct 23, 2015
1 parent 20ebec8 commit 5f661dd
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 62 deletions.
13 changes: 10 additions & 3 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,16 @@ Runner.prototype.runTests = function(suite, fn) {
}

test.state = 'passed';
self.emit('pass', test);
self.emit('test end', test);
self.hookUp('afterEach', next);
// Run the actual emit that the test passed after the forEach hooks,
// so they can still fail a test. And it's not already reported as
// passed.
self.hookUp('afterEach', function() {
if (test.state === 'passed') {
self.emit('pass', test);
}
self.emit('test end', test);
next();
});
});
});
}
Expand Down
Loading

0 comments on commit 5f661dd

Please sign in to comment.