E2E Testing
E2E tests are Playwright specs intests/e2e/*.spec.ts. The dev server starts automatically — Playwright launches it before running tests. Tests run against both ChatGPT and Claude hosts via Playwright projects.
- pnpm
- npm
- yarn
Writing E2E Tests
Importtest and expect from sunpeak/test. The mcp fixture provides protocol-level methods, and the inspector fixture handles rendering, double-iframe traversal, and host selection:
- Standalone (any MCP server)
- sunpeak framework
For non-sunpeak projects, pass a For stdio servers, pass a command and optional configuration:
server option to defineConfig:URL Parameters
Protocol methods
Test your MCP server at the protocol level without rendering anything:renderTool
inspector.renderTool renders the tool result in the inspector and returns an InspectorResult with both the MCP data and a UI locator. With input, the tool is called on the real server. Without input, simulation fixture data is used when available. The returned InspectorResult includes a source field ('fixture' or 'server') indicating where the data came from, and a screenshot() method for visual regression. Inspector sidebars are hidden by default in this fixture so app e2e and visual tests do not depend on inspector layout. Pass { sidebar: true } when a test needs the inspector controls.
theme, displayMode, sidebar, and timeout. Per-call timeout overrides the config default.
Configuring default timeouts
Testing Backend-Only Tools
If your resource calls backend tools viauseCallServerTool, define mock responses using the serverTools field in the simulation JSON. The inspector resolves these mocks based on the tool call arguments:
serverTools field supports both simple (single result) and conditional (when/result array) forms. See Simulation API Reference for details.
Example E2E Test Structure
A typical e2e test file tests a resource across different modes. Each test runs automatically against both ChatGPT and Claude hosts:Best Practices
Keep tests simple
Keep tests simple
Test one thing per test case. Clear tests are maintainable tests.
Use meaningful test descriptions
Use meaningful test descriptions
Test user-facing behavior
Test user-facing behavior
Test what users see and interact with, not implementation details:
Test across hosts, themes, and display modes
Test across hosts, themes, and display modes
Use See MCP Apps Display Modes for how hosts handle inline, fullscreen, and PiP views.
inspector.renderTool() options to test your resources in different configurations. Tests run across ChatGPT and Claude hosts automatically via Playwright projects. Pass theme and displayMode as options:Add visual regression tests for key states
Add visual regression tests for key states
Use
result.screenshot() in tests that cover important visual states (light/dark theme, fullscreen, empty states). Visual tests catch CSS regressions that functional assertions miss:Clean up after tests
Clean up after tests
Use
afterEach to reset state between tests:Learn More
Visual Regression Testing
Screenshot comparison and baseline management.
Inspector
The runtime that powers E2E tests.
Simulations
JSON schema, conventions, and auto-discovery.