New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test Coverage Integration? #883
Comments
For fun, I decided to try and get this working in a test project. I was able to get things working with Caveats:
My modified
To get the remap working, I used the following. You may need to change the numbers up depending on your browser.
|
After playing with it a bit more, I got this working on Caveats:
|
Where did we land with this? I see that the issue is closed but I can't really tell what the conclusion is. |
+1 |
Code coverage was added via #1455. |
How can I run the code coverage tool? When I run "ng help" I can't tell what command I need to run? |
It should run when you run |
Actually it was changed to only run when doing |
Do you know, how to enable this automatically? So defining this parameter somehow in angular-cli.json or something like that. And how to force WebStorm to create coverage when I am using Karma task with the root karma configuration? |
Is there a way to make the tests fail if the coverage falls before a threshold? |
The CLI lets you have code coverage stats with There is no nothing builtin in the CLI for failing if the coverage is below a threshold, but that's quite easy to set up. Start by installing it : Edit your plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
+ require('karma-istanbul-threshold'),
require('@angular/cli/plugins/karma')
],
// ...
coverageIstanbulReporter: {
- reports: ['html'],
+ reports: ['html', 'json'],
fixWebpackSourcePaths: true
},
// ...
+ istanbulThresholdReporter: {
+ src: 'coverage/coverage-final.json',
+ reporters: ['text'],
+ thresholds: {
+ global: {
+ statements: 90,
+ branches: 90,
+ lines: 70,
+ functions: 90,
+ },
+ each: {
+ statements: 80,
+ branches: 80,
+ lines: 60,
+ functions: 80,
+ },
+ }
+ },
// ...
reporters: config.angularCli && config.angularCli.codeCoverage
- ? ['progress', 'coverage-istanbul']
+ ? ['progress', 'coverage-istanbul', 'istanbul-threshold'] Then launch your test with Low Coverage: GLOBAL 44.83% of 70% lines
Low Coverage: GLOBAL 48.6% of 90% statements
Low Coverage: GLOBAL 2.2% of 90% functions
Low Coverage: GLOBAL 51.35% of 90% branches
Low Coverage: src/app/app.component.ts 62.07% of 80% statements
Low Coverage: src/app/app.component.ts 22.22% of 80% functions |
@cexbrayat I did all the step you described using Angular CLI 1.0, but I did not get the same result as you show below. Is there any configuration I need to do?
Thanks. |
@marciomsm The results will depend on how many unit tests you have in your application (see code coverage) |
Hi @cexbrayat, what I wanted say is that I didn't get the percentage information after to configure as you explained. I mean, I didn't get the below information. Low Coverage: GLOBAL X% of X% lines |
Well, It works on several of our apps, and it seems like some people 👍 it so I guess it should work for you too. Read carefully my previous comment, and make sure you did not missed any step. You can also read the docs of the plugin https://www.npmjs.com/package/karma-istanbul-threshold |
Hi @cexbrayat, I really appreciate your help. I did it again step by step and I got the correct information. I also set up 'json-summary' and it provided everything I needed. Thank you very much. |
With @angular/cli: 1.0.0, there is no need to install any additional threshold plugin like
The thresholds property will enforce a minimum of 80% code coverage when the unit tests are run in the project. Here is my output of
|
@khichar-anil that doesn't work for me, but using |
I wrote a terse, but perhaps helpful, blog post about this: How to Add a Test Coverage Report to an Angular CLI Project |
I tried using thresholds with Angular CLI 1.0.1, but my tests don't fail even if I specify high threshold numbers. |
ng test --code-coverage created code coverage for me. |
I agree with @yfain. It is not going to fail with Angular CLI 1.0.1. |
After upgrading the karma-coverage-istanbul-reporter to 1.2.1 it works as expected. |
Thank you @yfain, it is working now... |
I can confirm. I updated
This example I made only applies thresholds when code coverage is enabled in the build, else it will use out of date coverage reports. |
Am I the only one that finds these config files to be incredibly nuanced and poorly documented over time? |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Mac OS X (El Capitan)
ng --version
. If there's nothing outputted, pleaserun in a Terminal:
node --version
And paste the result here.
angular-cli: 1.0.0-beta.5
node: 6.0.0
os: darwin x64
(node 6.0.0)
do on your code? etc.
None - feature request.
more information.
None - feature request.
Angular-cli sets up Karma/Jasmine and basic unit tests which is really nice; thanks for that. However I'm wondering if there are plans to integrate code coverage reporting and threshold checking into the
ng test
flow (e.g. with Istanbul/Isparta, or similar).In my company's starter kits we have a shortlist of things we consider mandatory for a production toolchain; the ability to fail CI when unit test coverage drops below a certain threshold is one of them.
Is code coverage on your radar?
The text was updated successfully, but these errors were encountered: