CodePark/ questions / Isolation, parallelism & flaky tests
START PRACTICINGPRACTICE
Backend question · Backend testing › Isolation, parallelism & flaky tests

By default, how does Jest run your tests?

Test files run in parallel in separate worker processes; tests inside one file run one after another

Jest runs test files in parallel, in separate worker processes. Each file gets its own module registry, which is its own copy of the loaded modules. Inside one file, tests run one after another, unless you opt in with test.concurrent.

"Each individual test runs in its own worker process" is wrong: Jest splits work by file, not by test. "Everything runs sequentially in one process unless you pass
--parallel" is also wrong: parallel is the default. To run all files one after another in one process, use --runInBand. This helps when tests share a database.