mirror of
https://github.com/vitest-dev/vitest.git
synced 2025-12-08 18:26:03 +00:00
4.7 KiB
4.7 KiB
Vitest AI Agent Guide
This document provides comprehensive information for AI agents working on the Vitest codebase.
Project Overview
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
Setup and Development
Initial Setup
- Run
pnpm installto install dependencies - Run
pnpm buildto build all packages - Install Playwright browsers when working with browser features:
npx playwright install --with-deps
Key Scripts
pnpm build- Build all packagespnpm dev- Watch mode for developmentpnpm lint- Run ESLintpnpm lint:fix- Fix linting issues automaticallypnpm typecheck- Run TypeScript type checking
Testing
Running Tests
- 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
Testing Utilities
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
Project Structure
Core Packages (packages/)
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 Organization (test/)
test/core- Core functionality teststest/browser- Browser-specific tests- Various test suites organized by feature
Important Directories
docs/- Documentation (Vite-powered)examples/- Example projects and integrationsscripts/- Build and development scripts.github/- GitHub Actions workflowspatches/- Package patches via pnpm
Code Style and Conventions
Formatting and Linting
- Always run
pnpm lint:fixafter making changes - Fix non-auto-fixable errors manually
TypeScript
- Strict TypeScript configuration
- Use
pnpm typecheckto verify types - Configuration files:
tsconfig.base.json,tsconfig.build.json,tsconfig.check.json
Code Quality
- 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.
Common Workflows
Adding New Features
- 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
Debugging
- Use VS Code:
⇧⌘B(Shift+Cmd+B) orCtrl+Shift+Bfor dev tasks - Check
scripts/directory for specialized development tools
Documentation
- Main docs in
docs/directory - Built with
pnpm docs:build - Local dev server:
pnpm docs
Dependencies and Tools
Key Dependencies
- Vite - Build tool and dev server
- Rollup - Bundler
- ESLint - Linting
- TypeScript - Type checking
- Playwright - Browser testing
- Chai/Expect - Assertions
- Tinypool - Worker threading
- Tinybench - Benchmarking
Development Tools
- tsx - TypeScript execution
- ni/nr - Package manager abstraction
- bumpp - Version bumping
- changelogithub - Changelog generation
Browser Testing
- Two modes: Playwright and WebDriverIO
- Separate test commands for each
- Component testing supported (Vue, React, Svelte, Lit, Marko)
Performance Considerations
- This is a performance-critical testing framework
- Pay attention to import costs and bundle size
- Use lazy loading where appropriate
- Consider worker thread implications
Troubleshooting
Common Issues
- Ensure pnpm is used (not npm/yarn)
- Build before running tests
- Check Node.js version compatibility
- Playwright browsers must be installed for browser tests
Getting Help
- Check existing issues and documentation
- Review CONTRIBUTING.md for detailed guidelines
- Follow patterns in existing code