mochawesome icon indicating copy to clipboard operation
mochawesome copied to clipboard

Generate mochawesome from Karma

Open TiagoFig opened this issue 8 years ago • 14 comments

Is there any way to generate mochawesome report from karma? I tried to use "client:mocha:reporter" option from "karma-mocha", but not works =/.

TiagoFig avatar Sep 21 '16 13:09 TiagoFig

I've only used karma a couple of times and never tried changing the reporter. I would think that if karma-mocha supports any of the mocha built-in reporters then mochawesome should work. Might want to check with that repo what kind of reporter support they have.

adamgruber avatar Sep 28 '16 00:09 adamgruber

I can confirm this does not work for whatever reason. Perhaps @dignifiedquire or @maksimr can help us here.

RobertWHurst avatar Dec 29 '16 08:12 RobertWHurst

Found the issue I believe. The reporter isn't being included in the bundle karma sends to the browser. This is because mocha makes a dynamic require call to get reporters by name. screen shot 2016-12-29 at 12 24 50 am ^^ line 153 in lib/mocha.js

Because this is a dynamic require, it doesn't get included. I'm now looking for a way to force karma to include the reporter so hopefully the require method will return the reporter.

RobertWHurst avatar Dec 29 '16 08:12 RobertWHurst

@adamgruber @RobertWHurst first of all client:mocha:reporter works only for debug page. Second, we add only mocha.css to files, so if you want use custom html reporter on debug page, you should add js and css to files in config or you can pass require[1] options in client mocha config which contains path to those files.

[1] - https://github.com/karma-runner/karma-mocha#configuration (look at example with require)

Thanks

maksimr avatar Dec 29 '16 09:12 maksimr

@maksimr Sounds good. Thanks for the clarification. 👍

I did manage to get mochawesome into the page. Had to screw around with my karma webpack config. I quickly released it wouldn't work. mochawesome was trying to require the fs module. This makes sense. mochawesome is suppose to run in node, and generates the report in a directory. For this to work mochawesome would have to be built to support running inside the browser as the html reporter that ships with mocha does. If said changes were made then theoretically you should be able to load mochawesome with the require option as stated above by @maksimr.

🍻

RobertWHurst avatar Dec 29 '16 09:12 RobertWHurst

@RobertWHurst is correct. mochawesome was only ever meant to run in node

adamgruber avatar Dec 29 '16 17:12 adamgruber

is there any technical reason why it couldn't be retrofitted to run in the browser?

boneskull avatar Dec 29 '16 18:12 boneskull

hmm, no not that i can think of.

adamgruber avatar Dec 29 '16 18:12 adamgruber

How specific is the code to generate the report to mocha? I just saw this and was thinking, wouldn't it be nice if we could have something nice looking like this as a live dashboard in the browser that karma is currently executing in, or at least at a url like: localhost:9876/dashboard.

dignifiedquire avatar Dec 29 '16 20:12 dignifiedquire

@dignifiedquire If you have the right JSON you can create a report. Almost all of the JSON that mochawesome consumes comes from mocha's runner.suite object. I haven't looked at what karma outputs but I would imagine its similar to mocha and so if you can transform karma's output into what the report generator expects, you can generate a report.

adamgruber avatar Jan 19 '17 01:01 adamgruber

@RobertWHurst can you post karma config here please.

chriseugenerodriguez avatar Jul 10 '17 22:07 chriseugenerodriguez

Anybody get this working yet? Would love to get this running in my project.

zachsteffens avatar Dec 13 '17 14:12 zachsteffens

For reference... and knowledge about this issus take a look here: Karma + Mocha + Reporter

Itee avatar Jun 19 '18 07:06 Itee

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 12 '19 13:05 stale[bot]