Skip to content

Parallelism

File Parallelism

By default, Vitest runs test files in parallel. Depending on the specified pool, Vitest uses a different mechanism to parallelize test files:

Both "child processes" and "worker threads" are refered to as "workers". You can configure the number of running workers with minWorkers and maxWorkers options. Or more granually with poolOptions configuration.

If you have a lot of tests, it is usually faster to run them in parallel, but it also depends on the project, the environment and isolation state. To disable file parallelisation, you can set fileParallelism to false. To learn more about possible performance improvements, read the Performance Guide.

Test Parallelism

Unlike test files, Vitest runs tests in sequence. This means that tests inside a single test file will run in the order they are defined.

Vitest supports the concurrent option to run tests together. If this option is set, Vitest will group concurrent tests in the same file (the number of simultaneously running tests depends on the maxConcurrency option) and run them with Promise.all.

Vitest doesn't perform any smart analysis and doesn't create additional workers to run these tests. This means that the performance of your tests will improve only if you rely heavily on asynchronous operations. For example, these tests will still run one after another even though the concurrent option is specified. This is because they are synchronous:

ts
test.concurrent('the first test', () => {
  expect(1).toBe(1)
})

test.concurrent('the second test', () => {
  expect(2).toBe(2)
})

If you wish to run all tests concurrently, you can set the sequence.concurrent option to true.

Released under the MIT License.