Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage rate is incorrect when some code fragments are ignored #218

Open
hanhongfang opened this issue Jul 9, 2014 · 11 comments
Open

Coverage rate is incorrect when some code fragments are ignored #218

hanhongfang opened this issue Jul 9, 2014 · 11 comments

Comments

@hanhongfang
Copy link

Hi dev,

I'm using /istanbul ignore next/ to ignore some code fragments. For example, I totally have 1000 lines, and I ignore 900 lines. I have unit tests which covered 50 lines of the left 100 lines. Currently istanbul reports coverage rate as 950 / 1000 = 95%, which takes the 900 lines being ignored as tested. But I think the coverage rate should focus on the left 100 lines only. Within the left 100 lines, only 50 lines are tested, thus the coverage rate should be 50%. [In my case, 900 lines are library, which is built into a combined single javascript file with my code, but testing to the library is not my purpose.]

Is there any configuration that I can use to make istanbul calculate the rate as I expected?

Best regards,
Janet Han

@gotwarlost
Copy link
Owner

No. Let me think about this some more.

@shuhrat
Copy link

shuhrat commented Nov 21, 2014

+1

Facing with the same problem, I'm using some libraries that have their own tests and not needed to be tested. I have 2 modes of compilation. In dev mode i just require the libraries, in production mode, just inline them. These libraries are excluded from instrumenting(in configuration file), and added istanbul ignore comments to the head of each library before inlining. Unfortunately code coverage report is different in each mode of compilation.
@hanhongfang explained the problem very well.

@nataschachu
Copy link

+1

@andre487
Copy link

+1 Same problem: in the different build modes there is a different coverage report.

@anton-rudeshko
Copy link

We definitely need more options to handle ignored code.

@mishanga
Copy link

same thing

@abelmokadem
Copy link

+1 Is there an update on this?

@technicallyfeasible
Copy link

Agreed, I have some boilerplate code that is autogenerated by a babel transpile and is obviously not my code. When I ignore it I would expect this not to be set to "1" or even more if it is actually hit but instead be removed from the baseline coverage and only the rest of the code count towards testable lines.
Here's an example image:
istanbul_coverage

@ghost
Copy link

ghost commented Oct 22, 2015

I have a similar scenario to @technicallyfeasible

@hopeson
Copy link

hopeson commented Oct 23, 2015

+1

@technicallyfeasible
Copy link

I ended up creating a patch that I include before my tests:

https://gist.github.com/technicallyfeasible/5f066d323ddf608e3cac

This modifies the computeBranchTotals and computeSimpleTotals functions to report only stats which were not excluded.

Simply do require('patch_istanbul') before getting the test run totals or generating the report.

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

No branches or pull requests

10 participants