Appearance
Testing
Running Tests
bash
# All tests
pnpm test
# Specific file
pnpm test apps/backend/test/durables/PriceCollector.spec.ts
# Filter by name
pnpm test apps/backend/test/durables/PriceAlert.spec.ts -t 'should evaluate alerts'
# Watch mode
pnpm test --watch
# Web API tests
pnpm web:test:run -t "should return portfolio state with valid auth"Cross-DO Integration Tests
When testing cross-DO callbacks (e.g., PriceAlert triggering UserPortfolio):
- Initialize via RPC first: Always call
getPortfolioState(stub, userId)before other operations to ensure account exists in SQLite - Use
withMockedTime(): For timestamp-dependent operations (openLimitOrder,openPositionuseDate.now()internally) - Inject price data at PAST timestamps: Alarm uses
Date.now()asendCursor, so future timestamps won't be processed - Set cursor to match data range:
startCursor = lastCheckedTimestamp + 1 - Avoid direct internal method access:
runInDurableObjectstate changes don't persist to SQLite — use RPC methods for cross-DO visible state
Cloudflare-Specific Testing
See the Cloudflare Testing Guide for detailed patterns around Durable Object testing, miniflare, and worker test utilities.