Testing Guide
Opal Editor uses two testing approaches: custom unit tests with the TestSuite framework and end-to-end tests with Playwright. This guide covers both testing methodologies.Testing Frameworks
Unit Tests: TestSuite
Opal Editor uses a custom lightweight testing framework located at~/workspace/source/src/lib/tests/TestSuite.ts:1-127. This framework provides:
- Simple, readable test syntax
- Async test support
- Rich assertion methods
- Clear console output
End-to-End Tests: Playwright
Playwright tests ensure the entire application works correctly in real browsers. Configuration is at~/workspace/source/playwright.config.ts:1-52.
Running Tests
Run All E2E Tests
Run Tests with UI
Run Tests in Headed Mode
Debug Tests
Run Unit Tests
Playwright Configuration
The Playwright config (~/workspace/source/playwright.config.ts:1-52) includes:
- Test directory:
playwright-tests/ - Base URL:
http://localhost:3000 - Parallel execution: Enabled by default
- Retries: 2 retries on CI, 0 locally
- Trace collection: On first retry (for debugging)
- Browsers: Chromium, Firefox, WebKit
Web Server
Playwright automatically starts the dev server before running tests:Writing E2E Tests
Test File Location
Place E2E tests in theplaywright-tests/ directory:
Test Structure
Example from~/workspace/source/playwright-tests/workspace-creation.spec.ts:1-112:
Best Practices for E2E Tests
1. Use semantic selectorsWriting Unit Tests
Test File Location
Place unit tests next to the code they test with a.test.ts suffix:
TestSuite API
The custom TestSuite framework (~/workspace/source/src/lib/tests/TestSuite.ts:1-127) provides:
Creating a test suite:
Example Unit Test
From~/workspace/source/src/services/build/BuildStrategies.test.ts:50-69:
Unit Test Best Practices
1. Test one thing per testTest Coverage
Currently tested areas:-
E2E Tests:
- Workspace creation flow
- File creation and management
- UI interactions
-
Unit Tests:
- Build strategies (Freeform, Eleventy)
- Template processing (Nunjucks, Liquid, Mustache, EJS)
- File system operations
- Event emitters
- Promise polyfills
Areas Needing Tests
Consider adding tests for:- Git operations (clone, commit, push, pull)
- Publishing workflows (Netlify, Vercel, Cloudflare)
- Editor features (markdown editing, image upload)
- Search functionality
- Theme switching
- Import/export features
Debugging Tests
Playwright Debugging
1. Use Playwright InspectorUnit Test Debugging
1. Add console logsContinuous Integration
On CI environments:- Tests retry up to 2 times on failure
- Tests run sequentially (not in parallel)
- Dev server must start fresh (no reuse)
- HTML reports are generated for debugging
Test Organization
File Naming
- E2E tests:
*.spec.tsinplaywright-tests/ - Unit tests:
*.test.tsnext to source files
Test Grouping
Contributing Tests
When contributing code:- Add E2E tests for new user-facing features
- Add unit tests for complex business logic
- Ensure all tests pass before submitting PR
- Update this guide if introducing new testing patterns
Resources
- Playwright Documentation
- Playwright Best Practices
- Opal Editor on GitHub - View source code including TestSuite, E2E tests, and unit tests