Coverage reports 'Else path not taken' when there is no else path to take using ES6 imports
See original GitHub issueI’m not sure if this is a bug with babel-plugin-istanbul (if it’s best to post there just let me know), nyc or just a misconfiguration issue I’ve missed, but when setting up a new project I’ve now encountered the following:
Expected Behavior
Coverage should report 100% when using ES6 imports for the test code below.
Observed Behavior
See the images, but the reporter seems to think that there are else branches when there isn’t any. It also says the statement is not covered.
Bonus Points! Code (or Repository) that Reproduces Issue
This is using ES6 imports:
// index.js
export function test() {
return 'test';
}
// index.test.js
import { expect } from 'chai';
import { test } from './test';
describe('foo', () => {
it('should say test', () => {
expect(test()).to.equal('test');
});
});
Produces the following:
It also happens if you use default exports.
For module.exports, coverage is correct
// index.js - module.exports
module.exports function test() {
return 'test';
}
//index.test.js
import { expect } from 'chai';
const test = require('./test');
describe('test', () => {
it('should say test', () => {
expect(test()).to.equal('test');
});
});
Forensic Information
Operating System: Windows 10 Environment Information: npm : 6.0.1 node : 10.1.0 nyc : 12.02 babel-plugin-istanbul : 4.1.6
This is the .babelrc.js
module.exports = {
presets: [
['@babel/preset-env'],
['@babel/stage-0', { decoratorsLegacy: true }],
'@babel/preset-react'
],
plugins: ['react-hot-loader/babel'],
retainLines: true,
sourceMaps: true,
env: {
test: {
presets: [['@babel/preset-env', { modules: false }]],
plugins: [['istanbul']]
}
}
};
and this is the .nycrc:
{
"check-coverage": true,
"per-file": true,
"include": [
"./src/**/*.js"
],
"reporter": [
"lcov",
"text"
],
"cache": false,
"all": false,
"instruments" : false,
"sourceMap": false
}
I’ve also tried adding the instruments and sourceMap options to my package.json but that just causes the coverage to report back as empty. I’m using Mocha as my test runner.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:9 (1 by maintainers)
Top GitHub Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I have this same issue with vanilla node code… no exports, no transpiling. I confirmed without a doubt that the if path is taken (my tests wouldn’t pass otherwise, but I also threw in a console.log to ensure I wasn’t crazy).