Vitest in Practice
Vitest is Vite's test runner — it reuses your Vite config, so ESM, TypeScript, and path aliases just work.
Setup
// vitest.config.ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
include: ['**/__tests__/**/*.test.ts'],
globals: true,
},
})
ts
Snapshot Tests
Snapshots shine for transformation pipelines — markdown → HTML, AST → output, etc.:
import { expect, test } from 'vitest'
import { process } from '../src/process.ts'
test('processes headings', () => {
expect(process('# Hello')).toMatchSnapshot()
})
ts
Review snapshot diffs carefully — they're only as good as the reviewer.
Watch Mode
vitest (without run) enters watch mode by default. Only tests affected by changed files re-run. Fast feedback.