DEV Community

Alex Spinov
Alex Spinov

Posted on

Vitest Has a Free Test Runner That Makes Jest Feel Slow

Vitest runs on Vite's dev server. Tests execute in milliseconds, not seconds. Compatible with Jest's API but dramatically faster.

Why Developers Are Leaving Jest

Jest was built for a different era. It has its own module system, its own transforms, its own config. Running a single test file can take 3-5 seconds just to start.

Vitest shares Vite's pipeline. Your tests use the same config, same transforms, same module resolution as your app. Cold start: <300ms.

What You Get for Free

Jest-compatible APIdescribe, it, expect, vi.fn(), vi.mock() — just works
Native ESM — no transforms needed for import/export
TypeScript support — zero config, uses Vite's esbuild
Watch mode — only re-runs affected tests (HMR-level speed)
In-source testing — write tests in the same file as your code
UI mode — visual test runner in the browser
Coverage — built-in via v8 or istanbul

Quick Start

npm i -D vitest
Enter fullscreen mode Exit fullscreen mode

Add to package.json:

{ "scripts": { "test": "vitest" } }
Enter fullscreen mode Exit fullscreen mode

Write a test:

import { describe, it, expect } from 'vitest';

describe('math', () => {
  it('adds numbers', () => {
    expect(1 + 1).toBe(2);
  });
});
Enter fullscreen mode Exit fullscreen mode

Run: npm test. That's it. No jest.config.js, no babel transforms, no module name mapper.

Speed Comparison

Real project with 500 tests:

  • Jest: 45 seconds
  • Vitest: 3 seconds

Watch mode re-run after one file change:

  • Jest: 8 seconds
  • Vitest: 200ms

Killer Features

In-source testing:

export function add(a: number, b: number) { return a + b; }

if (import.meta.vitest) {
  const { it, expect } = import.meta.vitest;
  it('adds', () => { expect(add(1, 2)).toBe(3); });
}
Enter fullscreen mode Exit fullscreen mode

Tests live next to the code. They're tree-shaken out of production builds.

If you're using Vite and still running Jest — you're leaving 10x performance on the table.


Need web scraping or data extraction? Check out my tools on Apify — get structured data from any website in minutes.

Custom solution? Email spinov001@gmail.com — quote in 2 hours.

Top comments (0)