Angular CLI - Get coverage report to include all sources
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
)
Solution provided by Narm is really great, however still not ideal, as requires importing manually at least all the lazy loaded modules + root one to the tests and also on big projects there are almost always some non-used/forgotten components which are not part of any production code and which will leave in the source code for ever untested/undiscovered.
Solution:
https://github.com/kopach/karma-sabarivka-reporter.
To use it → install npm install --save-dev karma-sabarivka-reporter
And update karma.conf.js
as described here https://github.com/kopach/karma-sabarivka-reporter#-usage
After this – all files matching pattern will be included into final coverage result