Testing
Running Tests
bun test # vitest unit tests
bun test:coverage # vitest with coverage report
bun test:e2e # playwright end-to-end tests
Unit Tests (Vitest)
- Use
@testing-library/reactfor component tests - Use
fake-indexeddbfor Dexie mocking - Use MSW (Mock Service Worker) for API mocking
State Machine Tests
All XState machines require transition coverage for all states:
import { createActor } from 'xstate';
import { myMachine } from './myMachine';
test('transitions correctly', () => {
const actor = createActor(myMachine).start();
actor.send({ type: 'SOME_EVENT' });
expect(actor.getSnapshot().value).toBe('expectedState');
});
Game Rules Tests
Game rule engines require 100% branch coverage:
- All win conditions
- Draw detection
- Invalid move rejection
- Full game simulations
E2E Tests (Playwright)
End-to-end tests cover the full core loop:
bun test:e2e
Key test scenarios:
- Core loop: Login -> Onboard -> Add Plant -> Care -> Nurture -> Play -> Reward
- Multiplayer: Two-context host/guest game session
- Offline: Care event while offline, persisted after reconnect
Playwright Config
- Desktop and mobile Chromium profiles
- Virtual authenticator for passkey testing
- Configurable for real-auth validation with
MANUAL_WALLET=true
Coverage Targets
| Area | Target |
|---|---|
| Game rule engines | 100% branch coverage |
| State machines | All state transitions |
| Overall statement coverage | Increasing (currently ~33%) |
Key Files
packages/app/vitest.config.ts- Vitest configurationpackages/app/playwright.config.cjs- Playwright configurationpackages/app/e2e/- E2E test specs