|
1 | 1 | # Code Assistant Context |
2 | 2 |
|
3 | | -This document provides context for the any code assistant to understand the `@testing-library/react-native` project. |
| 3 | +`@testing-library/react-native` is a TypeScript/Jest library for testing React Native components with user-focused testing patterns. |
4 | 4 |
|
5 | | -## Project Overview |
6 | | - |
7 | | -`@testing-library/react-native` (RNTL) provides a set of utilities for testing React Native components. It is designed to facilitate writing tests that resemble how users interact with the application, avoiding implementation details. |
8 | | - |
9 | | -- **Core Principle:** "The more your tests resemble the way your software is used, the more confidence they can give you." |
10 | | -- **Tech Stack:** TypeScript, React Native, Jest. |
11 | | -- **Architecture:** The library simulates the React Native runtime on top of `test-renderer`. |
12 | | - |
13 | | -## Project Guidelines |
14 | | - |
15 | | -- Small API surface |
16 | | -- Expose all features of the underlying platform (react, react-reconciler) for Testing Libraries to use |
17 | | -- Render host elements only, yet provide escape hatches to fibers when needed |
18 | | - |
19 | | -## Building and Running |
20 | | - |
21 | | -The project uses `yarn` for dependency management and script execution. |
22 | | - |
23 | | -- **Installation:** `yarn install` |
24 | | -- **Run Tests:** `yarn test` (Runs Jest) |
25 | | -- **Run Tests (CI):** `yarn test:ci` (Runs Jest with worker limits) |
26 | | -- **Lint Code:** `yarn lint` (Runs ESLint on `src`) |
27 | | -- **Type Check:** `yarn typecheck` (Runs TypeScript compiler) |
28 | | -- **Format Check:** `yarn prettier` |
29 | | -- **Validate All:** `yarn validate` (Runs Prettier, ESLint, Typecheck, and Tests in sequence) |
30 | | -- **Build Project:** `yarn build` (Cleans, builds JS with Babel, and builds TS types) |
31 | | - |
32 | | -## Development Conventions |
33 | | - |
34 | | -- **Code Style:** |
35 | | - - **Linting:** ESLint is configured with `@callstack/eslint-config` and `typescript-eslint`. It enforces strict rules, including `no-console` and consistent type imports. |
36 | | - - **Formatting:** Prettier is used for code formatting (single quotes, trailing commas). |
37 | | - - **Imports:** Sorted using `eslint-plugin-simple-import-sort`. |
38 | | - |
39 | | -- **Testing:** |
40 | | - - **Framework:** Jest with `react-native` preset. |
41 | | - - **Location:** Tests are located within `src`, typically co-located in `__tests__` directories. |
42 | | - - **Setup:** `jest-setup.ts` configures the test environment. `src/index.ts` automatically configures cleanup after each test unless skipped. |
43 | | - - **Coverage:** Collected from `src`, excluding tests. |
44 | | - - **Organization:** Use `describe` to group test by theme. Avoid putting all tests in the same `describe` block. Avoid `describe` nesting. Avoid `describe` with only single test, make that test top-level. Prefere `test` over `it`. |
45 | | - |
46 | | -- **Commits & Releases:** |
47 | | - - **Commits:** Follow the **Conventional Commits** specification (e.g., `fix:`, `feat:`, `chore:`). This is enforced and used for changelog generation. |
48 | | - - **Releases:** Managed via `release-it`. |
49 | | - |
50 | | -- **File Structure:** |
51 | | - - `src/`: Source code. |
52 | | - - `src/pure.ts`: Core logic without side effects (no auto-cleanup). |
53 | | - - `src/index.ts`: Main entry point, re-exports `pure` and adds side effects (auto-cleanup). |
54 | | - - `examples/`: Example React Native applications using the library. |
55 | | - - `website/`: Documentation website. |
56 | | - |
57 | | -## Example App Regeneration |
58 | | - |
59 | | -- Prefer regenerating Expo example apps in a temporary directory and then copying the fresh scaffold into place, instead of mutating the existing app in place. |
60 | | -- Before replacing an example app, move the current app directory to `/tmp` so repo-specific code, tests, assets, and configs can be restored selectively. |
61 | | -- After copying a freshly generated app into `examples/`, remove the generated `.git` directory and generated `node_modules`, then reinstall from inside the repo workspace. |
62 | | - |
63 | | -- `examples/basic`: |
64 | | - - Generate from the Expo blank TypeScript scaffold: |
65 | | - - `yarn create expo-app /tmp/rntl-basic-fresh --template blank-typescript --yes` |
66 | | - - Restore the repo-specific sample app files on top of the new scaffold: |
67 | | - - `App.tsx` |
68 | | - - `components/` |
69 | | - - `__tests__/` |
70 | | - - `theme.ts` |
71 | | - - `jest.config.js` |
72 | | - - `jest-setup.ts` |
73 | | - - `babel.config.js` |
74 | | - - `eslint.config.mjs` |
75 | | - - `README.md` |
76 | | - - `.expo-shared/assets.json` if it existed before |
77 | | - - Keep the fresh Expo entrypoint (`index.ts`) and update `package.json` / `app.json` to match the repo naming and scripts. |
78 | | - |
79 | | -- `examples/cookbook`: |
80 | | - - Generate from a router-enabled Expo scaffold: |
81 | | - - `yarn create expo-app /tmp/rntl-cookbook-fresh --example with-router --yes` |
82 | | - - Restore the repo-specific cookbook files on top of the new scaffold: |
83 | | - - `app/` |
84 | | - - tutorial test directories such as `basics-tutorial/` and `basics-tutorial-react-strict-dom/` |
85 | | - - `theme.ts` |
86 | | - - `jest.config.js` |
87 | | - - `jest-setup.ts` |
88 | | - - `babel.config.js` |
89 | | - - `.eslintrc`, `.eslintignore` |
90 | | - - `README.md` |
91 | | - - custom assets not present in the scaffold, such as `assets/gradientRNBanner.png` |
92 | | - - `.expo-shared/assets.json` if it existed before |
93 | | - - Keep the fresh Expo Router entry setup, then reapply the cookbook-specific dependency set in `package.json` and `app.json`. |
94 | | - |
95 | | -- After regenerating either example app, validate from inside the app directory: |
96 | | - - `yarn expo install --check` |
97 | | - - `yarn lint` |
| 5 | +- Package manager: `yarn` (`yarn@4.11.0`) |
| 6 | +- Common commands: |
| 7 | + - `yarn test` |
| 8 | + - `yarn test:ci` |
98 | 9 | - `yarn typecheck` |
99 | | - - `yarn test --watchman=false` |
100 | | - |
101 | | -- If the fresh scaffold introduces dependency-resolution churn, prefer restoring the previous `yarn.lock` first and then running `yarn install`, rather than re-resolving the whole dependency tree from scratch. |
102 | | - |
103 | | -## PR draft workflow: |
104 | | - |
105 | | -- Maintain `PR.txt` at the repository root using the structure from `.github/pull_request_template.md`. |
106 | | -- Keep `PR.txt` aligned with the current branch diff relative to `origin/main`, including tests actually run and any known validation gaps. |
107 | | -- Do not commit `PR.txt`. |
| 10 | + - `yarn lint` |
| 11 | + - `yarn prettier` |
| 12 | + - `yarn build` |
| 13 | + - `yarn validate` |
| 14 | +- Task-specific guidance: |
| 15 | + - [Architecture and API design](docs/agents/architecture.md) |
| 16 | + - [Build, validation, and repo layout](docs/agents/build-and-validation.md) |
| 17 | + - [TypeScript and code style](docs/agents/code-style.md) |
| 18 | + - [Testing conventions](docs/agents/testing.md) |
| 19 | + - [Example app regeneration](docs/agents/example-apps.md) |
| 20 | + - [Git, releases, and PR workflow](docs/agents/git-workflow.md) |
0 commit comments