Skip to content

Commit 0cf4aa0

Browse files
committed
chore: refactor agents.md
1 parent bd11540 commit 0cf4aa0

7 files changed

Lines changed: 165 additions & 103 deletions

File tree

AGENTS.md

Lines changed: 16 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,20 @@
11
# Code Assistant Context
22

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.
44

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`
989
- `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)

docs/agents/architecture.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Architecture And API Design
2+
3+
## Project overview
4+
5+
`@testing-library/react-native` provides utilities for testing React Native components in ways that resemble real usage and avoid implementation details.
6+
7+
- Tech stack: TypeScript, React Native, Jest
8+
- Core principle: the closer tests are to real usage, the more confidence they provide
9+
- Runtime model: the library simulates the React Native runtime on top of `test-renderer`
10+
11+
## API design principles
12+
13+
- Prefer a small public API surface.
14+
- Expose underlying React and `react-reconciler` capabilities when Testing Libraries need them.
15+
- Render host elements only.
16+
- Provide escape hatches to fibers when needed.
17+
18+
## Key entry points
19+
20+
- `src/pure.ts`: side-effect-free core logic without auto-cleanup
21+
- `src/index.ts`: main entry point that re-exports `pure` and adds auto-cleanup side effects
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Build, Validation, And Repo Layout
2+
3+
## Common commands
4+
5+
- Install dependencies: `yarn install`
6+
- Run tests: `yarn test`
7+
- Run tests in CI mode: `yarn test:ci`
8+
- Type check: `yarn typecheck`
9+
- Lint source files: `yarn lint`
10+
- Check formatting: `yarn prettier`
11+
- Validate the main package: `yarn validate`
12+
- Build the package: `yarn build`
13+
14+
## Command notes
15+
16+
- `yarn lint` runs ESLint on `src`.
17+
- `yarn validate` runs typecheck, tests, lint, and Prettier checks for the main package.
18+
- `yarn build` cleans `build/`, transpiles source with Babel, and emits TypeScript declarations.
19+
20+
## Repo layout
21+
22+
- `src/`: source code
23+
- `src/pure.ts`: core logic without side effects
24+
- `src/index.ts`: main entry point with auto-cleanup side effects
25+
- `examples/`: example React Native apps
26+
- `website/`: documentation site
27+
- `codemods/`: codemod implementations and tests

docs/agents/code-style.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# TypeScript And Code Style
2+
3+
## Linting and formatting
4+
5+
- ESLint uses `@callstack/eslint-config` together with `typescript-eslint`.
6+
- Important enforced rules include `no-console` and consistent type imports.
7+
- Prettier is the formatter.
8+
- Formatting defaults include single quotes and trailing commas.
9+
10+
## Imports
11+
12+
- Keep imports sorted with `eslint-plugin-simple-import-sort`.

docs/agents/example-apps.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Example App Regeneration
2+
3+
## General workflow
4+
5+
- Regenerate Expo example apps in a temporary directory, then copy the fresh scaffold into place.
6+
- Before replacing an example app, move the current app directory to `/tmp` so repo-specific files can be restored selectively.
7+
- After copying a generated app into `examples/`, remove the generated `.git` directory and `node_modules`, then reinstall from inside the repo workspace.
8+
9+
## `examples/basic`
10+
11+
- Generate from the Expo blank TypeScript template:
12+
- `yarn create expo-app /tmp/rntl-basic-fresh --template blank-typescript --yes`
13+
- Restore these repo-specific files on top of the fresh scaffold:
14+
- `App.tsx`
15+
- `components/`
16+
- `__tests__/`
17+
- `theme.ts`
18+
- `jest.config.js`
19+
- `jest-setup.ts`
20+
- `babel.config.js`
21+
- `eslint.config.mjs`
22+
- `README.md`
23+
- `.expo-shared/assets.json` if it existed before
24+
- Keep the fresh Expo entrypoint `index.ts`.
25+
- Update `package.json` and `app.json` to match repo naming and scripts.
26+
27+
## `examples/cookbook`
28+
29+
- Generate from a router-enabled Expo scaffold:
30+
- `yarn create expo-app /tmp/rntl-cookbook-fresh --example with-router --yes`
31+
- Restore these repo-specific files on top of the fresh scaffold:
32+
- `app/`
33+
- tutorial test directories such as `basics-tutorial/` and `basics-tutorial-react-strict-dom/`
34+
- `theme.ts`
35+
- `jest.config.js`
36+
- `jest-setup.ts`
37+
- `babel.config.js`
38+
- `.eslintrc`
39+
- `.eslintignore`
40+
- `README.md`
41+
- custom assets not present in the scaffold, such as `assets/gradientRNBanner.png`
42+
- `.expo-shared/assets.json` if it existed before
43+
- Keep the fresh Expo Router entry setup.
44+
- Reapply the cookbook-specific dependency set in `package.json` and `app.json`.
45+
46+
## Validation after regeneration
47+
48+
- Run these commands from inside the regenerated app directory:
49+
- `yarn expo install --check`
50+
- `yarn lint`
51+
- `yarn typecheck`
52+
- `yarn test --watchman=false`
53+
54+
## Lockfile guidance
55+
56+
- If the fresh scaffold causes dependency-resolution churn, restore the previous `yarn.lock` first and then run `yarn install` instead of re-resolving the full tree.

docs/agents/git-workflow.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Git, Releases, And PR Workflow
2+
3+
## Commits and releases
4+
5+
- Use Conventional Commits such as `fix:`, `feat:`, and `chore:`.
6+
- Releases are managed with `release-it`.
7+
8+
## PR draft workflow
9+
10+
- Maintain `PR.txt` at the repository root using the structure from `.github/pull_request_template.md`.
11+
- Keep `PR.txt` aligned with the current branch diff relative to `origin/main`.
12+
- Include tests actually run and any known validation gaps in `PR.txt`.
13+
- Do not commit `PR.txt`.

docs/agents/testing.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Testing Conventions
2+
3+
## Test stack
4+
5+
- Test framework: Jest with the `react-native` preset
6+
- Test environment setup: `jest-setup.ts`
7+
- Auto-cleanup is configured from `src/index.ts` unless explicitly skipped
8+
9+
## Test location and coverage
10+
11+
- Library tests are typically colocated under `src/**/__tests__`
12+
- Coverage is collected from `src` and excludes test files
13+
14+
## Test organization
15+
16+
- Use `describe` blocks to group tests by theme.
17+
- Do not put all tests into a single `describe`.
18+
- Avoid nested `describe` blocks.
19+
- If a `describe` would contain only one test, make that test top-level instead.
20+
- Prefer `test` over `it`.

0 commit comments

Comments
 (0)