When is it appropriate to use each of --runInBand
or --maxWorkers 1
options?
If my intent is to run all tests in sequence (one at a time, in order), which of these is the right option?
Extra detail:
I'm using Jest to test a NodeJs express
application, with integration tests hitting the HTTP endpoints via supertest
. This may not make any difference to the answer, just mentioning in case it is relevant.
Here's the Jest CLI reference:
https://facebook.github.io/jest/docs/cli.html
Relevant parts:
--maxWorkers=<num>
Alias: -w. Specifies the maximum number of workers the worker-pool will spawn for running tests. This defaults to the number of the cores available on your machine. It may be useful to adjust this in resource limited environments like CIs but the default should be adequate for most use-cases.
--runInBand
Alias: -i. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging.
--runInBand Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging.
So to run a single test, there are two approaches: Option 1: If your test name is unique, you can enter t while in watch mode and enter the name of the test you'd like to run. Option 2: Hit p while in watch mode to enter a regex for the filename you'd like to run.
Each time a test run completes, the global environment is automatically reset for the next. Since tests are standalone and their execution order doesn't matter, Jest runs tests in parallel. This means that even if you have hundreds of unit tests you can run them frequently without the fear of having to wait.
There is no difference. Here's the method where it gets read from the args object:
export default function getMaxWorkers(argv: Argv): number { if (argv.runInBand) { return 1; } else if (argv.maxWorkers) { return parseInt(argv.maxWorkers, 10); } else { const cpus = os.cpus().length; return Math.max(argv.watch ? Math.floor(cpus / 2) : cpus - 1, 1); } }
original source code on github
--runInBand
and --maxWorkers=1
have the same behaviour.
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