Closed
Labels
P5The team acknowledges the request but does not plan to address it, it remains open for discussionThe team acknowledges the request but does not plan to address it, it remains open for discussioneffort2: medium (days)featureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
Description
Please provide us with the following information:
- OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
Mac OS X (El Capitan)
- Versions. Please run
ng --version. If there's nothing outputted, please
run 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)
- Repro steps. Was this an app that wasn't created using the CLI? What change did you
do on your code? etc.
None - feature request.
- The log given by the failure. Normally this include a stack trace and some
more information.
None - feature request.
- Mention any other details that might be useful.
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?
Metadata
Metadata
Assignees
Labels
P5The team acknowledges the request but does not plan to address it, it remains open for discussionThe team acknowledges the request but does not plan to address it, it remains open for discussioneffort2: medium (days)featureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
Activity
delasteve commentedon May 22, 2016
For fun, I decided to try and get this working in a test project. I was able to get things working with
karma-coverageandremap-istanbul.Caveats:
karma-remap-istanbul, but had no luck. This is probably due to user error. Also, it has an outdated version ofremap-istanbul(Bump remap-istanbul version marcules/karma-remap-istanbul#7). I had used the pull request project instead of the npm package.remap-istanbulrequires you to list specific source files, which if you add multiple browsers, will be multiple and will be fragile due to the specific browser needed. This will require a script to gather and remap each of the files to overcome the CLI commands I used.My modified
karma.config.jsfor reference (omitted parts that didn't change):To get the remap working, I used the following. You may need to change the numbers up depending on your browser.
delasteve commentedon May 23, 2016
After playing with it a bit more, I got this working on
ng testandkarma-remap-istanbul(from the PR version still). You can see the PR here: #895Caveats:
coverage/report.jasonswett commentedon Jul 19, 2016
Where did we land with this? I see that the issue is closed but I can't really tell what the conclusion is.
CristyTarantino commentedon Jul 27, 2016
+1
filipesilva commentedon Jul 27, 2016
Code coverage was added via #1455.
seescode commentedon Nov 17, 2016
How can I run the code coverage tool? When I run "ng help" I can't tell what command I need to run?
delasteve commentedon Nov 17, 2016
It should run when you run
ng test.filipesilva commentedon Nov 22, 2016
Actually it was changed to only run when doing
ng test --code-coverage, because of how slow having it on all the time was.humpedli commentedon Feb 1, 2017
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?
schechter commentedon Mar 1, 2017
Is there a way to make the tests fail if the coverage falls before a threshold?
3 remaining items
marciomsm commentedon Apr 6, 2017
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
Low Coverage: GLOBAL X% of X% statements
Low Coverage: GLOBAL X% of X% functions
Low Coverage: GLOBAL X% of X% branches
cexbrayat commentedon Apr 6, 2017
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
marciomsm commentedon Apr 6, 2017
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.
anilkhichar commentedon Apr 17, 2017
With @angular/cli: 1.0.0, there is no need to install any additional threshold plugin like
karma-istanbul-threshold. As per cli documentation, just add below line and your are all set with threshold as well.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
ajdaniel commentedon Apr 26, 2017
@khichar-anil that doesn't work for me, but using
karma-istanbul-thresholdworks. I have no idea why it didn't work, so I'm sticking with what worksjasonswett commentedon Apr 26, 2017
I wrote a terse, but perhaps helpful, blog post about this: How to Add a Test Coverage Report to an Angular CLI Project
yfain commentedon May 4, 2017
I tried using thresholds with Angular CLI 1.0.1, but my tests don't fail even if I specify high threshold numbers.
aniruddhadas9 commentedon May 8, 2017
ng test --code-coverage created code coverage for me.
SURENDARREDDY commentedon May 9, 2017
I agree with @yfain. It is not going to fail with Angular CLI 1.0.1.
It keeps getting success even I have all threshold 100%.
yfain commentedon May 9, 2017
After upgrading the karma-coverage-istanbul-reporter to 1.2.1 it works as expected.
SURENDARREDDY commentedon May 10, 2017
Thank you @yfain, it is working now...
ajdaniel commentedon May 11, 2017
I can confirm. I updated
karma-coverage-istanbul-reporterto 1.2.1 and now I can use thethresholdproperty in thecoverageIstanbulReporterconfig like so:This example I made only applies thresholds when code coverage is enabled in the build, else it will use out of date coverage reports.
angular-automatic-lock-bot commentedon Sep 7, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.