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

Bug: Code Coverage Report

Open niklas-wortmann opened this issue 9 years ago • 74 comments

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

$ ng --version @angular/cli: 1.0.0-rc.2 node: 6.9.5 os: win32 x64 @angular/common: 4.0.0-rc.5 @angular/compiler: 4.0.0-rc.5 @angular/core: 4.0.0-rc.5 @angular/forms: 4.0.0-rc.5 @angular/http: 4.0.0-rc.5 @angular/platform-browser: 4.0.0-rc.5 @angular/platform-browser-dynamic: 4.0.0-rc.5 @angular/router: 4.0.0-rc.5 @angular/cli: 1.0.0-rc.2 @angular/compiler-cli: 4.0.0-rc.5

Repro steps.

I have made a sample project, to reproduce this weird behaviour. Please take a look at: https://github.com/Loster102/angular-coverage-sample When I run 'ng test -cc true', there is a successful testrun. But when I look at the coverage report, the branch coverage is really strange. It says, that the constructor is not fully covered. sample

Desired functionality.

I would have expected that even the constructor is fully covered.

Mention any other details that might be useful.

In my real world application, there are some further strange behaviours, exactly like the one above. I try to reproduce these in the sample project. In this application, I'm using [email protected] and @angular/[email protected].

niklas-wortmann avatar Mar 20 '17 20:03 niklas-wortmann

I resolved it by running the unit test environment in full privileged mode

ghost avatar Feb 12 '18 15:02 ghost

Hey guys ! So de we know how Angular 5 fixed this issue... ? :-P

otroboe avatar Feb 20 '18 17:02 otroboe

Yeah has to do with the annotations now being parsed as typescript transformations instead. I'll try to find the article but it now doesn't put the same ternary operators which were found in the code coverage for constructors and input/outputs

On Tue, Feb 20, 2018, 12:42 PM otroboe [email protected] wrote:

Hey guys ! So de we know how Angular 5 fixed this issue... ? :-P

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/5526#issuecomment-367058155, or mute the thread https://github.com/notifications/unsubscribe-auth/AMPLtSEh5oxmc3taE5JVdrBecojU8jBsks5tWwQdgaJpZM4Mi9tY .

kenisteward avatar Feb 20 '18 17:02 kenisteward

@laxu have you fix this when using jest????

vigohe avatar Feb 22 '18 06:02 vigohe

For me with Jest 22.3.0, I just added this property in my jest.json config file:

{
  ...
  "mapCoverage": true
}

otroboe avatar Feb 22 '18 13:02 otroboe

@vigohe I experience the same issue with Jest. @otroboe the option mapCoverage doesn't help. It was also removed in Jest 22.4 @filipesilva can you tell us exactly what was the fix in Angular 5 ?

ahnpnl avatar Mar 04 '18 01:03 ahnpnl

I don't believe that jest is covered by the cli. In which case this doesn't belong here but on stack overflow.

On Sat, Mar 3, 2018, 8:33 PM Ahn [email protected] wrote:

@otroboe https://github.com/otroboe Angular 5 fixed the issue but only when testing with karma + jasmine, with Jest I also experience the same issue. @filipesilva https://github.com/filipesilva can you tell us exactly what was the fix in Angular 5 ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/5526#issuecomment-370194403, or mute the thread https://github.com/notifications/unsubscribe-auth/AMPLtUKPtuq-KCUr64POpqXwqLIUEJjbks5ta0R1gaJpZM4Mi9tY .

kenisteward avatar Mar 04 '18 01:03 kenisteward

+1

ggarbereder avatar Mar 07 '18 14:03 ggarbereder

It seems most of the issues are solved nevertheless we are still experiencing same issue like @brunolm mentioned image

mboughaba avatar Mar 16 '18 12:03 mboughaba

We are experiencing this in our project with constructors and decorators. Running angular 5.2.8, angular-cli 1.7.3, jasmine 3.1.0 running with karma.

kellycrowther avatar Mar 16 '18 15:03 kellycrowther

I resolve the problem by targetting es6 in tsconfig.spec.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "baseUrl": "./",
    "module": "commonjs",
    "target": "es6",
    "types": ["jasmine", "node"]
  },
  "files": ["test.ts"],
  "include": ["**/*.spec.ts", "**/*.d.ts"]
}

roupify avatar Mar 20 '18 17:03 roupify

Just make sure that you have sourcemaps turned on for your tests and coverage will work fine.

macbem avatar Mar 21 '18 13:03 macbem

@macbem Not the case for me, I experience this problem with and without sm flag.

mboughaba avatar Mar 21 '18 20:03 mboughaba

Thanks for the suggestions @macbem and @rousseaufiliong. I previously tried those suggestions along with the other suggestions in this thread like adding /* istanbul ignore next */ and I tried again today for good measure but still find coverage is low for branches because of constructors and decorators. Hopeful an update solves this for our project

kellycrowther avatar Mar 23 '18 16:03 kellycrowther

Is a fix on the way?

tedp avatar Mar 27 '18 09:03 tedp

I experience this problem with having source maps turned off for testing.

victormejia avatar Apr 02 '18 22:04 victormejia

@filipesilva with version 1.7.4 the problem continues :(

rafaelnery avatar Apr 10 '18 13:04 rafaelnery

We're also still seeing the same problem, Angular 5.2.6, Jest 22.4.3 and Jest Angular Preset 5.2.2. For whatever reason, it's not all the time, but there are issues where some of the params in a constructor will be uncovered. It doesn't seem to make a lot of sense, because it's not consistent.

mcblum avatar Jun 12 '18 19:06 mcblum

Also seeing this behaviour as described by @mcblum

soates avatar Jun 15 '18 07:06 soates

indeed, after adding --sourcemaps=false coverage started giving wrong numbers (cli 1.7.4, target es5). When you remove it, coverage is ok.

screenshot from 2018-06-20 10-55-28

dimitriy-k avatar Jun 20 '18 09:06 dimitriy-k