Skip to main content

Testing Guide

Hyperscape uses Playwright for end-to-end testing with real browser sessions and game instances. No mocks are allowed - all tests must use actual gameplay.

Testing Philosophy

Real Gameplay Testing

Every test must:
  1. Start a real Hyperscape server
  2. Open a real browser with Playwright
  3. Execute actual gameplay actions
  4. Verify with screenshots + Three.js scene queries
  5. Save error logs to /logs/ folder

No Mocks Policy

  • Forbidden: Mock objects, stub functions, fake data
  • Required: Real server, real browser, real gameplay
  • Reason: Ensures tests match production behavior exactly

Visual Testing

Tests use colored cube proxies for visual verification:
  • 🔴 Players (red)
  • 🟢 Goblins (green)
  • 🔵 Items (blue)
  • 🟡 Trees (yellow)
  • 🟣 Banks (purple)

Test Timeouts

Standard Timeouts

Increased Timeouts (Recent Changes)

GoldClob Fuzz Tests

File: packages/evm-contracts/test/GoldClob.fuzz.ts Timeout: 120s (120000ms) Reason: Randomized invariant tests process:
  • 4 random seeds
  • 140 operations per seed
  • Plus claim operations
  • Total: ~560 operations with gas calculations

EmbeddedHyperscapeService Tests

File: packages/server/src/eliza/__tests__/EmbeddedHyperscapeService.test.ts Timeout: 60s (60000ms) for beforeEach hooks Reason: Dynamic import of Hyperscape service takes time:
  • Module loading
  • World initialization
  • Asset loading
  • PhysX WASM initialization

Precision Fixes

File: packages/evm-contracts/test/GoldClob.round2.ts Change: Use larger amounts (10000n) to avoid gas cost precision issues Before:
After:

Test Configuration

Playwright Configuration

File: packages/client/playwright.config.ts

Vitest Configuration

File: packages/shared/vitest.config.ts

WebGPU Testing Requirements

Browser Requirements

  • Headless: NOT supported (WebGPU requires display)
  • Headful: Required with GPU access
  • Display: Xorg, Xvfb, or Ozone headless with GPU

Playwright WebGPU Setup

CI/CD Considerations

  • GitHub Actions: Use ubuntu-latest with GPU support
  • Docker: Requires GPU passthrough and display server
  • Vast.ai: Full GPU support with Xorg/Xvfb

Test Patterns

Basic Gameplay Test

Visual Verification Test

Combat Test with Timeout

Debugging Failed Tests

Screenshot Analysis

Video Recording

Console Logs

Three.js Scene Inspection

Performance Testing

Benchmark Tests

Memory Leak Detection

CI/CD Integration

GitHub Actions

Test Artifacts

Best Practices

Test Isolation

  • Each test should start with a fresh world
  • Clean up entities after test
  • Reset game state between tests

Timeout Guidelines

  • Simple tests: 30s (default)
  • Complex integration: 60s
  • Fuzz/randomized: 120s
  • beforeEach hooks: 60s (for world initialization)

Error Handling

Flaky Test Prevention

  • Use waitForFunction() instead of waitForTimeout()
  • Add retry logic for network-dependent operations
  • Increase timeouts for slow operations (combat, pathfinding)
  • Use deterministic random seeds for reproducibility

See Also

  • packages/client/playwright.config.ts - Playwright configuration
  • packages/shared/vitest.config.ts - Vitest configuration
  • packages/client/tests/e2e/ - End-to-end test examples
  • packages/shared/src/systems/shared/combat/__tests__/ - Combat system tests
  • packages/evm-contracts/test/ - Smart contract tests