-
Notifications
You must be signed in to change notification settings - Fork 160
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
Fix for Mocha 6 #291
Conversation
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
There was a problem hiding this 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') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the typeof
check?
Hi guys, |
Did test it, works great |
@jasonk Are you able to finish working on this? |
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 |
There was a problem hiding this comment.
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.
This change has been added in #303. Closing. |
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 gotthis 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