3000 tests - Major performance issues. What can be done?

Viewed 247

Our react project has ~3000 jest tests. Most of them are just typical "render without crashing".

When we run npm test, the amount of memory used slowly climbs all the way to 22 Gb.

On machines with only 16 Gb, the tests grind the entire machine to a halt and take a very long time to finish.

What we have tried that has not worked or made the issue worse:

  1. --maxWorkers=50% or --maxWorkers=4 etc
  2. --runInBand (way too slow)
  3. --detectLeaks (half our tests have memory leaks according to this experimental option, but we have no idea what they are or even if they are the cause of this problem)

The only thing that works is running the tests on a machine with a large amount of RAM (>= 32Gb).

Any idea on how we can reduce the amount of memory used by these tests?

1 Answers

We worked around this problem by splitting up the testing in multiple steps.

For example, if you have two source folders:

a/
b/

Then instead of running npm test, you can run it in two steps:

react-scripts test src/a && react-scripts test src/b

This will clear the memory used in each step.

Related