Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Uncovered branch which is created from babel #549

Open
lo1tuma opened this issue Feb 26, 2016 · 1 comment
Open

Uncovered branch which is created from babel #549

lo1tuma opened this issue Feb 26, 2016 · 1 comment

Comments

@lo1tuma
Copy link

lo1tuma commented Feb 26, 2016

I’m using istanbul 1.0.0-alpha 2 with babel 6.5.0 in the same way as sample-mocha-compilers.

I’ve noticed a bug where istanbul reports an uncovered branch which is not visible in the HTML report. After some debugging and looking at the transpiled code from babel I was able to create a minimal reproducible example based on sample-mocha-compilers.

The example can be found here: https://github.com/lo1tuma/sample-mocha-compilers/tree/issue-inline-ternary.

babel-plugin-transform-es2015-typeof-symbol transforms a typeof expression to a ternary which causes additional branches.

For example:

typeof bar === 'object'

will be transpiled to

(typeof bar === 'undefined' ? 'undefined' : _typeof(bar)) === 'object'

It seems like istanbul doesn’t recognise that this code was generated by babel and reports that one of the branches in the ternary isn’t covered.

Here is the screenshot of the HTML report of the example mentioned above:

screen shot 2016-02-26 at 21 47 24

As you can see the generated code isn’t visible anymore and according to the line-coverage every branch was taken.

@savcni01
Copy link

@lo1tuma You can just provide it tests two variants of maybeObj:
maybeObj = undefined
maybeObj = 'string'
then
typeof maybeObj === 'object'
will run both branches hidden at babel replacement of typeof

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants