Skip to content

Commit

Permalink
Fix for Mocha 6
Browse files Browse the repository at this point in the history
Mocha 6 introduced a new "stats-collector" that reporters have to
manually instantiate in order to get stats.  If running under Mocha
6 reporters that haven't done this will throw exceptions like `Cannot
read property 'passes' of undefined` or `Cannot read property 'failures'
of undefined`.

fixes adamgruber#269
fixes adamgruber#282
  • Loading branch information
jasonk committed Aug 28, 2019
1 parent a40d86b commit 8298125
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/mochawesome.js
Expand Up @@ -81,6 +81,16 @@ function Mochawesome(runner, options) {
// Set the config options
this.config = conf(options);

// If the runner doesn't have a stats object then we're probably
// running under Mocha 6 but were started in a way that didn't
// initialize the stats collector. Attempt to remedy that here.
if (!runner.stats) {
const createStatsCollector = require('mocha/lib/stats-collector');
if (typeof createStatsCollector === 'function') {
createStatsCollector(runner);
}
}

// Reporter options
const reporterOptions = Object.assign(
{},
Expand Down

0 comments on commit 8298125

Please sign in to comment.