angular-cli: Angular Cli: 6.0.1 code coverage thresholds not failing ng test task
After upgrade to Angular Cli 6.x the code coverage thresholds enforced by the karma-coverage-istanbul-reporter do not make the testing command fail with emitWarning set to false as they used to when using Angular Cli 6.0.1.
Versions
Angular CLI: 6.0.1
Node: 8.9.1
OS: win32 x64
Angular: 6.0.1
... animations, cli, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.1
@angular-devkit/build-angular 0.6.1
@angular-devkit/build-optimizer 0.6.1
@angular-devkit/core 0.6.1
@angular-devkit/schematics 0.6.1
@ngtools/webpack 6.0.1
@schematics/angular 0.6.1
@schematics/update 0.6.1
rxjs 6.1.0
typescript 2.7.2
webpack 4.6.0
Repro steps
- Create a repo using Angular Cli 1.7.x
- Enforce thresholds
- See the test command failing
- Upgrade Angular Cli and migrate
Observed behavior
The error is emitted by the reporter, however seems ignored by the angular client.
Desired behavior
The test command should be failing when thresholds not met as it used to.
Mention any other details that might be useful (optional)
Tried with both karma@1.7.x and 2.x, reporter version 0.x and 1.x. Seems that stops working as soon as the upgrade of Angular Client is done. Same repo with Angular Client 1.7 behaves correctly.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 16
- Comments: 23 (1 by maintainers)
Found a fix for this:
Remove
coverage-istanbul
from yourreporters
array in karma.conf and it will use the correct exit code.It seems that
coverage-istanbul
is registered automatically whencodeCoverage
is set to true in your configuration and when it was being called twice it was causing issues.Same issue here, currently preventing our regular CI workflow from running as expected
After trying everything, I was able to make it work by upgrading
@angular-devkit/build-angular
to0.7.5
as per @alexw10 suggestion. My config looks like this:Also, don’t forget to set
singleRun
to false when running the tests with --code-coverage.@codeNoobie you need to install latest version of the:
"@angular-devkit/build-angular": "~0.7.1",
Same issue with the exit code being 0. The output:
And the
ng --version
output:We are running into the same issue. Status code of the
ng test --code-coverage
will always be 0. We are heavily relying on this feature in our local and CI environment.