"Five minutes from npm install to the first green check."
Install in One Line
Vitest is one dependency for the runner, plus whatever DOM emulator and Testing Library helpers you want layered on top. For a typical React + TypeScript project, the install command is one line.
The --save-dev flag (or -D) puts everything under devDependencies — these packages never ship to your production bundle, and they shouldn't.
The Minimal Config
If your project already has vite.config.ts, Vitest reads its test field directly — you might not need a separate config file at all. If you do want one (test-specific environment, aliases that differ from build), drop a vitest.config.ts alongside.
Two fields earn their keep on day one:
environment:'happy-dom'for component tests,'node'for pure logic tests. Set per-file with// @vitest-environment nodeat the top if you mix.globals:trueexposesdescribe,it,expectglobally without import. Convenience vs explicitness — pick the team default and stick with it. Code below uses globals off and imports explicitly because that's what reads better in code review.
test script to package.json. Long-term, you'll type npm test a thousand more times than npx vitest run. Set it up once: "test": "vitest", "test:run": "vitest run", "test:ui": "vitest --ui". The CLI's two-character commands compound.The First Test File
Convention: put test files next to the code they test (format.ts + format.test.ts) or in a parallel __tests__/ folder. The next-to convention is easier to navigate and easier to delete cleanly when the code goes away. The __tests__/ convention isolates better for monorepos.
Vitest discovers files matching *.{test,spec}.{ts,tsx,js,jsx} by default — no manifest, no opt-in registration. Drop a file, save, and the watcher picks it up in the next tick.
setupFiles — the One Hook You'll Reach For
When you need code to run before every test file — extending matchers, polyfilling, configuring testing-library — that's setupFiles. Most React projects use one: a single vitest.setup.ts that imports @testing-library/jest-dom/vitest to expose matchers like toBeInTheDocument() and toHaveClass().
environment, setupFiles, and maybe globals. If your config grows past 30 lines, ask why — usually you've grown organic plugins that another tool already does, or you've enabled features (coverage, UI mode) at the wrong layer.