This document explains how to run and manage the Playwright visual tests for the DevRoast application.
We use Playwright for end-to-end visual testing and regression detection. All tests verify that the application UI renders correctly across different pages and viewport sizes.
Playwright and its browser dependencies are already configured:
pnpm install # Install dependencies (includes @playwright/test)Browsers are downloaded automatically on first test run.
pnpm exec playwright test visual-tests.spec.ts --config=playwright.config.tspnpm exec playwright test visual-tests.spec.ts --config=playwright.config.ts --headedpnpm exec playwright test visual-tests.spec.ts --config=playwright.config.ts --debugpnpm exec playwright show-report-
Dev server must be running on
http://localhost:3000pnpm dev
-
Database must have data - Tests query real submissions from the database or fall back to mock data
The test suite includes 14 comprehensive tests covering:
- Page structure with all sections rendered
- Animated metrics (codes roasted, average score)
- Leaderboard preview with syntax highlighting
- Navigation links and interactions
- Data rendering with proper loading states
- Syntax-highlighted code in table rows (100+ submissions)
- Scrollable code containers with max-height styling
- Clickable rows that link to results pages
- Dynamic ID resolution from leaderboard
- Code feedback structure and display
- Syntax highlighting with Shiki renderer
- Mobile viewport testing (375x667px)
- Home and leaderboard pages on mobile
- Baseline snapshots for home page
- Baseline snapshots for leaderboard page
Syntax Highlighting
- Tests verify Shiki-rendered code is properly displayed
- Supports multiple languages with proper fallbacks
- Uses Vesper theme for dark aesthetic
Scrollable Code
- Leaderboard code containers have max-height: 120px
- Home preview code has max-height: 80px
- Tests verify overflow scrolling works correctly
Dynamic Loading
- Tests wait for
networkidlestate before assertions - Handles async Suspense boundaries gracefully
- Timeouts set to 10 seconds for slow connections
Visual Regression
- Baseline images stored in
visual-tests.spec.ts-snapshots/ - Automatic comparison on future test runs
- Captures full-page screenshots for comparison
- Ensure dev server is running:
pnpm dev - Check localhost:3000 is accessible
- Increase timeout if running on slow machine (edit
playwright.config.ts)
- Add
--headedflag to see browser visually - Use
--debugflag for step-by-step debugging - Check if page structure changed - update selectors
- Expected: Database content varies between runs
- For intentional visual changes: run with
--update-snapshotspnpm exec playwright test visual-tests.spec.ts --config=playwright.config.ts --update-snapshots
File: playwright.config.ts
Key settings:
baseURL:http://localhost:3000(dev server URL)timeout:30000ms(per test timeout)workers:1(run sequentially to avoid port conflicts)reporter:html(generates detailed test report)screenshot:only-on-failure(capture failures for debugging)
File: visual-tests.spec.ts
The test file includes:
- 14 comprehensive test cases
- Smart selectors that adapt to page structure
- Proper loading state handling
- Accessibility-first assertions
To integrate tests into your CI pipeline:
# Example GitHub Actions workflow
- name: Run Playwright tests
run: |
pnpm install
pnpm build
pnpm dev &
sleep 5
pnpm exec playwright test visual-tests.spec.ts --config=playwright.config.tsWhen making UI changes:
-
Run tests locally first
pnpm dev & pnpm exec playwright test visual-tests.spec.ts --config=playwright.config.ts
-
Update selectors if HTML changes
- Edit selectors in
visual-tests.spec.ts - Ensure selectors are resilient (e.g., use
has-textfor text content)
- Edit selectors in
-
Update visual baselines if intentional
pnpm exec playwright test visual-tests.spec.ts --config=playwright.config.ts --update-snapshots
-
Commit updated snapshots with your changes
git add visual-tests.spec.ts-snapshots/ git commit -m "test: update Playwright snapshots after UI changes"
playwright.config.ts- Playwright configurationvisual-tests.spec.ts- Test definitions (14 tests)visual-tests.spec.ts-snapshots/- Visual baseline imageshome-page-chromium-darwin.pngleaderboard-page-chromium-darwin.png
- Add tests for new features (code submission form, results interactions)
- Integrate with CI/CD pipeline for automated testing
- Monitor visual regressions in pull requests
- Add performance testing for page load times