Search code examples
angularangular-clikarma-runnerkarma-coverage

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


Solution

  • 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)