This weekend, I started writing front-end tests for a few new components. I immediately hit a hiccup in the form of a dreadfully slow test suite. This didn’t make much sense to me because I only had a few simple tests at the time. With my local Docker setup, I was seeing test runs taking anywhere between 10 seconds and 80 seconds for maybe five tests. This seemed insane—even considering the fastest time I experienced.
After a bit of searching, I came across a thread with some folks suggesting Jest’s runInBand option. This tells Jest to run the tests serially in the current process rather than creating a worker pool and parallelizing the tests across several workers. It’s especially useful for environments with limited resources, which would make sense for why it helped my Docker container. One commenter indicated that
--runInBand reduced their test time from over 1.5 hours down to 4 minutes! It really makes me wonder why this option isn’t the default, leaving the worker pool to be opted into.