I am using create-react-app to create a react application. When I executes npm test -- --coverage the test never exists. npm test actually runs react-scripts test. Any Idea?
-- --coverage
part won't work, and should use one of the commands below to set CI
to true
.
By default npm test runs the watcher with interactive CLI. However, you can force it to run tests once and finish the process by setting an environment variable called CI.
source: React docs
set CI=true && npm test
set CI=true && npm run build
($env:CI = "true") -and (npm test)
($env:CI = "true") -and (npm run build)
CI=true npm test
CI=true npm run build
NOT included in the docs
docker run -e CI=true [myImage] npm run test
Coverage won't work with Jest in watch mode.
Because "react-scripts test --env=jsdom" works in watch mode by default, the watch mode has to be switched off while generating the coverage output.
The following excerpt from the package.json contains a line "coverage" for illustration, how code coverage can be achieved within an app which was bootet by create-react-app.
It's just the modified "test" script, where the options --watchAll=false and --coverage are added in combination:
"scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "coverage": "react-scripts test --env=jsdom --watchAll=false --coverage", "eject": "react-scripts eject" }
Please note that it is obsolete to use standalone double-dash -- .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With