What's The Difference Between '--watchAll=false' And 'CI=true'?

- 1 answer

I'm setting up a CI using reactjs and I don't want the tests to run in watch mode.

In the documentation for running tests, it states the following:

"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."

If, as stated, setting the 'CI=true':

"The test command will force Jest to run in CI-mode, and tests will only run once instead of launching the watcher."

Why does it (as quoted below) say For non-CI environments? Is there any reason you shouldn't use '--watchAll=false' in CI environments?

"For non-CI environments, you can simply pass the --watchAll=false flag to disable test-watching."

I've tried both in my CI environment and in my case both seems to work fine and doing the same thing. I would even prefer the '--watchAll=false', since this would be a more cross platform approach.

So, which one should I use in my CI environment and why? And also, what's the difference between the two of them?

Thank you!

Wondering which approach I should use 'CI=true' or '--watchAll=false'. I've tried both and they seem to be working in the same way.



Your CI environment will likely set the CI environment variable to true without you doing anything.

So for your CI you shouldn't really need to set either watchAll=false or CI=true but if you do want to set something manually rather use CI=true.

At least one difference between the 2 is that watchAll=false (and if CI=false) will still create Jest snapshots if they don't exist. You won't want this in a CI environment. Your tests will pass even if the snapshots change.