Is there a way to run some tests sequentially with Jest?

后端 未结 4 2015
青春惊慌失措
青春惊慌失措 2021-01-03 23:41

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)

4条回答
  •  走了就别回头了
    2021-01-04 00:20

    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).

提交回复
热议问题