Jest: Difference betwen --runInBand and --maxWorkers 1

12,236

Solution 1

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

Solution 2

--runInBand and --maxWorkers=1 have the same behaviour.

Share:
12,236
bguiz
Author by

bguiz

Writes Code.

Updated on June 19, 2022

Comments

  • bguiz
    bguiz almost 2 years

    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.