With CRA upgrade from 3.4.1 to 4.0.3 tests are running much slower

774 Views Asked by At

I have a CRA project which I updated from 3.4.1 to 4.0.3 With the update on 4.x.x it also updated Jest to version 26.x.x

After this update, the tests are 3x slower than before the upgrade. I suspect it has to do with the new Jest version.

Some important things to mention:

  • There are 1800 test suites with almost 10k tests;
  • the tests are 3x slower when run with runInBand, they take approx. 1700 seconds compared to approx. 600 seconds before the update;
  • the tests are running faster without runInband option but they take almost the entire CPU resources and memory;
  • adding --maxWorkers with any value flag does not help too much;
  • the script for the tests is run via react-app-rewired: "test": "react-app-rewired test";
  • jest config in package.json looks like this:
"jest": {
  "setupFiles": [
    "./jest.overrides.js",
    "jest-canvas-mock"
  ],
  "resetMocks": false
},
  • jest.overrides.js file contains:
const { error } = console;

console.error = (message, ...rest) => {
  error.apply(console, [message, ...rest]);

  if (message instanceof Error) {
    throw message;
  }

  throw new Error(message);
};

Removing the content of this file does not help either (I just give it a try).

  • I removed the react-app-rewired and run the tests via react-scripts and the speed is the same (slow).

Does anyone encounter a similar situation? Is there a way to improve the speed of the tests? I do not understand why an upgrade can cause this kind of regression.

Thank you in advance!

0

There are 0 best solutions below