create-react-library
create-react-library copied to clipboard
How do you run tests with coverage?
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 Were you able to find a solution for this?
I wish! Been on vacation for the holidays.