angular-cli: ng test --code-coverage in 6.1 improperly detecting branches
Bug Report or Feature Request (mark with an x
)
- [ X ] bug report -> please search issues before submitting
- [ ] feature request
Command (mark with an x
)
- [ ] new
- [ ] build
- [ ] serve
- [ X ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc
Versions
OS: macOS Sierra Node: v8.9.4 NPM: 6.2.0
Ng Version:
Angular CLI: 6.1.0
Node: 8.9.4
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
@angular/cdk 6.4.1
@angular/flex-layout 6.0.0-beta.16
@angular/material 6.4.1
@ngtools/webpack 6.1.0
@schematics/angular 0.7.0
@schematics/update 0.7.0
rxjs 6.2.2
typescript 2.9.2
webpack 4.9.2
Repro steps
Run ng test --code-coverage
Notice that things like import statements are counted as if else branches.
The log given by the failure
No log file
Desired functionality
I expect to see things like import statements and decorator metadata to not be marked as if else branches in the code coverage report.
Mention any other details that might be useful
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 38
- Comments: 35 (1 by maintainers)
Commits related to this issue
- Temp fix to incorrect detection of if else branches in code coverage See angular cli regression: https://github.com/angular/angular-cli/issues/11672 — committed to drumonii/LeagueTrollBuild by drumonii 6 years ago
- Temp fix to incorrect detection of if else branches in code coverage See angular cli regression: https://github.com/angular/angular-cli/issues/11672 — committed to drumonii/LeagueTrollBuild by drumonii 6 years ago
- Temp fix to incorrect detection of if else branches in code coverage See angular cli regression: https://github.com/angular/angular-cli/issues/11672 — committed to drumonii/LeagueTrollBuild by drumonii 6 years ago
- Temporary fix for https://github.com/angular/angular-cli/issues/11672 — committed to mpalourdio/ng-http-loader by mpalourdio 6 years ago
- fix(@angular-devkit/schematics): enable sourceMap for coverage mapping Fixes #11672 — committed to bitjson/angular-cli by bitjson 6 years ago
- Add --source-map test param as a workaround for broken test coverage The code coverage generated by ng test was erroneous, as per https://github.com/angular/angular-cli/issues/11672 I'm passing in --s... — committed to pfbrowning/ng-loading-indicator by pfbrowning 6 years ago
Maybe it’s the way that the sourceMaps are handled. If I add “sourceMap”: true, in the test section, with @angular-devkit/build-angular 0.7.0 it seems to work.
See: https://stackoverflow.com/questions/51257459/if-else-path-not-taken-in-imports-in-angular-istanbul-code-coverage-report/51676221#51676221
I was able to fix the issue by adding
"sourceMap": true,
inangular.json
test section.DevDependency versions are,
we’re planning a bug bash sprint starting in 1.5 weeks; as a P1 this issue will be on it.
In my case passing the
sourceMap
flag via CLI did fix the issue (ng test --source-map
) while setting it intsconfig.json
didn’t seem to have any effect.I am still having the same issue with all dependencies completely up to date
I can confirm this issue. And I can confirm that running it using
ng test --code-coverage --source-map
solves the issue.Here’s my
ng -v
output:Thought it might be worth noting that I’m still seeing this issue… I’m currently using Angular 6.2.7 I currently have “@angular-devkit/build-angular”: “~0.8.7”,
After adding
"sourceMap": true
to myangular.json
test options, checking that it was included in tsconfig.json, and manually trying to runng test --code-coverage=true --watch=false --source-map=true
I still have had zero success getting code coverage working and detecting branches properly.Just had the same problem start happening to me,
@lanegoolsby 's solution worked out for me, didn’t have to add anything into the CLI commands, just the
angular.json
file editFor anyone here from Google, I may have found a more permanent fix than using the CLI flag. Set “sourceMap”: true in angular.json under projects -> [yourProject] -> architect -> test -> options.
Making the change in the tsconfig.spec.json or tsconfig.json had no effect for me.
My environment:
Also confirm running ng test --code-coverage --source-map solves this, despite all settings being set to sourceMap:true. Of course, this advice conflicts with the advice given in #11968. 😞
Same issue as @frankrue - setting sourcemap to true did not resolve the issue.
EDIT: A bit more clarification - it does not work for libraries generated with Angular CLI 6. sourceMap option was added to angular.json and all tsconfig files.
I can confirm that setting
sourceMap: true
fixed the issue for me I am on0.7.2
@brian428 @jfpicard1 Guessing this shouldn’t need to be on since it worked without it before?Had the same problem after upgrading to cli 6.1.1 + devkit 0.7.1. Fixed by downgrading
@angular-devkit/build-angular
to 0.6.8Before (with coverage issues):
After (coverage working properly again):