Skip to main content

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/react for component tests
  • Use fake-indexeddb for 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

AreaTarget
Game rule engines100% branch coverage
State machinesAll state transitions
Overall statement coverageIncreasing (currently ~33%)

Key Files

  • packages/app/vitest.config.ts - Vitest configuration
  • packages/app/playwright.config.cjs - Playwright configuration
  • packages/app/e2e/ - E2E test specs