node.jssonarqubemocha.jsnycmochawesome

How to use mochawesome and mocha-sonarqube-report in a single command?


I have the following script in my package.json file to check the code coverage of the UT:

"coverage": "nyc --reporter=lcov --reporter=cobertura mocha ./test/apis_new/* --reporter mocha-sonarqube-reporter --reporter-options output=xunit.xml mocha ./test/apis_new/* --reporter mochawesome --exit"

When I run the above command, only mochawesome-report folder is getting generated but there is no such file as xunit.xml.

If I run the bellow command where I have changed the order of mochawesome and sonarqube, xunit.xml is geting generated but not mochawesome-report folder:

"coverage": "nyc --reporter=lcov --reporter=cobertura mocha ./test/apis_new/* --reporter mochawesome mocha ./test/apis_new/* --reporter mocha-sonarqube-reporter --reporter-options output=xunit.xml --exit"

What am I doing wrong? Is this the right way to use both together in a single script?


Solution

  • Natively, mocha supports only one reporter, so all behaves as expected only one of reporters (possibly first) is used.

    Check out mocha-multi-reporters. I use it to generate xunit and spec output.