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

Fix for Mocha 6 #291

Closed
wants to merge 1 commit into from
Closed

Fix for Mocha 6 #291

wants to merge 1 commit into from

Conversation

jasonk
Copy link

@jasonk jasonk commented Aug 28, 2019

Mocha 6 introduced a new "stats-collector" that has to be instantiated
in order to get stats. If you are using Mocha itself directly this
works fine, but a lot of things that are running Mocha
programatically, or overriding Mocha.prototype.run still haven't got
this right yet (Cypress is the big one for me).

Ideally this would be the frameworks problem to fix, but since it's
relatively simple to make Mochawesome work regardless of whether the
runner initialized correctly, I thought you might be interested.

fixes #269
fixes #282

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
Copy link
Owner

@adamgruber adamgruber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Do you think you could add a test case and update the changelog?

// initialize the stats collector. Attempt to remedy that here.
if (!runner.stats) {
const createStatsCollector = require('mocha/lib/stats-collector');
if (typeof createStatsCollector === 'function') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the typeof check?

@vitformusor
Copy link

Hi guys,
waiting for this fix over two month now :-)
Can it be merged soon?
Thanks a lot

@vitformusor
Copy link

Did test it, works great

@adamgruber
Copy link
Owner

@jasonk Are you able to finish working on this?

@adamgruber
Copy link
Owner

adamgruber commented Oct 21, 2019

Did some testing on this. It does allow mochawesome to work with cypress and mocha 6 but it does not work if you are using an earlier version of mocha. Also breaks when just using mocha 5 directly.

@@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this assumption is true. When running under Mocha 5, runner.stats will be undefined at this point and trying to require stats-collector will throw because it doesn't exist. When running directly in Mocha 6, runner.stats will be an object at this point.

@adamgruber
Copy link
Owner

This change has been added in #303. Closing.

@adamgruber adamgruber closed this Feb 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generated HTML reports are empty when running from CI TypeError: Cannot read property 'passes' of undefined
3 participants