create-react-app
create-react-app copied to clipboard
react-scripts test does not fail when coverage threshold is not met
Describe the bug
Utilizing create-react-app, when running tests,
Did you try recovering your dependencies?
Yes.
Which terms did you search for in User Guide?
Tests. Coverage.
Environment
System:
OS: macOS 10.14.6
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Binaries:
Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
Yarn: Not Found
npm: 6.4.1 - ~/.nvm/versions/node/v10.15.3/bin/npm
Browsers:
Chrome: 77.0.3865.120
Firefox: 69.0.2
Safari: 13.0.2
npmPackages:
react: ^16.8.6 => 16.9.0
react-dom: ^16.8.6 => 16.9.0
react-scripts: 3.0.1 => 3.0.1
npmGlobalPackages:
create-react-app: 3.0.1
Steps to reproduce
package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test:coverage": "npm run test -- --coverage --watchAll=false",
},
"jest": {
"collectCoverageFrom": [
"src/components/**/*.js",
"src/state/**/*.js",
"src/templates/**/*.js",
"src/routes/**/*.js"
],
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
}
}
Run test:coverage
, the console shows a message that test coverage failed, but the test passes.
Expected behavior
If the code coverage thresholds are not met, the console returns a non-zero response.
Actual behavior
Hi @plummer-flex : Is this open for grabs?
@anusha5696 what do you mean? To be worked?
Hi @plummer-flex, have you found any way to fail the script if coverageThreshold is not matched?
fwiw: this is working with Node.js 18, NPM 8, and react-scripts 5.
I'm running tests with coverage using a custom script: react-scripts test --coverage --watchAll=false