From 82981257a40044612acfafff58f11dd636a6ffc8 Mon Sep 17 00:00:00 2001 From: Jason Kohles Date: Wed, 28 Aug 2019 13:42:06 -0400 Subject: [PATCH] Fix for Mocha 6 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 #269 fixes #282 --- src/mochawesome.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/mochawesome.js b/src/mochawesome.js index a33da35..cb15c88 100755 --- a/src/mochawesome.js +++ b/src/mochawesome.js @@ -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( {},