Skip to main content

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.
Unit tests run your component and hook logic in isolation using Vitest with happy-dom. They’re fast, don’t require the inspector or a browser, and test tool handlers, React components, and data transformations directly.

Setup

Unit tests live in tests/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:

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

Add "lint": "eslint . --ext .ts,.tsx" to package.json scripts.
TypeScript is already installed. Add to package.json scripts:
Add "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.