mocha-vite-puppeteer icon indicating copy to clipboard operation
mocha-vite-puppeteer copied to clipboard

mochawesome custom reporter support

Open gabrielthomasjacobs opened this issue 3 years ago • 7 comments

I'm trying to setup mochawesome to report the results, but I cannot get any output to be generated.

I've tried the default script: mocha-vite-puppeteer --reporter mochawesome

As well as specifying a json file which looks like this:

{ "html": true }

The tests run and pass, but no output files are generated. I've tested all of the other built-in reporters (dot, json, etc.) which all work and the other custom reporter, mocha-junit-reporter, is outputting a file correctly.

I tried debugging and following the reporter lookup functions you've made, but things went a bit over my head...

edit: using mochawesome version 6.2.2

gabrielthomasjacobs avatar May 04 '21 00:05 gabrielthomasjacobs

Thank you for the bug report. You are right, and it seems like I only had this partially working. Sorry about that! I will remove the mention of "mochawesome" from README.md for now, and then investigate the issue further. How urgent is this issue for you?

larsthorup avatar May 04 '21 07:05 larsthorup

Hi, thank you for the quick response! It's not too urgent, I will go with the xml reporter option for the time being.

I am curious though, would allowing a mocharc.json file to be forwarded to the mocha instance be too complicated? I know the mocha instance is able to handle merging configs.

Perhaps this would remove the need to explicitly support reporters and other configs?

gabrielthomasjacobs avatar May 04 '21 07:05 gabrielthomasjacobs

Thx. Could you create a separate issue for using mocharc.json over explicit CLI options, as that appears to be a separate improvement in its own right?

I have marked this issue with "enhancement" and will keep it open.

larsthorup avatar May 04 '21 07:05 larsthorup

I think I understand the relationship between all of the pieces in the project a bit better, but please let me know if I don't...

But I think it might be possible for us to "intercept" when "mochawesome" is specified as a reporter and then handle it by replacing "mochawesome" with "json". When the tests complete and the output comes back, it'll be in string/JSON form, if we can intercept this output and do a JSON.parse(), we should be able to just do mochawesome.create(outputObj) to have mochawesome-report-generator create the output.

I can start creating a prototype PR and testing, but I would need some direction for when/how the results are logged. I tried exploring a bit, but I can't seem to find it....

gabrielthomasjacobs avatar Jul 06 '21 19:07 gabrielthomasjacobs

Good suggestion, but unfortunately I don't think that will work. I assume that "outputObj" here is Mocha's output object, which contains a lot of self references (e.g. tests reference suites, and suites reference tests). And the "json" reporter only serializes a tiny bit of this object, which is the reason why this project includes the mochaProtocolReporter so we can include more of Mocha's objects and "recreate" some of the self references in mochaProtocolPlayer.

I believe the right strategy is to figure out which further properties of Mocha's output object is needed by mochawesome, and then add those to the mochaProtocolReporter and -Player.

larsthorup avatar Jul 07 '21 05:07 larsthorup

Using the mochawesome reporter, if I breakpoint after the tests run, the mochaProtocolPlayer.reporter.output seems to be almost in a good shape to be useful.

There are a few issues though, within that object, each suite object needs a "_timeout" key/value and it seems that all of the specs are reporting as skipped. Not really sure why....

gabrielthomasjacobs avatar Jul 26 '21 18:07 gabrielthomasjacobs

I don't know either - more debugging required, I guess - happy to assist with ideas, if you share a fork with a specific question!

larsthorup avatar Jul 27 '21 05:07 larsthorup