How to speed up Jest?

Lee young-jun
Sep 3, 2021

--

I tried to enhance jest performance.

My cases use yarn. yarn jest

1. yarn jest (first time)

Takes 91s

2. yarn jest (second time)

Takes 37s

3. yarn jest --cache

Takes same to “yarn jest”. because --cache is default.

You can see default cache directory like this

yarn jest --showConfig

You have to use option --cacheDirectory to specify cache location

yarn jest --cacheDirectory ./__tests__/cache

This is helpful running in CI

3. yarn jest --maxWorkers

  • you can specify core count or use rate(percent of cores)
  • -w is shortcut to — maxWorkers

yarn jest -w=5

yarn jest -w=50%

  • but 100% is not fastest

yarn jest -w=100%

Final

This is my last jest command

yarn jest -u -w=50% --silent --cacheDirectory ./__tests__/cache

37s → 27s

Faster 10s !!!

Reference

https://runebook.dev/ko/docs/jest/cli

--

--

No responses yet