Overview
TemPad Dev uses Vitest for all testing with a strict coverage model and split runtime strategy.Tech Stack
- Test runner: Vitest 4.0.18
- Browser tests: @vitest/browser-playwright + Chromium
- Coverage provider: Istanbul
- Package manager: pnpm
Quick Start
First-Time Setup
Install browser test runtime (once per machine):Standard Pre-PR Verification
Run this sequence before submitting changes:Command Reference
Root Commands
Run from repository root:Per-Package Commands
Extension
MCP Server
Plugins
Shared
Test Organization
File Naming Conventions
Tests live under package-localtests/ directories:
*.test.ts- Node runtime tests*.browser.test.ts- Browser runtime tests (Playwright)
Runtime Split
Node Runtime
For pure logic, utilities, and server-side code:- Default Vitest environment
- No DOM APIs
- Fast execution
- Used by: mcp-server, plugins, shared, extension (non-UI)
Browser Runtime
For DOM manipulation, browser APIs, and UI components:- Playwright Chromium
- Real browser environment
- Used by: extension UI tests
- Never use jsdom (not supported)
Coverage Strategy
Configuration
- Provider: Istanbul (required to avoid V8 parse failures)
- Config: Root
vitest.config.ts - Excludes:
**/dist/**,**/.output/**
Coverage Targets
Strict pure coverage enforced on:Extension
- Pure utility functions
- Formatters and transformers
MCP Server
src/asset-utils.tssrc/tools.tssrc/config.tssrc/request.tssrc/asset-store.tssrc/asset-http-server.tssrc/shared.ts
Shared
src/index.tssrc/mcp/constants.tssrc/mcp/errors.tssrc/mcp/index.tssrc/mcp/protocol.tssrc/mcp/tools.tssrc/figma/index.tssrc/figma/color.tssrc/figma/gradient.tssrc/figma/stroke.tssrc/figma/style-resolver.ts
Plugins
src/index.ts
Running Coverage
coverage/ (gitignored).
Test Authoring Rules
Deterministic Tests
Tests must be deterministic:- No system clock dependence - Use mocked time
- No random IDs - Use fixed seeds or mocks
- No network calls - Mock external services
- No filesystem side effects - Use in-memory fixtures
Pure Function Testing
For pure functions, enforce strict coverage:Browser Testing
For DOM/UI code, use Playwright browser tests:tests/components/MyComponent.browser.test.ts
Regression Tests
Add regression assertions in the same PR as behavior changes:Required Checks by Change Type
Always Required
Pure Utility/Formatter Changes
Extension Build/Runtime Changes
DOM/Browser Behavior Changes
Cross-Package Contract Changes
Validate in order:pnpm --filter @tempad-dev/shared test:runpnpm --filter @tempad-dev/mcp test:runpnpm --filter @tempad-dev/extension test:run
Troubleshooting
Coverage Parse Errors
Symptom: Files unexpectedly excluded or V8 parse errors Solution:- Confirm provider is
istanbulinvitest.config.ts - Clean install:
Build Artifacts in Coverage
Symptom:dist/ or .output/ files appear in reports
Solution:
- Check root
vitest.config.tsexcludes - Ensure tests import from
src/, notdist/
Package vs Root Coverage Differences
Symptom: Package coverage passes, root coverage fails Solution: Root run aggregates workspace projects. Validate against root config first:Browser Tests Fail to Launch
Symptom: Playwright errors or missing browser Solution:Tests Pass Locally, Fail in CI
Common causes:- Non-deterministic tests (time, random, network)
- Missing setup step (browser runtime)
- Environment-specific paths or configs
Best Practices
- Write tests first for new features (TDD)
- Keep tests focused - One assertion per test when possible
- Use descriptive names -
it('returns null when input is empty') - Avoid test interdependence - Each test should be isolated
- Mock external dependencies - Network, filesystem, browser APIs
- Update tests with code - Never leave tests broken
- Add regression tests - For every bug fix
- Use snapshots sparingly - Only for stable output formats
Related Documentation
- Testing architecture:
docs/testing/architecture.md(in source repo) - Extension requirements:
docs/extension/requirements.md(in source repo) - Extension design:
docs/extension/design.md(in source repo) - Architecture
- Building