This project uses a robust testing pipeline combining Vitest and Playwright to ensure the GameBoy component and site functionality work flawlessly across browsers.
Unit tests focus on isolated logic and utility functions that don't depend on browser rendering.
- Location:
tests/unit/ - Config:
vitest.config.ts - Command:
npm run test:unit
E2E tests simulate real user interactions in a browser environment. The suite covers 100% of the interactive features of the device.
- Location:
tests/e2e/gameboy.spec.ts - Config:
playwright.config.ts - Command:
npm run test:e2e
The E2E suite verifies the following user stories:
- Boot Sequence: Ensures the start overlay appears and is dismissible via keyboard interaction.
- Navigation:
- D-Pad: Verifies Up/Down navigation correctly updates active links.
- Tabs: Verifies Left/Right navigation switches between Links, About, and Help tabs.
- Selection: Validates that pressing 'Enter' (A button) triggers link navigation.
- Theming: Checks that switching themes (B button) updates the DOM and persists across page reloads (via
localStorage). - Audio: Confirms toggling mute (M key) updates state and persists across reloads.
- Hardware Features:
- Power Switch: Verifies the power switch toggles the console on/off.
- Konami Code: Inputs the secret code (Up, Up, Down, Down, Left, Right, Left, Right, B, A) and verifies the "Matrix Mode" visual effect.
Validates .astro file syntax and TypeScript types.
- Command:
npm run check(runsastro check)
A GitHub Actions workflow (.github/workflows/ci.yml) runs on every push to main and pull requests.
Workflow Steps:
- Install: Sets up Node.js and dependencies.
- Check: Runs static analysis.
- Unit Tests: Executes Vitest suite.
- Build: Compiles the Astro project.
- E2E Tests: Runs Playwright against the preview build.
- Artifacts: Uploads failure traces and videos if tests fail.
To catch errors before they event reach the CI pipeline, this project uses Husky to enforce local testing before pushing code to the remote repository.
A pre-push hook is configured (in .husky/pre-push) to automatically run npm run test (which triggers both Unit Tests and E2E Tests) whenever git push is invoked locally. If any tests fail, the push is aborted.
This prevents the codebase from bloated pre-commit times, while guaranteeing that developers never push broken code to GitHub.
To debug tests visually, use the Playwright UI mode. This allows you to step through tests, time-travel, and inspect the DOM.
npx playwright test --uiPlaywright generates an HTML report for each run.
npx playwright show-report