2

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!

Bogdan Lungu
  • 786
  • 1
  • 9
  • 16
  • 1
    I am also experiencing a similar problem, after upgrading my packages the jest tests appear to take **MUCH** longer. I went from 2 seconds to 60+ seconds, it appears to effect multiple Jest versions (on the major revisions). I am not sure which minor update causes this problem just yet. I am using Vue JS and TS Jest with the jest plugin, but getting same symptoms you are basically. – Ambidex Apr 18 '22 at 15:23
  • @Ambidex it is possible that there is an issue with Node versions above 16.10 I heard that Node 16.13 upgraded V8 which just makes memory leaks from node 14 much more visible. I did not tested myself yet but at least from the tests done by a colleague that handles the DevOps part this was the conclusion. – Bogdan Lungu May 04 '22 at 07:19
  • 1
    Stumbled upon this Q after seeing similar behavior in an upgrade to react-scripts v4. There's a (still-open) issue on the Jest repo re: a perf regression in v25 that might be related: https://github.com/facebook/jest/issues/9457. react-scripts v3 was on Jest v24 before. – Geoff Rich Sep 23 '22 at 23:14

0 Answers0