create react app : configure Jest : Run all test files
Asked Answered
V

4

14

I would like to configure npm test in my server. when I run npm test, it invokes react-scripts test which triggers a prompt window ( attached screen ). How do I avoid the prompt and run all testcases in the server.

"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"lint": "./node_modules/.bin/eslint ."
},

enter image description here

Vaporize answered 17/9, 2019 at 6:7 Comment(0)
V
37

To run all the tests, use "test": "react-scripts test --watchAll=false"

Vespertilionine answered 17/1, 2020 at 7:33 Comment(1)
As documented here: create-react-app.dev/docs/running-tests/#command-line-interfaceScalariform
C
4

If you pass CI=true, it will run once without setting up that prompt as described at https://create-react-app.dev/docs/running-tests/#linux-macos-bash:

CI=true npm test

Cabbage answered 11/9, 2021 at 22:9 Comment(0)
G
2

When you want to run all tests you can use npm test --watchAll

Glynas answered 17/9, 2019 at 6:8 Comment(2)
--watchAll looking for changes in the script and it's keep spinning. Is there any other argument that avoid prompt and run all testfiles ?Vaporize
ReactScripts tests all uncommited files in git. What do you want to achieve? Run all of the tests even if something not has been changed? npm test as well goes into watch modeGlynas
B
-1

You can just update your package.json and in the scripts section update the test one with just "test": "jest"

It should run every test file that it can find in your project

Bear answered 17/9, 2019 at 6:10 Comment(1)
It's not that simple, because CRA programatically sets config you may be relying on: https://mcmap.net/q/827277/-how-can-i-make-jest-run-with-the-same-config-as-react-script-test-on-a-create-react-appLichi

© 2022 - 2024 — McMap. All rights reserved.