no coverage report in the console?
ninjabhishek opened this issue ยท 8 comments
I understand about the warning that it will not fail with threshold, but do we get the overall coverage report in the console itself when tests are done executing, or is that pending as well?
Using in Angular 11
If yes, how? Or are we not getting that feature at all?
Please contribute: http://karma-runner.github.io/5.2/dev/contributing.html
yep, would be nice to have it, deprecated 'karma-coverage-istanbul-reporter'
has it.
Well, the functionality is there, but one needs to be on most recent versions (at least I have tested on them) with karma at 6.0.1
and karma-coverage at 2.0.3
and the update the config.
In karma.conf.js
where karma-coverage-istanbul-reporter
had config like
coverageIstanbulReporter: { dir: require('path').join(__dirname, './coverage/'), thresholds: { statements: 80, lines: 80, branches: 80, functions: 80, }, reports: ['html', 'lcovonly', 'text-summary'], fixWebpackSourcePaths: true, }
karma-coverage
will have like
coverageReporter: { dir: require('path').join(__dirname, './coverage/'), thresholds: { statements: 80, lines: 80, branches: 80, functions: 80, }, reporters: [{ type: 'lcovonly', subdir: '.' }, { type: 'html', subdir: '.' }, { type: 'text-summary', subdir: '.' },], fixWebpackSourcePaths: true, }
notice the diff of reports vs reporters. also note subdir is given for every report type. this is important if you want to generate these report files at same folder level to which karma-coverage-istanbul-reporter
generated. if this is left blank for any report type, another folder is created inside coverage folder in the name of browser on which the test was run. this will work @valera33
@johnjbarton When I used one of not latest versions few weeks ago, I got a warning that there is a known issue where will not fail if thresholds are not met. Is that fixed?
@ninjabhishek if you replace thresholds
with check
it works.
For anyone else wondering about this, the docs don't mention it explicitly but if you specify file
for a reporter config, it will not print to the console.
I need both the Cobertura-format XML and the console summary output for CI. Gitlab uses the XML results to annotate MR diffs, but it has to scrape the overall percentage from the console via regex against the job logs.
I was about to ask if I needed to open a new issue to support this, but it turns out that all I was missing was this:
coverageReporter: {
dir: ...,
reporters: [
...,
{type: 'text-summary'}
]
}
The text-summary coverageReporter is responsible for the little color-coded "Coverage summary" block with percentages and line/block counts.