Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between '--watchAll=false' and 'CI=true'?

Tags:

reactjs

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.

like image 641
user8973449 Avatar asked Oct 16 '19 07:10

user8973449


People also ask

What is watchAll false?

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

What does CI true do?

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.

How do I test a specific file in jest?

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.


1 Answers

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.

like image 172
Jonathan Irwin Avatar answered Oct 10 '22 05:10

Jonathan Irwin