Angular-cli: ng test --code-coverage doesn't include files outside of src folder

Created on 4 Oct 2018  路  3Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [x] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

node v8.9.4
npm v6.4.1
Mac OS Mojave
Angular CLI: 6.2.4
Angular: 6.1.9

Repro steps

  1. ng new test-app
  2. create packages/test-package outside of src folder
  3. add there simple test.component.ts and test.component.spec.ts
  4. Modify test.ts file and add context of 'packages directory
    replace
const context = require.context('./', true, /\.spec\.ts$/);
context.keys().map(context1);

with

const context1 = require.context('../packages', true, /\.spec\.ts$/);
const context2 = require.context('./', true, /\.spec\.ts$/);

context1.keys().map(context1);
context2.keys().map(context2);
  1. Add "../packages/**/*.spec.ts", to tsconfig.spec.json in "include" section

  2. ng test --code-coverage and open coverage/index.html

Description

Files from packages directory don't include in final coverage report

Desired functionality

All files despite on their location should be presented in final coverage report

Most helpful comment

It would be great if we could supply an optional list of external directories to include. (perhaps in angular.json?)

That commit completely broke coverage reporting in my team's mono-repo setup :(

All 3 comments

This is actually by design, Only files under sourceRoot are listed in the code coverage report. Anything which is not under sourceRoot is considered as external.

https://github.com/angular/angular-cli/issues/11934

It would be great if we could supply an optional list of external directories to include. (perhaps in angular.json?)

That commit completely broke coverage reporting in my team's mono-repo setup :(

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings