Commit 97dbfb2
committed
test(client-react): give the package a test harness and pin realtime hook behavior (#4682)
`packages/client-react` shipped 8 public hooks with `build` and `typecheck` as
its only scripts and zero test files. `tsc --noEmit` is structurally blind to
what actually breaks in a hook: a dependency array is a value, not a type, so a
missing entry, a missing cleanup and a callback that never fires all typecheck
perfectly. #4678 was exactly that shape — `useAutoRefresh` ignored predicate
writes, the case that dirties a list hardest, and no type noticed.
Adds the workspace's first DOM test environment (jsdom + @testing-library/react,
`environment: 'jsdom'`; every other package runs `node`) and 17 tests over the
realtime hooks covering the three things the type checker cannot see:
- re-subscription driven by the dependency array — changing `object` opens a
subscription on the new name and releases the old one, an unrelated re-render
churns nothing, and the hooks key on the primitive `options?.recordId` /
`options?.packageId` rather than the options object's identity, so an
equal-but-new object stays a no-op;
- release on unmount, including `useAutoRefresh`, which holds two subscriptions;
- delivery — events reach state and callbacks, and `useAutoRefresh` refetches on
the per-record *and* the bulk stream (the #4678 regression pin).
Every assertion was verified by sabotage rather than assumed: dropping the
`object` dep (1 failure), deleting a cleanup (3) and reverting `useAutoRefresh`
to the single-stream version (3) each turn the suite red; reverting turns it
green again.
CI needs no wiring — `Test Core` partitions by package off `turbo ls`, and the
new `test` script puts client-react on shard 2 (verified with
scripts/partition-test-shards.mjs).
No runtime code changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LYnZrTwXbrctB8E8HpJAPT1 parent 742cebb commit 97dbfb2
6 files changed
Lines changed: 926 additions & 88 deletions
File tree
- .changeset
- packages/client-react
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| 30 | + | |
28 | 31 | | |
29 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
| |||
0 commit comments