Bug: Code Coverage Report
- [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.
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].
Thanks @brunolm
Because of above kinds of issue, I was going to apply this hack to everywhere lol. you saved my life.
@webcat12345 well, if you need to see real metrics it might be worth to attempt to do it. Currently there is no other way.
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.
With the release versions (Angular 5.0.0 and CLI 1.5) all coverage now appears perfect!
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 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?
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 - 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

@filipesilva I just made sure that all tsconfig files are identical to the auto-generated ones from a new project. No workarounds at all.
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
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:

angular 5.0.0:

I upgraded to Angular 5 in a big project.
Almost everything worked without workarounds, there is just one scenario where it didn't work:

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 :)
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.
Also still experiencing this issue event after moving to angular 5. Its even highlighting comments as not being tests :(
@el-davo @laxu did you also upgrade to click 1.5.0?
Am completely wrong, it seems I had -sm set to false which was completely throwing the coverage off. My bad, Angular 5 FTW!! :dancer:
@kenisteward Yup, cli is 1.5.0 too.
@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
@laxu did you find a solution for that issue with jest? I'm facing the same issue :(
@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.
I'm closing as it seems this is fixed with 1.5.