gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 787 forks source link

Ignored branches in code not incrementing the taken field for branches in the lcov.info #851

Open deanml opened 6 years ago

deanml commented 6 years ago

for example: If you ignore a branch in the following code snippet (lets say the if statement is line 44):

/ istanbul ignore next / app.get('/quote/:id', function(req, res) { if(quotes.length <= req.params.id || req.params.id < 0) { res.statusCode = 404; return res.json('Error 404: No quote found'); }

Run a coverage session and istanbul properly shows the statements and branches as being ignored:

Statements : 95.12% ( 39/41 ), 5 ignored Branches : 93.75% ( 15/16 ), 4 ignored Functions : 100% ( 6/6 ), 1 ignored Lines : 95.12% ( 39/41 )

However if you are outputting to lcov file, you will see that the branch is never marked as taken:

BRDA:44,1,0,0 BRDA:44,1,1,0 BRDA:44,2,0,0 BRDA:44,2,1,0

Ignored code for branches should be marked as taken.

According to the lcov documentation, the BRDA format is described as follows: Branch coverage information is stored with one line per branch: BRDA:line number,block number,branch number,taken