Skip to content

Commit 898b091

Browse files
committed
feat: add examples/basic app with component tests
1 parent a25ff14 commit 898b091

46 files changed

Lines changed: 939 additions & 371 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/test.yml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,31 @@ jobs:
5656
- if: inputs.nitro-ui == 'latest'
5757
run: ./scripts/use-latest-nitro-ui.sh
5858
- run: bun run test:${{ matrix.runner }}
59+
60+
# The example app runs every runner the way a NitroUI app would set them up,
61+
# through the package's own exports.
62+
example:
63+
runs-on: ubuntu-latest
64+
defaults:
65+
run:
66+
working-directory: examples/basic
67+
steps:
68+
- uses: actions/checkout@v4
69+
- uses: actions/setup-node@v4
70+
with:
71+
node-version: 24
72+
- uses: oven-sh/setup-bun@v2
73+
with:
74+
bun-version-file: package.json
75+
# Must run before `bun install`, which reads the tarball first.
76+
- run: ./scripts/vendor-test-renderer.sh
77+
working-directory: .
78+
- run: bun install --frozen-lockfile
79+
working-directory: .
80+
- if: inputs.nitro-ui == 'latest'
81+
run: ./scripts/use-latest-nitro-ui.sh
82+
working-directory: .
83+
- run: bun run typecheck
84+
- run: bun run test:jest
85+
- run: bun run test:vitest
86+
- run: bun run test:bun

‎AGENTS.md‎

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ reviewed steps, rather than copying it wholesale.
2222
- **NitroUI:** only the latest `nitro-ui-renderer` release (currently 0.3.0).
2323
NitroUI and this library are both 0.x and change quickly, so raise the
2424
minimum supported version (the `peerDependencies` range and the exact
25-
devDependency) whenever we move to a newer NitroUI. Don't keep compatibility
25+
devDependency) whenever we move to a newer NitroUI, and re-create
26+
`examples/basic` from the new template. Don't keep compatibility
2627
code for older NitroUI versions.
2728
- **React:** pin the devDependency to the exact version `nitro-ui-renderer`
2829
depends on (currently 19.3.0). A second React copy breaks hooks. After
@@ -57,6 +58,24 @@ the NitroUI ecosystem.
5758
`NITRO_UI_VERSION=x.y.z ./scripts/use-latest-nitro-ui.sh`, then revert
5859
`package.json` and `bun.lock`.
5960

61+
## Example app
62+
63+
`examples/basic` is a NitroUI app from the default template (`create-nitro-ui`)
64+
with its native projects, assets and agent skills removed, plus small components tested on all three
65+
runners. It's a Bun workspace, so `bun install` at the root installs it, and
66+
it uses the library through `workspace:*` and the package's own exports,
67+
like an app would. `bun run test:examples` runs its typecheck and tests, and CI
68+
runs them against pinned and latest NitroUI.
69+
70+
- Re-create it from the template whenever the NitroUI template changes,
71+
usually when raising the NitroUI version. The steps and the deliberate
72+
changes from the template are in `examples/basic/README.md`.
73+
- Its NitroUI packages and React must match the root's exact versions: the
74+
library and the app share one `nitro-ui-renderer` and one React only when
75+
the versions are the same. `scripts/use-latest-nitro-ui.sh` updates both.
76+
- The template's `App` isn't tested, because `nitro-ui-navigation` isn't
77+
supported yet.
78+
6079
## Tests
6180

6281
- Tests live in `src/**/__tests__/*.test.{ts,tsx}`, and every file must pass on
@@ -138,10 +157,12 @@ The setup entries (`src/setup/`) let NitroUI load without a device:
138157
works without a global `jest`.
139158
- Matchers (`src/matchers/`, one file per matcher, shared message helpers in
140159
`utils.ts`) follow RNTL v14 where NitroUI allows:
141-
`toBeOnTheScreen`, `toBeEmptyElement`, `toContainElement`,
160+
`toBeMounted`, `toBeEmptyElement`, `toContainElement`,
142161
`toHaveTextContent`, `toHaveDisplayValue`, `toHaveProp` and `toHaveStyle`,
143-
plus NitroUI's `toHaveLayout`. The other RNTL matchers need accessibility
144-
props. They use only the parts of a matcher's `this` that Jest, Vitest and
162+
plus NitroUI's `toHaveLayout`. `toBeMounted` is RNTL's `toBeOnTheScreen`,
163+
renamed because it checks the element is in the tree, not that it's on
164+
screen; keep that name free of a `toBeOnTheScreen` alias. The other RNTL
165+
matchers need accessibility props. They use only the parts of a matcher's `this` that Jest, Vitest and
145166
Bun share, and write the first message line by hand, because
146167
`utils.matcherHint` differs between runners. `register()` adds them to
147168
`expect`: the Vitest and Bun setup entries pass their `expect`, and on Jest
@@ -158,22 +179,24 @@ no `fireEvent`: NitroUI handlers live on gesture recognizers and the native
158179
`TextInput`, not on host props, so the realistic path is the only one. There's
159180
no `userEvent.setup()` either, since there's no state or option to keep.
160181

161-
- `tap`, `longPress` and `pan` (one file each) run the recognizers a touch
182+
- `tap` runs the recognizers a touch
162183
would reach (`dispatch-gesture.ts`, with hit testing in `hit-test.ts`): from the `gestureRecognizers` prop, or attached
163184
with `setGestureRecognizers()` through a ref (`helpers/native-view.ts`
164185
records them). The deepest accepting recognizer wins. Disabled ones and ones
165186
whose `gestureRecognizerShouldBegin` returns `false` are skipped, and
166-
`isUserInteractionEnabled={false}` sends the touch to the view below. They
167-
throw when no recognizer for the gesture exists at all, since that's almost
168-
always a test mistake, but do nothing when one exists and can't run.
187+
`isUserInteractionEnabled={false}` sends the touch to the view below. It
188+
throws when no recognizer for the gesture exists at all, since that's almost
189+
always a test mistake, but does nothing when one exists and can't run.
169190
- `tap` also runs a `LongPressGestureRecognizer` with
170191
`minimumPressDuration = 0`, NitroUI's documented pressable pattern.
171-
- `longPress` and `pan` wait (`user-event/wait.ts`): in real time, or by
172-
advancing fake timers when they're on.
173192
- `type` edits the `MockTextInputRef`, so each character goes through
174193
`onBeforeTextChange`, `onTextChanged` and `onSelectionChanged` like on a
175194
device. `{Backspace}` and `{Enter}` are special keys.
176195
- Names follow NitroUI, not RNTL: `tap`, not `press`.
196+
- No `longPress` or `pan` yet: their APIs (holding or dragging step by step,
197+
release velocity) need more design first. Their recognizers are still faked,
198+
so apps that create them render, but only `tap` runs them, and only a long
199+
press with no minimum hold.
177200

178201
## `device`
179202

0 commit comments

Comments
 (0)