I am investigating what is the faster and has a smaller memory footprint compare to Jest, any recommendation? #16467
Replies: 3 comments
|
BTW I am also asking the same question in Vitest since I was not able to find a good answer to this question:
My Goal
In a large project with many test suites |
|
Before you switch runners, it's worth trying Jest 30's own speed and memory settings. Most of the cost in a big TS suite is transpilation and memory held between test files, not the runner itself. 1. Upgrade to Jest 30 if you're on 29 or older. The release post describes the new module resolver and memory work (one large TS app reported 37% faster runs and 77% lower memory). 2. Turn on globals cleanup. It releases memory between test files. The default // jest.config.js
module.exports = {
testEnvironmentOptions: { globalsCleanup: 'on' },
};3. Cap worker memory. module.exports = { workerIdleMemoryLimit: '512MB' }; // or '50%' of system memory4. Transpile with SWC instead of module.exports = {
transform: { '^.+\\.(t|j)sx?$': '@swc/jest' },
};5. Run fewer tests, and in parallel. You don't need Nx for this. Jest's built-in Measure before and after: |
|
If your main goals are execution speed and lower memory usage, I think Bun is worth testing against your actual project. Its test runner supports a Jest API, TypeScript, snapshots, mocks, DOM testing, workers, and sharding, although Jest compatibility is still not complete. I would not choose a runner based only on published benchmarks though. For a large codebase, dependency loading, transforms, DOM environments, isolation, mocks, and worker configuration can have a bigger impact than the test runner itself. A useful comparison would be to run the same representative suites with Jest, Vitest, Bun, and rjest and measure the following:
You can often try For very large monorepos, I would still combine the faster runner with affected-test selection or sharding. A faster runner helps, but avoiding unnecessary tests usually gives a much larger improvement as the project grows. |
Uh oh!
There was an error while loading. Please reload this page.
Hi guys,
I know this might not be the best way to approach this but I was wondering if we have a faster test runner I can use in My NodeJS and Frontend projects written in TS/JS. Right now the bigger the project the longer it takes to finish all the unit tests. I know I can use and probably must use something like Nx to just run those tests which hae been affected. But I would still like to know if there is a faster test runner in NPM echo system (or if possible outside of it) to run my tests faster with smaller memory footprint.
I have looked at
rjest, but I am unsure still about it. Any comment?I also am considering if I should use Bun, but then we really do not have the Jest's echo system: https://app.studyraid.com/en/read/11127/344668/comparing-bun-with-jest
So what are your take on this?
All reactions