Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only report coverage for TS files that have spec files? #116

Open
jgodi opened this issue Apr 14, 2017 · 4 comments
Open

Only report coverage for TS files that have spec files? #116

jgodi opened this issue Apr 14, 2017 · 4 comments

Comments

@jgodi
Copy link

jgodi commented Apr 14, 2017

I have a few files in my library that don't need/have spec files and they are showing in my coverage report. How can I ignore these without specifically calling them out with the exclude?

-----------------------|----------|----------|----------|----------|----------------|
File                   |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
-----------------------|----------|----------|----------|----------|----------------|
 src/                  |    10.53 |      100 |        0 |    13.33 |                |
  index.ts             |        0 |      100 |      100 |        0 |        2,3,6,7 |
  ng-starter.module.ts |    15.38 |      100 |        0 |    18.18 |... 19,21,22,24 |
 src/meow/             |    33.33 |      100 |    33.33 |    35.71 |                |
  index.ts             |        0 |      100 |      100 |        0 |            1,2 |
  meow.component.ts    |      100 |      100 |      100 |      100 |                |
  meow.module.ts       |    11.11 |      100 |        0 |     12.5 |... ,7,14,15,17 |
-----------------------|----------|----------|----------|----------|----------------|
All files              |    21.62 |      100 |    16.67 |    24.14 |                |
-----------------------|----------|----------|----------|----------|----------------|

I only want the meow.component.ts to appear.

@erikbarke
Copy link
Collaborator

erikbarke commented Apr 15, 2017

Hey @jgodi, the only way to do it (currently) is excluding files using karmaTypescriptConfig.coverageOptions.exclude. Are you looking for a way to automatically exclude files that don't have a corresponding spec file?

@jgodi
Copy link
Author

jgodi commented Apr 15, 2017

Yes, that would be amazing. I can hard-code the exclusion, but it would be nice to only include coverage for files that have tests with them.

Especially in Angular, there are module files, index files, etc that only have decorators on a class. Testing these would provide no benefit, but including them reduces the numbers drastically.

I would gladly help with a PR, if you want to point me in a good direction.

@erikbarke
Copy link
Collaborator

Ok, so something like

karmaTypescriptConfig {
    coverageOptions: {
        exclude: [/\.(d|module|spec)\.ts$/i, /index\.ts$/i]
    }
}

to exclude all *.module.ts and index.ts files wouldn't be enough to solve your issue?

If so, this would have to be an opt-in feature because it would mean that you could have 100% test coverage even with a ton of untested files, if all untested files are excluded automatically.

These are good starting points for a PR:

Cheers!

@teogeos
Copy link

teogeos commented Feb 9, 2018

Just so you know, I prefer coverage to show for all files by default. I think it's better to make it harder to forget to test files by default. I'd rather have to explicitly exclude files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants