There is a known bug when using Babel with Istanbul (NYC) that when you run coverage it displays coverage problems with
else path not taken
For example, in my case, I had:
1 import sequelize from Sequelize
and running coverage result with:
1 else path not taken
It usually happens if you have in your babel.config.json the following:
and when you remove them the coverage jumps back with no coverage issues?
I found few non helpful solutions for this case:
- To remove the sourceMaps and retainLines (which I didn’t wanted).
- To use
or1/* istanbul ignore next */which didn’t worked1/* istanbul ignore else */
- To add
to Babel configuration which didn’t worked for me.1auxiliaryCommentBefore: ' istanbul ignore next '
The solution I found to be the best is to use the babel plugin:
install it using
npm i --save-dev babel-plugin-istanbul
Then, add the following to your
and last, update your package.json script to run coverage with BABEL_ENV variable set to
"coverage": "cross-env BABEL_ENV=test nyc npm run test -s",
And now the coverage working perfectly with sourceMaps and retainLines!!!