Charlie Fish Charlie Fish - 1 year ago 121
Node.js Question

Node.js Istanbul/Mocha Unit Tests not printing details

I'm trying to use Istanbul along with Mocha in Node.js to run unit tests and generate code coverage reports. I'm using the following code to run run the unit tests and generate those code reports.

istanbul cover _mocha -- -R tap 'test/*.test.js' > test.tap; istanbul report clover

If I just want to run unit tests without code coverage reports I can just run the following.


Both of these methods work fine. But the first method doesn't really print anything to the console. I have no idea which unit test it is currently running and when it's all complete I have no idea what exactly went wrong. It doesn't provide any form of error logs or anything. The second method prints the status of that certain unit test after each test so it's easy in the console to see exactly what unit test you are currently working on and after all tests are complete it gives you details and error logs about why they failed so you can start to debug. The first method doesn't provide any of this.

Is there anyway to generate code coverage reports using Istanbul but have it print all the details to the console that just running
prints? If so how can I achieve this? Some of my tests take a little bit to run and finish so when generating code coverage reports with Istanbul it would be nice to see exactly what test it's currently on and more detail about the test in real time.

Answer Source

Your istanbul command redirects the output to test.tap, so you are not going to see it on the console:

istanbul cover _mocha -- -R tap 'test/*.test.js' > test.tap; istanbul report clover

The test output in test.tap is not needed by Istanbul, so you could remove the redirection. If you want the command to continue writing the file, you could use the tee command to write the test output to both the file and the console.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download