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

Thanks @brunolm image Because of above kinds of issue, I was going to apply this hack to everywhere lol. you saved my life.

webcat12345 avatar Oct 23 '17 19:10 webcat12345

@webcat12345 well, if you need to see real metrics it might be worth to attempt to do it. Currently there is no other way.

brunolm avatar Oct 23 '17 19:10 brunolm

do note @webcat12345 @brunolm when they add --aot support to ngtest then we'll be able to target es2015 from the resolved #7610 and it will fix everything for tests.

kenisteward avatar Oct 23 '17 19:10 kenisteward

With the release versions (Angular 5.0.0 and CLI 1.5) all coverage now appears perfect! image There was a transient remap problem due to something in RC 8 and/or possibly TS>2.4. Is everyone else's experience the same?

dinvlad avatar Nov 03 '17 00:11 dinvlad

@dinvlad that's somewhat surprising to me, because I haven't actually added any fixes in 1.5.0 for this. But maybe the change in compiler pipeline helped somehow, or one of the dependencies that does coverage had fixes in it.

Can you share if added any workarounds or modifications in your project to address the coverage problems?

filipesilva avatar Nov 03 '17 12:11 filipesilva

Now that I think about it, @hansl fixed a problem with sourcemaps in https://github.com/angular/angular-cli/pull/8230. Maybe that was the root cause of this issue in the first place.

Can other people confirm if your codeverage is now correct?

filipesilva avatar Nov 03 '17 12:11 filipesilva

@filipesilva - I can confirm it fixed the issue with constructors. I assume other similar issues were caused by the same thing.

I updated my test repo to Angular 5 and the coverage report is now correct: https://github.com/rg1220/angular-cli-coverage-issue-5526/tree/feature/update-to-angular-5 screen shot 2017-11-03 at 8 44 16 am

rg1220 avatar Nov 03 '17 12:11 rg1220

@filipesilva I just made sure that all tsconfig files are identical to the auto-generated ones from a new project. No workarounds at all.

dinvlad avatar Nov 03 '17 17:11 dinvlad

I'm using 4.4.6 until a library i'm using fixes a deprecated API. Just chiming in that CLI 1.5.0 and NG 4.4.6 does not correct it. I think you may have to specifically be on NG5.0

kenisteward avatar Nov 03 '17 20:11 kenisteward

I confirm that Angular 5 solves the problem. I move from:

  • angular 4.4.6 to 5.0.0
  • angular/cli 1.4.9 to 1.5.0
  • nguniversal 1.0.0-beta.3 to 5.0.0-beta.5
  • angular/flex-layout 2.0.0-beta.9 to 2.0.0-beta.10

on this project and I can reach 100% code coverage on branches now.

I did a code coverage with angular 4.4.6 and another one with angular 5.0.0 on the same code, and results are below:

angular 4.4.6: capture d ecran 2017-11-10 a 21 11 56

angular 5.0.0: capture d ecran 2017-11-10 a 21 03 04

f4nilo avatar Nov 05 '17 14:11 f4nilo

I upgraded to Angular 5 in a big project.

Almost everything worked without workarounds, there is just one scenario where it didn't work:

image

One of the tests for it:

it('calls setLocale', () => {
  spyOn(MomentDateAdapter.prototype, 'setLocale').and.callThrough();

  const adapter = new MomentDateAdapter();

  expect(adapter).toBeDefined();
  expect(MomentDateAdapter.prototype.setLocale).toHaveBeenCalledWith('pt-BR');
});

That's the only thing that didn't work for me.

Great job, Angular 5 is awesome :)

brunolm avatar Nov 05 '17 18:11 brunolm

I'm still experiencing the constructor issue when using Jest with Angular 5.0 and jest-angular-preset. Setting tsconfig.spec.json target to es6 does not seem to have any effect.

laxu avatar Nov 15 '17 14:11 laxu

Also still experiencing this issue event after moving to angular 5. Its even highlighting comments as not being tests :(

el-davo avatar Nov 15 '17 17:11 el-davo

@el-davo @laxu did you also upgrade to click 1.5.0?

kenisteward avatar Nov 15 '17 17:11 kenisteward

Am completely wrong, it seems I had -sm set to false which was completely throwing the coverage off. My bad, Angular 5 FTW!! :dancer:

el-davo avatar Nov 15 '17 17:11 el-davo

@kenisteward Yup, cli is 1.5.0 too.

laxu avatar Nov 16 '17 08:11 laxu

@filipesilva I can confirm after upgrading to Angular 5 and CLI 1.5.0 I also got full coverage for the constructors when before i was getting issues.

I'm targeting the default es5 that the cli generates

kenisteward avatar Nov 21 '17 18:11 kenisteward

@laxu did you find a solution for that issue with jest? I'm facing the same issue :(

Brototype avatar Nov 28 '17 13:11 Brototype

@Brototype Unfortunately no. In the mean time you have to either use the /* istanbul ignore next */ workaround or lower branch coverage to account for the issue.

laxu avatar Nov 29 '17 10:11 laxu

I'm closing as it seems this is fixed with 1.5.

filipesilva avatar Dec 07 '17 15:12 filipesilva