Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jestjs - jest coverageThreshold glob exclude some sub folders

Inside my ./src/app/global-team folder, there are a-z folders. I want to set my threshold level on all folders aggregated except d, f, and y. I want to get the aggregate numbers instead of numbers per folder/file. My closest attempt is the following which reports the numbers by file:

coverageThreshold: {
  './src/app/global-team/!(d|f|y)/**': {
    branches: 95,
    functions: 95,
    lines: 95,
    statements: 95
  }
}

And removing the ** wild cards doesn't work: './src/app/global-team/!(d|f|y)/

What would be the correct glob to exclude some subfolders but have the report at aggregate level?

question from:https://stackoverflow.com/questions/65894304/jest-coveragethreshold-glob-exclude-some-sub-folders

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As explained in the Jest Documentation, you can specify multiple thresholds, and can use wild cards. While this is not the glob specific method, like collectCoverageFrom, it will support what you are trying to accomplish.

{
  ...
  "jest": {
    "coverageThreshold": {
      "global": {
        "branches": 50,
        "functions": 50,
        "lines": 50,
        "statements": 50
      },
      "./src/components/": {
        "branches": 40,
        "statements": 40
      },
      "./src/reducers/**/*.js": {
        "statements": 90
      },
      "./src/api/very-important-module.js": {
        "branches": 100,
        "functions": 100,
        "lines": 100,
        "statements": 100
      }
    }
  }
}

I have my coverage set to cover the project, and in using the parent directory with a glob, then removing what I do not want to cover, I do get a source tree view. This view then has folder 'A' with overall coverage metrics overall metrics.

Click into it, then the individual files (or more folders) with their metrics the metrics for that folder or file.

Likely still not want you want. I have also run before the Jest

The next option is to create multiple jest.config.js files (jest.config.main.js, jest.config.projectb.js) and run Jest with each of these configuration files, but putting the output into different directories. I use this for test coverage during my e2e tests.

Again, not sure this fully does what you want.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...