direct-adv-interfaces / mocha-headless-chrome

Run client-side mocha tests in the command line through headless Chrome.
MIT License
95 stars 34 forks source link

Test result is not saved in the format of the reporter. #26

Open dietergeerts opened 6 years ago

dietergeerts commented 6 years ago

I was expecting to see the reporter output when using --out, but that's not the case. I use xunit reporter, and I see the xml in the terminal, but the file which save the results is a json object:

console:

<testsuite name="Mocha Tests" tests="1" failures="0" errors="0" skipped="0" timestamp="Wed, 13 Jun 2018 08:37:18 GMT" time="0.017">
<testcase classname="Button" name="must render a button with given content as label" time="0.014"/>
</testsuite>

saved file:

{"stats":{"tests":1,"passes":1,"pending":0,"failures":0,"start":"2018-06-13T08:37:18.093Z","end":"2018-06-13T08:37:18.110Z","duration":17},"tests":[{"title":"must render a button with given content as label","fullTitle":"Button must render a button with given content as label","duration":14,"err":{}}],"pending":[],"failures":[],"passes":[{"title":"must render a button with given content as label","fullTitle":"Button must render a button with given content as label","duration":14,"err":{}}]}
TeknoFiend commented 4 years ago

Old issue but... I looked into fixing this and it's not simple unfortunately. mocha-headless-chrome is attaching to the mocha instance running in the browser and setting it's reporter to whatever is specified on the command line. So the reporter instance is running in the browser which is not supported by mocha (https://mochajs.org/#options-that-differ-slightly-from-cli-options). And each reporter is responsible for producing the report file (there's not abstraction for the reporter tell mocha "here's my data") so there's no place to hook in to that data and pass it back to mocha-headless-chrome, you'd have to "fix" each reporter.

The reason it kinda works (structured report info in the terminal output) is that most reporters also do some form of console.log and mocha-headless-chrome is already grabbing all the browser console lines and outputting them to the terminal. But because there is other info intermixed (like warnings, errors, etc) it would not be easy or reliable to try to just get the report data.

The only solution I see is to have a special mocha-headless-chrome reporter that works like the JSONStream reporter (just logs each test event in JSON form) except that it builds the JSON up in browser memory (in a global variable) so Puppeteer+mocha-headless-chrome can pull it out. Then mocha-headless-chrome would have to support the reporter API (ie call them directly just like mocha does) and generate the events that the reporter is expecting from the JSON data.