DEV Community

56kode
56kode

Posted on

Migration from Jest to Vitest: A Real-World Experience with 2900+ Tests

We recently completed a migration from Jest to Vitest in our React/TypeScript project. Here's our complete feedback, good and bad, no marketing talk.

Why We Migrated

Our test suite was growing (2900+ tests), and we faced recurring issues with Jest:

  • Random freezes requiring --max-workers flag
  • ESM compatibility nightmares
  • Complex configuration to handle modern packages
  • High memory consumption

What We Learned

  1. ESM Support is a Game Changer
    No more complicated transpilation config! We removed 20+ lines of module transformation rules.

  2. Performance Surprises
    The speed gains weren't exactly what we expected. Some tests run faster, others slower, and it varies by machine (30s to 5min on different computers).

  3. Hidden Issues Revealed
    Vitest caught empty snapshots that Jest was silently passing. Some of our tests were green... but testing nothing! 🤔

  4. i18n Optimization
    By properly mocking i18next, we divided some test execution times by 3. Worth the effort!

Quick Wins

  • Happy DOM instead of jsdom: Almost 1 minute saved
  • Direct ESM support: Cleaner configuration
  • Better error detection: No more false positives

Main Challenges

  • Portal handling requires specific mocks
  • Default exports need explicit configuration
  • Some tests needed adaptation for stricter checks
  • Translation mocking was complex but worth it

Our complete guide includes all configurations, code examples, and detailed solutions.

Want all the details? Check the full article here:https://www.56kode.com/posts/migration-from-jest-to-vitest/

Top comments (0)