Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude function (not an entire file) from JavaScript code coverage

I'm creating some unit tests with Jasmine and the test runner I'm using is Karma. I'm also checking the code coverage of these test specs with the karma-coverage plugin.

I was wondering if there's any way of excluding certain functions from the code coverage itself and also from the Karma report (Istanbul actually). I'm thinking that if the first one is solved then so is the second.

Pretty sure there's no obvious way of doing this, as I've looked in Istanbul as well (karma-coverage uses it) but maybe some of you run into this before.

like image 894
Marcel N. Avatar asked Dec 18 '13 12:12

Marcel N.


People also ask

How do you exclude files from code coverage?

To exclude test code from the code coverage results and only include application code, add the ExcludeFromCodeCoverageAttribute attribute to your test class.

What is code coverage in JavaScript?

Code coverage provides information about whether, and optionally how often certain parts of an application have been executed. It's commonly used to determine how thoroughly a test suite exercises a particular codebase.


1 Answers

It appears that the guy behind Istanbul has added support for ignoring specific sections of code from coverage analysis. Really useful!

More here: https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md

like image 91
Marcel N. Avatar answered Oct 23 '22 20:10

Marcel N.