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

Question: can you check coverage on a per-file basis? #468

Closed
mrsimonemms opened this issue Dec 9, 2016 · 12 comments
Closed

Question: can you check coverage on a per-file basis? #468

mrsimonemms opened this issue Dec 9, 2016 · 12 comments

Comments

@mrsimonemms
Copy link

I didn't really want to put a question in here, but I can't find it detailed elsewhere.

I'm trying to set up my coverage tests to ensure that each file has at least 80% coverage on lines, statements, functions and branches. The calculations with my config appear to be working on the coverage of the whole project., not on the individual files.

As an example, if the coverage of the whole project is 90%, but one file only has 70% coverage, I want NYC to throw a check-coverage error.

Does anyone have any bright ideas?

My package.json:

{
    "nyc": {
    "all": true,
    "check-coverage": true,
    "cache": true,
    "lines": 80,
    "statements": 80,
    "functions": 80,
    "branches": 80,
    "include": [
      "src/**/*.js"
    ],
    "reporter": [
      "lcov",
      "text-summary"
    ],
    "require": [
      "babel-register"
    ],
    "sourceMap": false,
    "instrument": false
  },
}
@alonronin
Copy link

alonronin commented Dec 11, 2016

use text reporter to see all files report not just summary

"reporter": [
      "lcov",
      "text",
      "text-summary"
    ],

@mrsimonemms
Copy link
Author

Thank @alonronin. That strikes me as the checking being a manual process - is there a way of using the check-coverage command to automate this?

@bcoe
Copy link
Member

bcoe commented Dec 18, 2016

@riggerthegeek @alonronin this sounds like a reasonable feature request, any thoughts about what the interface might look like for enabling this?

@mrsimonemms
Copy link
Author

To my mind, a simple boolean in the config object. I'd suggest perFile with it defaulting to false.

If I were writing the package from scratch, I'd default it to true but I'd consider it a (potentially) breaking change so probably best to desult to false.

If everyone's ok with that update, I'll have a look at doing a PR

@alonronin
Copy link

maybe average: false property?

@mrsimonemms
Copy link
Author

Sounds good to me @alonronin. When I get some time over the next month, I'll see if I can create a pull request

@JaKXz
Copy link
Member

JaKXz commented Apr 5, 2017

This sounds like a definite value add, though I'd definitely favour perFile over average: false because the former is more semantic [i.e. does what it says on the tin].

@DblK
Copy link

DblK commented Aug 24, 2017

I suggest to have lines, statements, functions & branches under a global object and also a perFile object.
That way we can have a global of 90 and a minimum per file at 60.
That way we can avoid 0 on some files when working on huge project with a lot of 100.

Something similar of https://github.com/titel-media/karma-istanbul-threshold for global and each

@asgoth
Copy link

asgoth commented Oct 7, 2017

Seems very similar as the global/file coverage feature of istanbul (v1):

check:
  global:
    statements: 90
    lines: 90
    branches: 80
    functions: 90
    excludes: []
  each:
    statements: 80
    lines: 80
    branches: 75
    functions: 75
    excludes: []

Seems a feature that was forgotten in #309

@mkonikov
Copy link

Ya. Would love this feature to have both. Currently migrating some repos over from istanbul and noticed it missing.

@jdcmarques
Copy link

Is there a plan to support per-file coverage thresholds with possible overrides?

@d65yan
Copy link

d65yan commented Dec 2, 2020

I think jest provides a neat feature to allow for individual files thresholds, does not look like a complicated effort although i have not looked deeply into the checkCoverage code, jest's impl seems reasonably simple, any chance we can get something along those lines?

@mrsimonemms mrsimonemms closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2023
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

9 participants