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.
--watchAll If you want to re-run only the tests that depend on the changed files, use the --watch option. Use --watchAll=false to explicitly disable the watch mode. tip. In most CI environments, this is automatically handled for you.
It sets an environment variable to "true". Without context you will never get an answer here. CI usually means Continuous Integration , and considering the tagging, I believe it should trigger a build/test from jenkins.
In order to run a specific test, you'll need to use the jest command. npm test will not work. To access jest directly on the command line, install it via npm i -g jest-cli or yarn global add jest-cli . Then simply run your specific test with jest bar.
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.
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