Jest runs your test suite in parallel by default, but there is a flag (--runInBand
) that allows you to run the whole suite sequentially (as pointed out here)
Extended from Joachim Lous's answer, you can divide test files into projects and specify a different runner for each project.
In jest.config.js
:
module.exports = {
projects: [
{
displayName: "default-tests",
testEnvironment: "node",
},
{
displayName: "serial-tests",
testEnvironment: "node",
runner: "jest-serial-runner",
testMatch: ["**/?(*.)+(serial-test).[jt]s?(x)"],
},
],
}
Then, rename any tests that need to be run sequentially to *.serial-test.js
(as opposed to *.test.js
).