Skip to main content

E2E Testing

E2E tests are Playwright specs in tests/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.

Writing E2E Tests

Import test and expect from sunpeak/test. The mcp fixture provides protocol-level methods, and the inspector fixture handles rendering, double-iframe traversal, and host selection:
The config is a one-liner:
This auto-detects sunpeak projects and creates per-host Playwright projects (chatgpt, claude). Each test runs once per host automatically — no host loops needed.
For non-sunpeak projects, pass a server option to defineConfig:
For stdio servers, pass a command and optional configuration:

URL Parameters

Inspector set to fullscreen dark mode via URL params Inspector set to inline light mode via URL params

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.
The options object accepts 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 via useCallServerTool, define mock responses using the serverTools field in the simulation JSON. The inspector resolves these mocks based on the tool call arguments:
The 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

Test one thing per test case. Clear tests are maintainable tests.
Test what users see and interact with, not implementation details:
Use 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:
See MCP Apps Display Modes for how hosts handle inline, fullscreen, and PiP views.
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:
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.