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
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.
Starting Angular 11, the karma-coverage-istanbul-reporter has been deprecated.
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With