AlexStack AlexStack - 1 year ago 136
React JSX Question

Running CRA Jest in non-interactive mode

Update: my use case is mainly to run tests at CI, but overriding default CRA Jest parameters is something I'm generally wondering about.

I'm running tests using the Jest, config that came with Create React App. It always launches into the interactive mode:

› Press a to run all tests.
› Press o to only run tests related to changed files.
› Press p to filter by a filename regex pattern.
› Press q to quit watch mode.
› Press Enter to trigger a test run.

But I don't want it to wait for my input. I want it to run once and then terminate. I tried using the
switches but it still launches in interactive mode.

If I globally install
, and run it in the root of my project, it executes once and finish (just as I want). But when I run
npm test
which runs
react-scripts test
, it goes into the watch mode even when I'm not passing

Update: I've also filed an issue on CRA.

Answer Source

CRA looks for a CI environment variable, if its present it doesnt run in watch mode.

CI=true npm test should do what you are looking for

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download