⚡️10x speed up your Jest start-up spin-up time by watchman

Nate Liu
2 min readFeb 13, 2022
Photo by Ferenc Almasi on Unsplash

10 seconds ➡ 1 seconds to actually start running your Jest tests in a repo with 100-ish test files and 1000-ish test cases

When running your Jest test suites, it’s primarily comprised of two stages:

  1. Spin-up: traverse, filter and transpile files matching test file pattern for this round of test.
    The stage is the long silence before you see anything output in console by command jest , which is the time we could speed up.
    💡 Spin-up time is NOT part of the “Time” recorded in your final Jest test results
  2. Run: your actual test names are logging to console and results follow.
    At the moment you see Determine test suites to run logged in console, it’s when your tests are actually running.

watchman is a facebook developed file watching service, running background at various operation systems and it incredibly boosts up your Jest spin-up time. Jest by default uses watchman as file crawler, but it only comes into play when your environment has that service up-and-running.

To know if your environment has that file watching service alive, simply run CLI command watchman -v and it should tell you the version instead of some general command-not-found error. To install the service, for example on macOS just brew install watchman.

Your jest spin-up time is now ready(or already) to be boosted up by that service. 🎉

--

--

Nate Liu

Passionate engineer, UX advocator and snow chaser.