Overview
Unit tests are for sunpeak app framework projects (created with
sunpeak new). If you’re using sunpeak as a standalone testing framework for an existing MCP server, use E2E tests instead, which test your server over the wire via the MCP protocol.- pnpm
- npm
- yarn
Setup
Unit tests live intests/unit/ (or any *.test.ts / *.spec.ts file matched by your Vitest config). For sunpeak framework projects, Vitest is pre-configured with happy-dom.
For standalone usage, add Vitest to your project:
- pnpm
- npm
- yarn
Writing Unit Tests
Test component rendering, hook logic, and data transformations without the full inspector stack.Testing Components
Testing Data Transformations
Testing Tool Handlers
Tool handlers are plain async functions, so you can test them directly:When to Use Unit Tests vs E2E Tests
Unit tests and E2E tests are complementary. Unit tests catch logic bugs fast. E2E tests catch rendering and integration issues across the full inspector stack.
Additional Quality Tools
Linting (ESLint)
Linting (ESLint)
- pnpm
- npm
- yarn
"lint": "eslint . --ext .ts,.tsx" to package.json scripts.Type Checking
Type Checking
TypeScript is already installed. Add to package.json scripts:
Formatting (Prettier)
Formatting (Prettier)
- pnpm
- npm
- yarn
"format": "prettier --write ." to package.json scripts.Learn More
Vitest Docs
Learn more about Vitest for unit testing.
E2E Testing
Full-stack testing with the inspector and Playwright.