create-react-library icon indicating copy to clipboard operation
create-react-library copied to clipboard

How do you run tests with coverage?

Open jestrickler opened this issue 3 years ago • 2 comments

I tried several permutations on the scripts:

"test:coverage": "react-scripts test -- --coverage --env=jest-environment-jsdom-fourteen",
"test:coverage": "cross-env CI=1 react-scripts test -- --coverage --env=jest-environment-jsdom-fourteen",
"test:coverage": "cross-env CI=1 react-scripts test -- --env=jest-environment-jsdom-fourteen --coverage",

"test:coverage": "CI=true npm test -- --env=jest-environment-jsdom-fourteen --coverage",

"test:coverage": "CI=true npm test -- --coverage --collectCoverageFrom='src/**/*.js' --collectCoverageFrom='!src/**/*.stories.js' --collectCoverageFrom='!src/**/reportWebVitals.js' --collectCoverageFrom='!src/**/index.js'  --collectCoverageFrom='!src/**/api.js' --collectCoverageFrom='!src/**/*Context*.js'",

"test:coverage": "cross-env CI=1 react-scripts test -- --env=jest-environment-jsdom-fourteen --coverage --collectCoverageFrom='src/**/*.js' --collectCoverageFrom='!src/**/*.stories.js' --collectCoverageFrom='!src/**/reportWebVitals.js' --collectCoverageFrom='!src/**/index.js'  --collectCoverageFrom='!src/**/api.js' --collectCoverageFrom='!src/**/*Context*.js'",

but none of these would work.

I tried turning coverage on in the jest configuration:

"jest": {
    "collectCoverage": true
}

but this was not in the list of accepted jest options.

I added the following options:

 "jest": {
    "collectCoverageFrom": [
      "src/**/*.js",
      "!src/**/index.js",
      "!src/**/*.stories.js"
    ],
    "coverageReporters": ["clover", "json", "lcov", "text"],
    "coverageThreshold": {
      "global": {
        "branches": 80,
        "functions": 80,
        "lines": 80,
        "statements": -10
      }
    }
}

which were accepted but didn't seem to generate any coverage report.

jestrickler avatar Dec 17 '21 19:12 jestrickler

@jestrickler Were you able to find a solution for this?

zachkaigler avatar Dec 29 '21 19:12 zachkaigler

I wish! Been on vacation for the holidays.

jestrickler avatar Jan 03 '22 14:01 jestrickler