E2E Testing Guidelines
⚠️ CRITICAL: Always Use Docker for E2E Tests
NEVER run Playwright tests directly on your local machine for this project. Always use Docker.
Why Docker Only?
- •Screenshot Consistency: Playwright screenshots are OS-dependent. Running tests on macOS will generate
darwinscreenshots, while CI runs on Linux and generateslinuxscreenshots. - •CI Compatibility: Our CI pipeline runs tests in Docker with Linux. Local screenshots won't match CI screenshots.
- •Font Rendering: Different operating systems render fonts differently, causing pixel-perfect screenshot comparisons to fail.
- •Reproducibility: Docker ensures everyone gets identical test results regardless of their local environment.
Running E2E Tests
Update Screenshots (Most Common)
When you've made visual changes and need to update the baseline screenshots:
npm run test:e2e:docker:update
This will:
- •Build the app with
VITE_TYPEWRITER_SPEED=0(disables animations) - •Run ALL Playwright tests
- •Update screenshot baselines in
test/**/*-linux.png
Update Specific Test Screenshots
To update screenshots for a specific test file only:
./scripts/playwright-docker.sh test/e2e-mobile.test.ts --update-snapshots
Run Tests Without Updating
To verify tests pass without changing screenshots:
npm run test:e2e:docker
Run Specific Test
./scripts/playwright-docker.sh test/e2e-mobile.test.ts
Environment Variables
VITE_TYPEWRITER_SPEED
Set to 0 to disable the typewriter animation effect during tests. This eliminates timing issues and race conditions.
- •Already configured in
scripts/playwright-docker.sh - •Already configured in
playwright.config.tswebServer command - •Applied during build time via Vite
How It Works
// src/hooks/useTypewriter.ts
const envSpeed = import.meta.env.VITE_TYPEWRITER_SPEED;
if (envSpeed === "0") {
// Text appears instantly instead of character-by-character
}
Common Pitfalls
❌ DON'T: Run tests locally
# This will create darwin screenshots - DON'T DO THIS npm run test:e2e npx playwright test --update-snapshots
✅ DO: Run tests in Docker
# Always use the Docker script npm run test:e2e:docker:update ./scripts/playwright-docker.sh --update-snapshots
❌ DON'T: Commit darwin screenshots
# If you accidentally created darwin screenshots rm -rf test/**/*-darwin.png git status # Should only show *-linux.png files
✅ DO: Only commit linux screenshots
git status # Should show files like: # test/e2e-mobile.test.ts-snapshots/01-mobile-bios-mobile-chrome-linux.png
Test File Organization
test/
├── e2e-mobile.test.ts # Mobile-specific tests
├── e2e-desktop.test.ts # Desktop-specific tests (if exists)
└── e2e-mobile.test.ts-snapshots/ # Auto-generated by Playwright
├── 00-mobile-ascii-welcome-mobile-chrome-linux.png
├── 01-mobile-bios-mobile-chrome-linux.png
└── ...
Mobile Test Helpers
dismissBiosIfPresent()
Always call this helper after dismissing the ASCII welcome screen in mobile tests:
await page.locator("[data-e2e=mobile-ascii-welcome]").tap();
await dismissBiosIfPresent(page);
This handles the BIOS startup screen that shows once per session.
Timeouts
Mobile tests use longer timeouts to account for the typewriter effect (even though it's disabled in tests, we keep timeouts for safety):
- •Dialog appearance:
15000ms - •Options appearing:
15000ms - •Message typing:
10000ms
Debugging Failed Tests
- •Check Docker is running:
docker ps - •Check screenshots: Look at the diff images in test results
- •Run specific test:
./scripts/playwright-docker.sh test/e2e-mobile.test.ts --debug - •Check environment variables: Ensure
VITE_TYPEWRITER_SPEED=0is set
CI Integration
The CI pipeline automatically:
- •Runs
npm run test:e2e:docker - •Compares screenshots against committed
*-linux.pngfiles - •Fails if screenshots don't match (visual regression detected)
Visual Regression Testing
When you change UI:
- •Make your changes
- •Run
npm run test:e2e:docker:update - •Review the updated screenshots carefully
- •Commit the updated
*-linux.pngfiles - •NEVER commit
*-darwin.pngor*-win32.pngfiles
Quick Reference
| Task | Command |
|---|---|
| Update all screenshots | npm run test:e2e:docker:update |
| Update specific test | ./scripts/playwright-docker.sh test/FILE.test.ts --update-snapshots |
| Run all tests | npm run test:e2e:docker |
| Run specific test | ./scripts/playwright-docker.sh test/FILE.test.ts |
| Debug test | ./scripts/playwright-docker.sh test/FILE.test.ts --debug |
Remember: If you see darwin or win32 in your git status, you did something wrong. Only linux screenshots should be committed.