This document provides comprehensive information for AI agents working on the Vitest codebase.
Vitest is a next-generation testing framework powered by Vite. This is a monorepo using pnpm workspaces with the following key characteristics:
- Language: TypeScript/JavaScript (ESM-first)
- Package Manager: pnpm (required)
- Node Version: ^20.0.0 || ^22.0.0 || >=24.0.0
- Build System: Vite + Rollup
- Monorepo Structure: 15+ packages in
packages/directory
- Run
pnpm installto install dependencies - Run
pnpm buildto build all packages - Install Playwright browsers when working with browser features:
npx playwright install --with-deps
pnpm build- Build all packagespnpm dev- Watch mode for developmentpnpm lint- Run ESLintpnpm lint:fix- Fix linting issues automaticallypnpm typecheck- Run TypeScript type checking
- All tests:
CI=true pnpm test:ci - Examples:
CI=true pnpm test:examples - Specific test suite:
CI=true cd test/<test-folder> && pnpm test <test-file> - Core directory test:
CI=true pnpm test <test-file>(fortest/core) - Browser tests:
CI=true pnpm test:browser:playwrightorCI=true pnpm test:browser:webdriverio
IMPORTANT: Do NOT use -- when passing test filters to pnpm.
Using -- causes pnpm to drop the filter, resulting in a full test run instead of a filtered one.
# WRONG - runs ALL tests (filter is ignored):
pnpm test -- basic.test.ts -t 'expect'
# CORRECT - runs only matching tests:
pnpm test basic.test.ts -t 'expect'When writing tests, AVOID using toContain for validation. Prefer using toMatchInlineSnapshot to include the test error and its stack. If snapshot is failing, update the snapshot instead of reverting it to toContain.
If you need to typecheck tests, run pnpm typecheck from the root of the workspace.
runInlineTestsfromtest/test-utils/index.ts- You must use this for complex file system setups (>1 file)runVitestfromtest/test-utils/index.ts- You can use this to run Vitest programmatically- No mocking policy - You must never mock anything in tests
vitest- Main testing frameworkbrowser- Browser testing supportui- Web UI for test resultsrunner- Test runner coreexpect- Assertion libraryspy- Mocking and spying utilitiessnapshot- Snapshot testingcoverage-v8/coverage-istanbul- Code coverageutils- Shared utilitiesmocker- Module mocking
test/core- Core functionality teststest/browser- Browser-specific tests- Various test suites organized by feature
docs/- Documentation (Vite-powered)examples/- Example projects and integrationsscripts/- Build and development scripts.github/- GitHub Actions workflowspatches/- Package patches via pnpm
- Always run
pnpm lint:fixafter making changes - Fix non-auto-fixable errors manually
- Strict TypeScript configuration
- Use
pnpm typecheckto verify types - Configuration files:
tsconfig.base.json,tsconfig.build.json,tsconfig.check.json
- ESM-first approach
- Follow existing patterns in the codebase
- Use utilities from
@vitest/utils/*when available. Never import from@vitest/utilsmain entry point directly. - Do not add comments explaining what the line does unless prompted to.
- Identify the appropriate package in
packages/ - Follow existing code patterns
- Add tests using testing utilities
- Run
pnpm build && pnpm typecheck && pnpm lint:fix - Add tests with relevant test suites
- Use VS Code:
⇧⌘B(Shift+Cmd+B) orCtrl+Shift+Bfor dev tasks - Check
scripts/directory for specialized development tools
- Main docs in
docs/directory - Built with
pnpm docs:build - Local dev server:
pnpm docs - When adding cli options, run
pnpm -C docs run cli-tableto update the cli-generated.md file
- Vite - Build tool and dev server
- Rollup - Bundler
- ESLint - Linting
- TypeScript - Type checking
- Playwright - Browser testing
- Chai/Expect - Assertions
- Tinypool - Worker threading
- Tinybench - Benchmarking
- tsx - TypeScript execution
- ni/nr - Package manager abstraction
- bumpp - Version bumping
- changelogithub - Changelog generation
- Two modes: Playwright and WebDriverIO
- Separate test commands for each
- Component testing supported (Vue, React, Svelte, Lit, Marko)
- This is a performance-critical testing framework
- Pay attention to import costs and bundle size
- Use lazy loading where appropriate
- Consider worker thread implications
- Ensure pnpm is used (not npm/yarn)
- Build before running tests
- Check Node.js version compatibility
- Playwright browsers must be installed for browser tests
- Check existing issues and documentation
- Review CONTRIBUTING.md for detailed guidelines
- Follow patterns in existing code