Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 React istanbul No coverage information was collected, exit without writing coverage information

I have an issue when running my tests the code coverage doesn't work, I have the message

No coverage information was collected, exit without writing coverage information

I write my tests using ES6 and I use babel to transform the code.

To solve the problem I use the github project provided in this discussion: https://github.com/gotwarlost/istanbul/issues/496

The trick is to use

`babel-node ./node_modules/istanbul/lib/cli cover node_modules/mocha/bin/_mocha -- --require test-helper.js --bail --recursive 'src/js/__tests__/**/*.test.js'` 

instead of

"istanbul cover node_modules/mocha/bin/_mocha -- --compilers js:babel-core/register --require scripts/test-helper.js --recursive 'src/js/__tests__/**/*.test.js'"

It works well but the problem is that the code coverage is only considering the classes you have tested, not all the classes you created.

If I add a new class mod.js in the src folder of the project, the coverage is 100% for the app.js component. This is logical because it is fully tested but in the report the mod.js class doesn't appear on the report - it is not listed as class with 0% tested (https://github.com/JakeSidSmith/istanbul-no-coverage).

I tried to add the cover -x 'src/js/__tests__/**/*.test.js' but doesn't work. I cannot mix mix the first style with the second.

Another problem is that in the project example provided above the test-helper.js is considered as fully tested and i cannot exclude it from the coverage using cover -x .

Is there another trick to have right code coverage using ES6/mocha and having mocha call babel-core/register?

like image 411
Aaleks Avatar asked Dec 30 '15 23:12

Aaleks


1 Answers

I also faced the same problem but this github issue guided well. I hope you can use use [email protected] which solved the problem for me.

and my command goes like this istanbul cover --dir ./coverage _mocha -- ./tests/**/**/*.js --opts ./tests/mocha.opts -R spec

like image 97
sam Avatar answered Sep 23 '22 05:09

sam