karma-mocha-runner
v1.1.2
Published
A Karma plugin. Adapter for Mocha testing framework, with access to the mocha runner instance.
Downloads
1,243
Maintainers
Readme
karma-mocha-runner
Adapter for the Mocha testing framework. Forked from karma-mocha in order to add access to the mocha runner instance and its events.
Primary Documentation
Please refer to the karma-mocha site for documentation.
Access to the Mocha test runner instance
The primary reason for this fork is to provide access to the Mocha test runner instance. With access to the runner, you gain the ability to listen to its events.
One possible use for these events is to help mitigate memory usage for large test suites. By handling the 'suite end' and/or 'test end' events, some of the mocha test suite context can be explicitly released in ways mocha itself does not.
Inspired by this mocha issue comment
var runner = getRunner(); // obtain the runner instance by some means... (TBD @@@)
runner.on('suite end', function(suite) {
// ASSUMPTION: 'suite end' event takes into account any async `before...` and `after...` hooks, i.e. those
// that use the `done()` callback.
delete suite._afterAll;
delete suite._afterEach;
delete suite._beforeAll;
delete suite._beforeEach;
delete suite.ctx;
delete suite.suites;
delete suite.tests;
});
runner.on('test end', function(test) {
// DO NOT alter tests that should be retained due to use of the `done()` callback.
if (! test.async) {
delete test.ctx;
}
});