Hi there, just wondering if it's possible to use a babel compiler with mocha and still have istanbul generate coverage statistics. At the moment this is my test script
./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --compilers js:babel/register --recursive specs
But i get the error
Error: cannot resolve path (or pattern) 'js:babel/register'
Tests run fine if I remove istanbul from the command. Any ideas?
You should use the -- separator to tell istanbul to pass the remaining args to mocha:
https://github.com/gotwarlost/istanbul#the-cover-command
Yep, like this: istanbul cover _mocha -- --require babel/register
@davglass @iamstarkov I cannot get istanbul to produce coverage report on source file instead of the babeled file. any Idea??
@nilveryawesome its impossible, try isparta!!!11 or ask on stackoverflow. Is it helpful??
Struggling with this as well, but I can share some things that do and do not work.
Does not work
Using -r babel-register with istanbul gives the dreaded "No coverage information was collected," error likely because istanbul's require hook is wiped out by babel's require hook .
node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha — -r babel-register -R dot --recursive tests/unit/lib
Does not work
Using --compilers with the js:babel-register does the exact same thing as above. We're left with the No coverage information was collection message.
./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- --recursive tests/unit/lib --compilers js:babel-register
Almost Works
This command shows a coverage report, but shows incorrect coverage numbers. Further investigation shows the hooks are in place properly for coverage, but mocha still chokes on the es6 code and fails.
babel-node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R dot --recursive tests/unit/lib
Almost Works
Swapping istanbul for isparta however seems to cause the coverage report to die pre-maturely without an error message.
node ./node_modules/.bin/isparta cover ./node_modules/mocha/bin/_mocha -- -R dot --recursive tests/unit/
Works
Calling isparta with babel-node solves the problem of coverage not being reported and failing with unknown syntax.
babel-node ./node_modules/.bin/isparta cover ./node_modules/mocha/bin/_mocha -- -R dot --recursive tests/unit/
@jladuval did you find a solution?
This seems to work for me: ./node_modules/istanbul/lib/cli.js cover --dir=./coverage/unit ./node_modules/mocha/bin/_mocha -- --recursive test/unit --compilers js:babel/register -R spec
ps: --dir= is optional
@brunops sorry dude, added that to my does not work list above. Same issue as before. Somehow the babel compiler over-rides the istanbul compiler and it doesn't instrument anything. I wonder if this is a babel6 thing.
Maybe. I'm using babel 5.8.23, istanbul 0.3.22 and mocha 3.2.4.
Sorry guys just got alerted that this is still open! The -- fix worked fine, thanks for everyones help
Most helpful comment
You should use the
--separator to tellistanbulto pass the remaining args tomocha:https://github.com/gotwarlost/istanbul#the-cover-command