[Jest] Track project code coverage with Jest

2752 단어
Jest comes pre-packaged with the ability to track code coverage for the modules you're testing, but it takes a little extra work to make it track untested files as well. Let's look at what Jest can do for you, what you have to do yourself, and how to setup code coverage thresholds so you can work to improving the code coverage numbers for your projects.
 
//package.json

{
  ...
  "jest": {
    "testEnvironment": "node",
    "collectCoverageFrom": [
      "src/*.js"
    ],
    "coverageThreshold": {
      "global": {
        "branches": 100,
        "functions": 50,
        "lines": 33,
        "statements": 25
      }
    }
  }
}

 
"collectCoverageFrom":  include all the js files, it will exclude *.test.js/*.spec.js files automatically
"coverageThreshold": limit the coverage, if below the coverage, it will report error

좋은 웹페이지 즐겨찾기