Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular CLI - Get coverage report to include all sources

I am trying to figure out how to include all my .ts sources in the generated coverage report from the angular CLI. Currently I am only getting coverage for files that have an associated spec with tests against.

I have tried adding the includeAllSources flag to my karma.conf.js file but this made no difference.

Whats the correct approach here? I am using Angular CLI 6.1.5

Thanks

like image 723
mindparse Avatar asked Aug 30 '18 18:08

mindparse


People also ask

How do I generate karma coverage report?

To activate the coverage reporter add this to your configuration file. reporters = ['coverage']; This will create a coverage report for every browser that the tests are run in. In addition, it will create a JSON file that outputs the intermediate data.

Is Karma coverage Istanbul reporter deprecated?

Starting Angular 11, the karma-coverage-istanbul-reporter has been deprecated.


1 Answers

The simplest solution that worked for me on Angular(v6) was just adding a app.module.spec.ts file to compliment your app.module.ts and within that .spec include the following code

import './app.module';

Apparently due to the fact app.module.ts is the root of your application including a .spec for that module will result in the inclusion of all your files during code coverage (ng test --code-coverage)

like image 83
Narm Avatar answered Sep 28 '22 10:09

Narm