Skip to content

Running tests with code coverage doesn't include files outside the sourceRoot directory #22531

Closed
@Michael-Ziluck

Description

@Michael-Ziluck

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, the previous version in which this bug was not present was: Any time before PR #11974

Description

A clear and concise description of the problem...

🔬 Minimal Reproduction

  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. Run ng test --code-coverage and open coverage/index.html

🔥 Exception or Error

No error but the files outside the directory are not included in the coverage report.

Anything else relevant?

This was reported previously on issue #12474. They simply dismissed it as saying only files under sourceRoot are listed on the coverage report. Having the intended behavior be where tests from outside sourceRoot are ran but not included in the coverage report seems counterintuitive. They should either both be ran and included in the coverage report or not included in either place.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions