Section 09 · 33 rules

Testing, tooling & CI/CD

Testing

  • T1 MUST test behavior through the UI with React Native Testing Library: query by role, label or text, act with userEvent, assert what the user sees. NEVER test internal state or private functions, and NEVER rely on whole-screen snapshots as the main test.
  • T2 MUST spend tests where bugs cost most: unit tests for pure logic (money math, validation, formatters), functional tests for screens (user events + mocked API), E2E only for critical journeys (sign-in, payment). NEVER chase a coverage percentage.
  • T3 MUST ship every bug fix with a test that fails before the fix, and every new screen with at least one functional test for its success state and its error state (EB5).
  • T4 MUST mock at the network boundary, not the query hooks: render with a real query client (retries off) inside one shared test wrapper.
  • T5 MUST use the Jest preset for the stack: jest-expo in Expo projects, React Native’s preset in bare ones. On React Native Testing Library v14, render, act, renderHook and fireEvent are async: await them (A5).
  • T6 MUST keep tests deterministic: fake timers, no real network, no sleeps or arbitrary waits.
  • T7 SHOULD use Maestro for E2E flows when the level calls for it (table below); in Expo projects it runs as a job in EAS Workflows.

Test writing conventions

Files and names

  • TW1 MUST colocate tests with the code: TransferScreen.test.tsx beside TransferScreen.tsx (or the repo’s __tests__/ convention). Performance tests end in .perf-test.tsx. Maestro flows live in .maestro/, one file per journey (sign-in.yaml, send-transfer.yaml).
  • TW2 MUST name tests by behavior in plain words: describe('TransferScreen'), it('shows an error with a retry button when loading fails'). NEVER it('works') or names that repeat the implementation.
  • TW3 MUST write one behavior per test in Arrange → Act → Assert order. NEVER if or loops inside a test; use it.each for variations.
  • TW4 MUST query in this order: getByRole → getByLabelText → getByText → getByTestId. A testID is the last resort, or for Maestro flows. A screen that is hard to query by role usually has an accessibility bug (C6).
  • TW5 MUST share setup through one test/render.tsx (providers + a fresh query client) and typed factories in test/factories/ (buildTransfer({ status: 'failed' })). NEVER paste large JSON fixtures into tests.

Unit tests

  • UT1 MUST unit-test pure logic: money math, formatters, validation schemas, reducers, and hooks with real logic. Cover the edges with it.each: 0, negative, maximum, rounding, empty input.
  • UT2 NEVER unit-test a component’s internals; components are covered by functional tests.
  • UT3 MUST keep unit tests free of network, timers and native modules, so the whole unit suite stays fast enough to run on every save.

Functional tests

  • FT1 MUST give every screen a functional test (Jest + React Native Testing Library): render it with providers and a mocked API, drive it with userEvent, assert what the user sees. Cover success, error, empty and the main action (submit, retry).
  • FT2 MUST mock only the edges: network responses and native modules (jest-expo mocks the Expo SDK). Keep real components, real hooks and a real query client; use the router’s testing utilities where they exist (A5). In Expo Router that is renderRouter from expo-router/testing-library, which needs React Native Testing Library v14 or later. Route tests NEVER go inside app/, because every file there becomes a route; put them beside the feature screen or in __tests__/.
  • FT3 MUST write Maestro E2E flows for critical journeys only, run against a release-like build, selecting elements by accessibility label or testID. Each flow starts from a clean state and does not depend on another flow.

Tooling

  • TL1 MUST pass on every change: type check (tsc --noEmit), lint, tests, and npx expo-doctor in Expo projects. New projects lint with --max-warnings 0.
  • TL2 MUST format with Prettier, on touched files only (P7).
  • TL3 MUST pin the Node version (.nvmrc or engines) at or above the React Native minimum; React Native 0.84+ needs Node 22.
  • TL4 MUST commit the lockfile and use one package manager. NEVER mix npm, Yarn, pnpm and Bun in one repo.
  • TL5 MUST upgrade React Native or the Expo SDK in its own change, with no feature work mixed in, using the Upgrade Helper or npx expo install --fix.

CI checks

Every check runs on every PR at its level and fails the build on its own; the agent runs the Starter checks locally before reporting done (D1).

Check Tool Fails the build when Level
Types tsc --noEmit Any type error Starter
Lint ESLint or npx expo lint, --max-warnings 0 in new projects Any error, or any warning in new projects Starter
Circular dependencies dpdm -T --exit-code circular:1 on the app entry, or madge --circular --extensions ts,tsx src/, or Oxlint import/no-cycle Any import cycle Starter
Project health npx expo-doctor (Expo projects) Any failed check Starter
Unit and functional tests Jest + React Native Testing Library Any failure Starter
Render performance Reassure, comparing the PR against main in the same CI run A statistically significant slowdown or extra renders beyond the budget Growing
Bundle size Production export measured against main (Expo Atlas to inspect) Growth beyond the budget with no note in the PR Growing
Device performance Flashlight on a release Android build, critical journeys Score drops below the stored baseline Scale
E2E Maestro (EAS Workflows job in Expo projects) Any failed flow Scale
  • CI1 NEVER introduce an import cycle. The usual cause is a barrel file: inside a feature, import siblings directly, never through the feature’s own index.ts; index.ts is only for other features (S3). Type-only imports (import type) are excluded from the cycle check.
  • CI2 MUST add a Reassure test (.perf-test.tsx) for list rows, heavy screens and anything a PR claims to make faster. Compare against main on the same CI machine, never against numbers from another machine.
  • CI3 MUST keep budgets (bundle size, render time, device score) in the repo’s config. Going over a budget needs a guardrail exception with the reason (D2), never a silently raised budget.
  • CI4 NEVER hide a flaky test with automatic retries. Quarantine it with a linked issue and fix it within the sprint.

Builds and releases

  • R1 MUST build anything for testers or stores in CI (EAS Build / Workflows or the repo’s CI), never on a laptop.
  • R2 MUST ship JavaScript-only changes as over-the-air updates and native changes as new builds: an update can only change the JS layer of the build it targets. Set a runtime version policy; fingerprint is the safer default because it changes whenever native code changes.
  • R3 NEVER push an over-the-air update to all users at once: go through a preview channel, roll out in stages, and keep the previous update ready to roll back.
  • R4 NEVER commit secrets, signing keys or keystores. They live in the CI or EAS secret store.
  • R5 MUST let CI bump version and build numbers, never by hand.
  • R6 NEVER, as an agent, start a production build, publish an update or submit to a store without the human’s explicit approval in that conversation.
Level CI on every PR Releases
Starter Types, lint, circular dependencies, project health, unit and functional tests Manual store release from a CI build
Growing + render performance, bundle size, preview build per PR + OTA updates through a preview channel
Scale + device performance, Maestro E2E on critical journeys + staged rollouts, release owner, CODEOWNERS