angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Code coverage report issue with branch coverage (if path not taken)

Open Tataraovoleti opened this issue 8 years ago • 18 comments

Code coverage report showing if path not taken and else path not taken even though there are no if and else statements. This affecting the branch coverage.

cover

Angular version we are using is : 5.1.3 "@angular/cli": "1.6.0", "@angular/compiler-cli": "5.1.3",

Tataraovoleti avatar Jan 31 '18 11:01 Tataraovoleti

This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?

You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

filipesilva avatar Feb 01 '18 09:02 filipesilva

also just seeing this error now after upgrading to latest Angular and Angluar CLI. will try to create a sample repo if OP hasn't yet.

cherihung avatar Feb 12 '18 21:02 cherihung

I fixed this problem for my project. I upgraded my angular specific dependencies to the latest. And taking out --sm=false flag that I had to run test did the trick.

Once I took that flag out and ran test like so ng test --single-run --browsers ChromeHeadless --watch=false --cc The test coverage calculation went back correctly.

my project's dependencies versions FYI

"dependencies": {
    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19"
  },
"devDependencies": {
    "@angular/cli": "1.6.8",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }

cherihung avatar Feb 13 '18 22:02 cherihung

Hi all, We cross checked dependencies in package.json, there is a some issue with Jasmin what we used. Now working as expected.

Tataraovoleti avatar Feb 22 '18 08:02 Tataraovoleti

Closing as it seems to be sorted.

filipesilva avatar Feb 27 '18 20:02 filipesilva

@Tataraovoleti which version of Jasmine you changed it to make it work?

tahera49 avatar Jun 06 '18 16:06 tahera49

@filipesilva please reopen, this is not sorted.

stewones avatar Jul 26 '18 14:07 stewones

@filipesilva if you want to reproduce it, just create a new ng project and run ng test --code-coverage

Angular CLI: 6.1.0
Node: 9.11.1
OS: darwin x64
Angular: 6.1.0
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.7.0
@angular-devkit/build-angular     0.7.0
@angular-devkit/build-optimizer   0.7.0
@angular-devkit/build-webpack     0.7.0
@angular-devkit/core              0.7.0
@angular-devkit/schematics        0.7.0
@ngtools/webpack                  6.1.0
@schematics/angular               0.7.0
@schematics/update                0.7.0
rxjs                              6.2.2
typescript                        2.7.2
webpack                           4.9.2

stewones avatar Jul 26 '18 14:07 stewones

lol, worked with source map flag. 100% of branches are now covered.

For those who are also not getting good code coverage

just run:

ng test --source-map --code-coverage

stewones avatar Jul 30 '18 14:07 stewones

As @stewwan mentioned I found that setting the "sourceMap": true in angular.json fixed the issue for me. Thanks man!

perrosen avatar Aug 23 '18 01:08 perrosen

Oh good to know, I’ll do that too 🙂

stewones avatar Aug 23 '18 01:08 stewones

@stewwan I am even getting the same issue, i found my sourceMap:False in Angular.json. Do i need to make any changes as True for that so that my issue can be sloved?

svuppala10 avatar Sep 10 '18 17:09 svuppala10

screenshot-2018-9-10 code coverage report for src app report components total-applicants component ts

This is the issue which i have we are using angular 6

svuppala10 avatar Sep 10 '18 17:09 svuppala10

@stewwan 's suggestion worked.

ng test --source-map --code-coverage

vimalans avatar Nov 29 '18 23:11 vimalans

@stewwan Maybe check if that's not a false positive. If I run it with --source-map the branch coverage is 100% but the actual amount of branches is 0/0. So there is a little bit of sleight of hand going on. When I put it to --source-map=false then it gives the right values but the report is a bit mixed up.

marthinus-engelbrecht avatar Apr 13 '19 10:04 marthinus-engelbrecht

@filipesilva I'm still experiencing this issue.

I'm seeing the same issue @marthinus-engelbrecht is seeing when using angular-cli 8.0.0. When running tests on a Mac, setting --sourceMap true causes my coverage to pass when it should not (shows 0/0 branches) and setting it to false detects the lines but makes debugging difficult. On Linux, coverage reports are accurate regardless of the sourceMap flag value.

We would like to have the source maps for debugging purposes but also need accurate coverage reports.

Is there anything I'm missing that would cause reports to be different based on the platform they're running on?

jonasray-wf avatar Jul 09 '19 15:07 jonasray-wf

update: never seen it again since I moved to nx mono repositories which uses jest as test runner. cc @marthinus-engelbrecht

stewones avatar Aug 14 '19 03:08 stewones

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.