|
| 1 | +# E2E Controller Mocking |
| 2 | + |
| 3 | +This document explains when and how to mock controller logic during E2E tests. This is not about Sentry; it focuses on replacing provider SDK interactions when needed, with the HyperLiquid provider as the concrete example. |
| 4 | + |
| 5 | +## Context and Rationale |
| 6 | + |
| 7 | +- Some features depend on external provider SDKs and live data streams (e.g., HyperLiquid market data via WebSocket). In E2E we need deterministic, reliable tests that are not affected by third-party uptime, timing, or data variability. |
| 8 | +- In these cases, we may replace controller interactions with the provider SDK so flows can proceed with stable, test-controlled data. |
| 9 | +- If your calls are plain HTTP/HTTPS and can be intercepted by our E2E mock server, prefer HTTP-level mocking instead (it’s simpler, more generic, and easier to maintain). |
| 10 | + |
| 11 | +## Perps + HyperLiquid Controller Mixin (Specific Case) |
| 12 | + |
| 13 | +- File: `e2e/controller-mocking/mock-config/perps-controller-mixin.ts` |
| 14 | +- Purpose: Replace HyperLiquid provider SDK touchpoints for E2E with safe, deterministic alternatives so the Perps connection lifecycle (initialization, subscriptions, reconnection) can be exercised without relying on the live SDK backend. |
| 15 | + |
| 16 | +Key behaviors: |
| 17 | + |
| 18 | +- Intercepts Perps controller methods that would call into the HyperLiquid SDK and redirects them to E2E-provided mocks. |
| 19 | +- Keeps the rest of the business logic intact while ensuring stable inputs/outputs for tests. |
| 20 | + |
| 21 | +Scope note: |
| 22 | + |
| 23 | +- This mixin is a solution for this particular provider and feature. Do not treat it as a general pattern for all network or SDK interactions. |
| 24 | + |
| 25 | +## Prefer HTTP Mocking When Possible |
| 26 | + |
| 27 | +- If your feature communicates over HTTP, use the E2E mock server (fixtures + proxy) to stub responses: |
| 28 | + - Faster to implement and review |
| 29 | + - Centralized and reusable across tests |
| 30 | + - Avoids coupling tests to controller internals |
| 31 | + |
| 32 | +Only consider controller-level mocking when: |
| 33 | + |
| 34 | +- The dependency is an SDK with complex transport (e.g., WebSockets) that isn’t easily intercepted by our mock server, or |
| 35 | +- You need to drive very specific edge cases not feasible at the network layer. |
| 36 | + |
| 37 | +## How to Apply Controller Mocks |
| 38 | + |
| 39 | +1. Implement a feature-scoped mixin/override under `e2e/controller-mocking/mock-config/`. |
| 40 | +2. Use your E2E bridge/initializer to inject the mixin into the running app for tests that require it. |
| 41 | +3. Keep overrides minimal and focused on stabilizing provider interactions. Avoid changing unrelated business logic. |
| 42 | + |
| 43 | +## Best Practices |
| 44 | + |
| 45 | +- Keep mocks deterministic and fast. Avoid timers and external dependencies. |
| 46 | +- Document each override and its purpose. |
| 47 | +- Align with the Page Object Model in specs; controller mocking should be configured via fixtures/bridge, not from the test body. |
| 48 | +- Prefer HTTP/network mocking where feasible; use controller mocking only when necessary. |
| 49 | + |
| 50 | +## Notes |
| 51 | + |
| 52 | +- This document is specifically about provider SDK replacement (e.g., HyperLiquid) for E2E stability. For third‑party library swaps at the module level, see `MODULE_MOCKING.md`. |
0 commit comments