Post

⚡️ Yes! Vitest is generally faster than Jest -- but is feedback speed the only factor that matters? If you are still on the fence about switching to Vitest, here are 15+ reasons that will convince you! 📝 cookbook.marmicode.io/angular/why-... #javascript #angular #testing

23 reposts96 likes

A couple of questions: - Isn't "multi-thread mode" misleading? Shouldn't it be called "multi-cpu mode"? - Regarding vm.Module not supporting ESM, it's unfortunate. Shouldn't this be a call out for Node.js overlooking ESM in important parts of the runtime?

Why do you think multi-thread is misleading? It’s using node worker threads. Node VMs support ESM but it’s experimental. + conceptually speaking node VM isolation is prone to memory leaks as imported modules might have side effects etc…

Great post! Vitest does indeed allow users to choose the isolation mode and parallelization method (process, threads) based on their needs. The VM isolation on Vitest has same issues as Jest; node:vm leaks memory and we need to restart forks/threads when a certain limit is reached to prevent OOM.

Choosing between forks or threads is also great, as there are many packages that cause segfaults when run on 'node:worker_threads'. Typically these packages are built using Node-API with C++/Rust/Go. We've listed such packages in github.com/vitest-dev/v.... None of those packages crash with forks.

It's also worth to note that comparing non-isolation mode against Jest isn't really fair, and we've seen even ~10x faster execution times on Vitest without isolation: github.com/vitest-dev/v... Though I think there is a community-driven Jest runner that provides non-isolation mode there too.

I think I have to learn how to switch my Nx monorepo from jest to vitest, esp. because I need ES2022 to compile my code and Jest has problems with async tests (some weird Angular error about "ProxyZone" I don't remember...).

If you’re not in a rush and can wait few days. I am working on a migration guide that should help you. Hard to speculate on the root cause of the ProxyZone but in testing it sometimes related to async/await not being downgraded… and both jest preset angular & vitest plugin handle that properly.