Testing Overview
The Template Playground uses a comprehensive testing strategy with two main testing frameworks:- Vitest: Fast unit and integration tests for components and logic
- Playwright: End-to-end tests for full user journeys
Running Tests
Unit Tests
Run all unit tests with Vitest:vitest run for CI/CD environments.
End-to-End Tests
Run E2E tests with Playwright:Unit Testing with Vitest
Configuration
Vitest is configured invite.config.ts:
Setup File
The test setup (src/utils/testing/setup.ts) includes:
- @testing-library/jest-dom: Custom matchers for DOM assertions
- jest-canvas-mock: Mock canvas APIs
- Global test utilities and configurations
Writing Component Tests
Basic Component Test
Testing User Interactions
Testing with Zustand Store
Testing Utilities
Testing Error Handling
Testing Compression
Test Organization
End-to-End Testing with Playwright
Configuration
Playwright is configured inplaywright.config.ts with:
- Multiple browser configurations (Chromium, Firefox, WebKit)
- Screenshot on failure
- Video recording for failed tests
- Retry logic for flaky tests
Writing E2E Tests
Basic E2E Test
Testing User Workflows
Testing Error States
Testing Best Practices
General Guidelines
Write Clear Test Names
Write Clear Test Names
Use descriptive test names that explain what is being tested:
Follow Arrange-Act-Assert Pattern
Follow Arrange-Act-Assert Pattern
Structure tests clearly:
Avoid Testing Implementation Details
Avoid Testing Implementation Details
Test behavior, not implementation:
Use Data Test IDs Sparingly
Use Data Test IDs Sparingly
Prefer accessible queries:
Mocking
Mocking Functions
Mocking Modules
Continuous Integration
Tests run automatically on:- Pull request creation and updates
- Commits to main branch
- Pre-release checks
CI Test Commands
Coverage Goals
Aim for:- 80%+ overall coverage: Core functionality should be well-tested
- Critical paths: 100% coverage for state management and template processing
- Edge cases: Test error conditions and boundary cases
Next Steps
Contribution Guidelines
Review our contribution standards and workflow
Development Setup
Set up your development environment