ES6 React istanbul Coverage information was not collected, exit without recording coverage information

I have a problem running my tests, code coverage does not work, I have a message

Coverage information was not collected; exit without recording coverage information

I am writing my tests using ES6 and I am using babel to convert the code.

To solve the problem, I'm using the github project presented 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

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

This works well, but the problem is that the code coverage only takes into account the classes that you tested, and not all the classes you created.

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

I tried adding cover -x 'src/js/__tests__/**/*.test.js' but it does not work. I can’t mix the first style with the second.

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

Is there another trick for properly covering code using ES6 / mocha and calling mocha babel-core/register ?

+5
source share
1 answer

I also ran into the same problem, but this github issue was well managed. Hope you can use the use of istanbul@1.0.0-alpha.2 , which solved the problem for me.

and my team is as follows: istanbul cover --dir ./coverage _mocha -- ./tests/**/**/*.js --opts ./tests/mocha.opts -R spec

+7
source

Source: https://habr.com/ru/post/1239532/


All Articles