Including "projects" in Jest config causes several redundant runs of each test

Viewed 96

I am using Jest in a monorepo. I am using create-react-app and so am configuring with CRACO. Below is the Jest section of my CRACO config. With jestConfig.projects = ["<rootDir>/packages/*"]; commented out, each test runs once. But when it is un-commented, each test is run multiple times, making my Jest calls take a long time.

I'd like to be able to take advantage of parallelization with projects, which should make my tests run more quickly, not more slowly.

How can I prevent the redundant test runs and take advantage of parallelization?

  jest: {
    configure: (jestConfig, { env, paths, resolve, rootDir }) => {
      // jestConfig.projects = ["<rootDir>/packages/*"]; un-commenting causes each test to be run repeatedly
      jestConfig.roots = ["."];
      jestConfig.setupFiles = ["./jest.overrides.js"];
      jestConfig.setupFilesAfterEnv = ["./setupTests.js"];
      jestConfig.testMatch = [
        "<rootDir>/packages/**/*.{spec,test}.{js,jsx,ts,tsx}",
      ];
      return jestConfig;
    },
  },

Screenshot of test run with projects enabled: enter image description here

Screenshot of test run with projects commented out: enter image description here

0 Answers
Related