question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coverage reports 'Else path not taken' when there is no else path to take using ES6 imports

See original GitHub issue

I’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:

capture - imports

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');
    });
});

capture - module

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:open
  • Created 5 years ago
  • Reactions:8
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

44reactions
stale[bot]commented, Jan 5, 2019

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.

1reaction
th317erdcommented, May 25, 2022

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).

if (this.roles) {
        roles = this.roles.map((role) => {
          if (typeof role === 'string')
            return role;
          else if (role instanceof Role) // <<----- claims that this else path is never taken... but it most certainly is!
            return role.name;
        });
      }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Coverage reports 'Else path not taken' when there is no else ...
Coverage should report 100% when using ES6 imports for the test code below. Observed Behavior. See the images, but the reporter seems to...
Read more >
else path not taken in unit testing - angular - Stack Overflow
But I am unable to cover branches due to else path not taken . What I need to do to get 100% branch...
Read more >
NYC Istanbul 'else path not taken' from import node_modules
There is a known bug when using Babel with Istanbul (NYC) that when you run coverage it displays coverage problems with else path...
Read more >
Angularjs: Jasmine-Karma Statement(If Else Path Not Taken)
Code coverage report issue with branch coverage (if path not taken). ... there is no else path to Coverage should report 100% when...
Read more >
Exports defaults else path not taken with Jest and ES6-Reactjs
The problem was in the jest configuration, we were using a preprocessor in order to resolve some imports: In the package json we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found