This document defines our testing approach, infrastructure seams, and developer workflow. It is the source of truth for how tests are written and run in this repo.
- Flake-free, deterministic tests.
- High signal, low maintenance.
- Confidence for aggressive refactors without breaking core flows.
We intentionally avoid a large pyramid of brittle component tests. Instead we use a barbell strategy:
- Unit tests for pure logic and mock correctness.
- A small set of high-value E2E tests for critical user flows.
- Integration and component tests only where wiring or complex UI logic warrants it.
- Layer A: Unit (Vitest)
- Layer B: Integration (Vitest + Provider Harness)
- Layer C: Components (Vitest + RTL)
- Layer D: E2E Smoke (Playwright)
- Layer E: E2E Full (Playwright)
- No DOM snapshots (
toMatchSnapshotis banned). - No MetaMask automation in E2E. Use MockConnector only.
- No UI debug clicking in E2E. Use the Test Bridge to set state.
- No page-local scenario switchers as the primary QA path for mature mock-backed routes.
- No locale testing in E2E. Use strict decimals with a
.separator.
We expose a typed control surface for E2E tests. It is only injected when NEXT_PUBLIC_E2E=true (even in production builds).
- Location:
lib/test-bridge.ts(interface + implementation helpers). - Initialization:
components/TestBridgeListener.tsxrendered insidestate/protocol.tsx. - Guard:
if (process.env.NEXT_PUBLIC_E2E === "true"). - All state mutations invalidate React Query for deterministic UI updates.
- Each mock-heavy domain adds a typed adapter to this shared seam rather than creating a second test bridge.
await page.evaluate(async () => {
await window.__TEST__?.reset();
await window.__TEST__?.setBalance(
"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
"YFI",
"100"
);
});reset(): clears mock stores, time, and React Query cache.setNow(timestamp): sets the fixed mock time (seconds since epoch).getState(address): returns a snapshot of mock state (stYFI, veYFI, yETH).setBalance(address, symbol, amount): sets wallet or mock token balances.setAllowance(address, symbol, spender, amount): sets mock allowances.setScenario(name): loads a predefined scenario (resets first).setYethPreset(address, preset): applies yETH mock account state (claimable,recovery_position,empty).
Teams, YBC, and DAO adapters show the pattern that new domains must follow:
components/TestBridgeListener.tsxaccepts optionalteams,ybc, anddaoadapterslib/test-bridge.tsexportsTeamsTestBridgeAdapter,YbcTestBridgeAdapter, andDaoTestBridgeAdapter- shared domain mutation methods invalidate
teamsKeys.all,ybcKeys.all, ordaoKeys.allautomatically after the adapter mutation runs - shared
setNow(timestamp)also calls adapteronSetNow(timestamp)hooks before the global query invalidation
Representative adapter methods already reserved by the shared contract:
- Teams:
resetTeams,setTeamsViewerRole,setTeamsSelectedTeam,setTeamsLoading,setTeamsEmpty,setTeamsCurrentPeriod,patchTeamsTeam,patchTeamsFundingApproval,patchTeamsBonus,patchTeamsAdmin - YBC:
resetYbc,setYbcPerspective,setYbcLoading,setYbcEmptyRoster,setYbcEmptyBoard,setYbcEpoch,patchYbcMember,patchYbcProposal,patchYbcRewards,patchYbcAdmin - DAO:
resetDao,setDaoFixture,setDaoSelectedProposal,setDaoPersona,setDaoRole,setDaoContentState,setDaoLifecycle,setDaoVetoState,setDaoAnalysisState,setDaoAccountState,setDaoExecutionState,setDaoAuthoringState,setDaoTransactionOutcome,indexDaoPendingAction,clearDaoPendingAction, and granular proposal/proposer fact setters
DAO bridge mutations wait for the adapter and then invalidate daoKeys.all.
This is required because the route client is module-scoped and DAO queries use
infinite stale times.
Amounts passed to the bridge must be human-readable strings without commas (e.g. \"100.5\").
All bridge methods are async and should be awaited.
Scenario presets are applied to the default E2E address unless a test overrides state via setBalance.
Prefer calling reset() at the start of each E2E test to avoid leaked state.
New domains with substantial mock state should add app-specific bridge methods instead of
requiring visible route-local scenario controls for QA.
DAO proposal-content tests pin exact canonical JSON bytes, including the final LF, plus SHA-256 digest and CIDv1/raw/SHA-256/Base32 vectors. A committed raw asset fixture must match manifest byte length, digest, media type, dimensions, and derived CID. Component and Playwright coverage must prove that attachment cards make zero automatic asset requests and that only a user-activated Open uses the validated suffix-free raw-CID URL. Creation-flow tests keep transaction hash, receipt-derived composite identity, awaiting-index, and indexed states separate and assert that the identity never changes.
Available scenarios:
standard: baseline mock state.active: seeded stYFI balance for the default address.legacy_user: legacy veYFI balance pending migration.caps_exhausted: redemption caps and inventory fully consumed.
All time logic must come from lib/mocks/time.ts:
nowSeconds()is the single source of truth.setFixedNow(ts | null)freezes or clears time.- In mock mode, UI epoch/cooldown timing is driven by local mock time only (not global-data/chain canonical sources), so debug time travel remains deterministic.
- Debug time travel controls are expected to invalidate identity plus domain query keys and refetch active/inactive observers immediately.
- Each domain exposes one root query-key entry point for shared reset and time
invalidation. Existing examples are
teamsKeys.all,ybcKeys.all, anddaoKeys.all. - Shared debug time travel synchronizes the DAO runtime even when a non-DAO route
owns the mounted panel, then invalidates
daoKeys.allwith the other domain roots.
Any logic that previously called Date.now() must use nowSeconds() instead.
When NEXT_PUBLIC_E2E=true, wagmi uses a mock connector with a fixed address:
- Default E2E address:
0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 - Location:
lib/constants.ts
This means E2E tests are instantly “connected” and do not rely on wallet UI
flows. The E2E-only wrapper resolves exactly eth_accounts from that local
deterministic account and delegates every other provider request to wagmi's mock
connector. Wagmi reconnect reaches the connected account without network fetch;
after an explicit disconnect, reconnect preserves the disconnected state. Do
not disable reconnect-on-mount to hide RPC failures.
The mock connector is for testing only and should never be enabled in real user environments.
DAO RPC regression coverage deliberately points local E2E at the dead sentinel
http://127.0.0.1:8546. Board, detail, and authoring tests wait for hydrated
route state and assert zero eth_accounts request bodies, loopback requests,
request failures, page errors, and console errors. Chromium maps
dao-beta.dao-ops.com to loopback only when E2E_BASE_URL is local; remote and
preproduction runs never receive that resolver rule.
The beta-host navigation smoke uses an HTTPS browser origin with local HTTP
transport. Playwright routes those requests to the isolated server and preserves
the host headers. This keeps production CSP, including upgrade-insecure-requests,
active without sending requests to the public beta host.
Local hostname mapping does not test Cloudflare Access. Before beta UAT, verify all six exact governance beta hosts with an unauthenticated incognito request, an approved GitHub organization/team member, an unrelated GitHub account, and a representative nested route. After authentication, repeat noindex/canonical, cross-beta navigation, wallet connection, and wallet-popup checks. Keep results sanitized and leave any host without direct evidence marked incomplete.
Vitest runs in parallel by default.
Playwright smoke runs are intentionally single-worker (npm run test:e2e -> --workers=1) to avoid cross-flow flake from shared mock-store mutations and time controls.
Preferred structure (target layout, not fully migrated yet):
tests/unit/*tests/integration/*tests/components/*tests/e2e/smoke/*tests/e2e/full/*
Use descriptive filenames:
lib/format.test.tshooks/useStyfiAccount.test.tsxcomponents/UnstakePanel.test.tsxsmoke/styfi-flow.spec.ts
Do:
- Validate math, formatting, and error mapping at the unit level.
- Verify hooks call clients and invalidate queries.
- Test complex disconnected UI logic with plain props.
- Use the Test Bridge to set E2E state.
- Keep default route chrome production-like and place mock-only controls behind debug APIs.
- Prefer granular bridge setters that mutate live route state over scenario-only loading once a route has matured past initial prototype mode.
- For each new mock-heavy domain, test its state-machine boundaries, typed bridge controls, deterministic time behavior, reset behavior, main components, and at least one smoke flow through the production-shaped route.
Do not:
- Assert on implementation details or DOM snapshots.
- Use flakey timers or refetch intervals in tests.
- Click debug UI in E2E to set state.
Current commands:
npm run test(Vitest)npm run lintnpm run typechecknpm run test:e2e(Playwright smoke)npm run test:e2e:full(Playwright full)
Playwright can also be run directly:
npx playwright test --project=smokenpx playwright test --project=full
TypeScript 7 does not provide the compiler API that Next.js and typescript-eslint require.
The package configuration uses Microsoft's documented side-by-side aliases.
The exact aliases are @typescript/native: npm:typescript@7.0.2 and typescript: npm:@typescript/typescript6@6.0.2.
The lockfile resolves the compatibility API to TypeScript 6.0.3.
npm run typecheck runs the native 7.0.2 compiler. Next.js builds and ESLint use the compatibility API.
Both paths retain strict type checking.
The React, import, and accessibility plugins still declare peer ranges that exclude ESLint 10. Exact plugin-version overrides select the root ESLint version. The configuration uses ESLint compatibility utilities to restore the removed rule APIs. The regression test checks that React, hooks, accessibility, and TypeScript rules still report invalid code. The compatibility configuration keeps the existing lint rules enabled. The lockfile also updates typescript-eslint and React Hooks to versions that declare ESLint 10 support.
The newer Hooks checks require derived state and form resets to run without synchronous effects. The app fixes retain default asset selection, Teams navigation, funding-form resets, trade-input resets, and yETH deadline gating. The shared clock supplies the veYFI lock status and epoch countdown.
Use the pinned Node.js and npm versions with the repository’s release-age policy. Keep the native-install-script allowlist in place. Remove compatibility aliases and plugin overrides only after the dependent tools support their replacements. The historical index retains the original migration record.
NEXT_PUBLIC_E2E=trueenables the Test Bridge and mock wallet.NEXT_PUBLIC_USE_MOCKS=trueensures the app uses mock clients.NEXT_PUBLIC_E2E=truealso forces mock clients for safety.NEXT_PUBLIC_MOCK_TIME_OFFSET_SECONDScan offset the clock in dev.- For manual UI QA of disconnected states while mocks are enabled, use
NEXT_PUBLIC_USE_MOCKS=truewithNEXT_PUBLIC_E2E=false(otherwise the mock connector is auto-connected).
Once the Teams/YBC baseline fork smoke has passed, local UX iteration should normally use mock mode plus the mock navigator/debug bridge. This is acceptable for visual hierarchy, copy, tables, cards, tabs, responsive layout, loading states, empty states, and state-specific review.
Run the normal local checks before preprod:
npm run typecheck -- --incremental falsenpm run lintnpm run testnpm run test:e2enpm run build
Re-run Teams/YBC fork smoke when a change touches onchain clients, write hooks,
transaction plumbing, token approval handling, amount parsing, deployment/feed address
fields, action gating, wallet or chain handling, or write-button argument threading.
The repeatable launch runbook is
teams-ybc-fork-smoke-plan.md.
- Bridge missing: check
NEXT_PUBLIC_E2E=true. - UI not updating: ensure bridge mutations are awaited (React Query invalidates).
- Cap tests failing: use
setScenario("caps_exhausted")to force caps.
E2E_WEB_SERVER_COMMANDcan override the Playwright web server command if you want to testnext startinstead ofnext dev.- Typecheck uses
types/next-shim.d.tsto satisfy Next’s internal type imports under.next/types. - Keep the shim's
PrefetchandEnsureStaticunions aligned with the pinned Next.js declarations. Production builds generate imports for both types.