Repository navigation
test: generate the demo's registry copies, and cover the measurement machine - #25
Conversation
…machine Two kinds of duplication and drift previously went unchecked. Generated registry copies. The registry components are the source of truth for what shadcn installs. The demo needs the same code pointing at its own vendored components rather than at `@/components/ui/*`, which resolves through a consumer's setup, so its copies are now generated by scripts/sync-registry-copies.mjs instead of maintained by hand. They had already drifted: the demo copies were missing five comment lines the registry versions carry. `pnpm sync:registry:check` fails on a stale or hand-edited copy and runs in CI. What generation cannot cover is checked by tests instead: that the two registry variants differ only by the one prop Base UI's Positioner takes and Radix has no equivalent for, that each declared exemption really is present in exactly one variant, that both expose the same public API, and that every path in each registry.json exists on disk. Regression tests for the measurement machine. jsdom has no layout engine, so `getBoundingClientRect` returns zeros and `getClientRects` returns nothing — under those values the component filters out every child and measurement quietly does nothing, and tests would pass against a component that does not work. So the tests run against a deliberately simple flex-wrap model in tests/dom/layout-harness.ts, where items declare their width and rects are computed by filling rows. That covers the phase machine, the invalidation triggers, and the visible-count arithmetic. It does not cover anything depending on real layout, such as the `min-width: auto` behaviour fixed in 0.3.3; the Storybook stories stay responsible for that. Every test was checked by reverting the behaviour it guards. Six reversions, six failures: measuring every child (#23), never re-measuring on a signature change (#21), reducing the signature to a plain sum, reducing it to a position-weighted sum, dropping the length check from the comparison, and reintroducing a 0.5px tolerance. Also adds a CI workflow. Only deploy and publish ran before, so nothing checked a pull request. Type-checking now includes the tests through tsconfig.test.json, which caught two real errors in them: passing `children` alongside `items`, which the props union forbids, and `Array.prototype.at` being outside the configured lib. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
✅ Deploy Preview for react-responsive-overflow-list ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Review limit reached
Next review available in: 18 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (12)
Comment |
Adds the first tests this repo has, plus CI to run them. Two kinds of duplication and drift previously went unchecked.
1. The registry copies are now generated, not tested
You preferred generation wherever generation is possible, so the demo's copies of the shadcn registry components are derived rather than maintained by hand.
The registry files are the source of truth for what consumers install. They import
@/components/ui/*, which resolves through a consumer's own shadcn setup, so the demo cannot use them as-is — it needs the same code pointing at its own vendored components. That is the only difference, soscripts/sync-registry-copies.mjsemits the demo copies with the import rewritten and a do-not-edit banner.They had already drifted: both demo copies were missing five comment lines (4 JSDoc + 1 inline) that the registry versions carry. Regenerating restored them — visible in the diff, and behaviour-neutral.
pnpm sync:registry:checkfails on a stale or hand-edited copy, runs in CI, and is also wired into the demo'sprebuildso the demo can never build against a stale copy.2. Tests for what generation cannot cover
files[].pathin eachregistry.jsonexistsshadcn addsilentlyThe only legitimate variant difference turned out to be a single line:
positionerClassName="z-50", which Base UI's Positioner takes and Radix has no equivalent for. That is declared in one place in the test.3. jsdom regression tests for the measurement machine
The problem worth stating up front: jsdom has no layout engine.
getBoundingClientRectreturns all zeros andgetClientRectsreturns an empty list. Under those valuesgetRowPositionsDatafilters out every child and measurement quietly does nothing — so naive jsdom tests would pass against a component that does not work at all.So the tests run against a deliberately simple flex-wrap model in
tests/dom/layout-harness.ts: items declare a width, the container declares a width, rects come from filling rows left to right, and a stub ResizeObserver reports the container's box the way a browser's does.What this buys: the phase machine, the invalidation triggers, and the visible-count arithmetic, all deterministic.
What it does not buy: anything depending on real layout — the
min-width: autoflex behaviour fixed in 0.3.3, fractional pixel grids, font metrics. The Storybook stories stay responsible for those, in a real browser. This is a complement to them, not a replacement.Cases: all-fit, overflow with correct visible count,
maxRows={2}, #23 items kept mounted and hidden (through the realrenderItemVisibilityprop), #23 out-of-flow children injected the way a popover library injects focus guards, #21 grow, #21 shrink, #21 redistribution at constant total, container resize, and settling.Every test was checked by reverting what it guards
A test that cannot fail is worth nothing, so each was mutation-tested. Six reversions, six failures:
catches a redistribution that leaves the total unchangedcatches a redistribution that leaves a position-weighted total unchangedcatches a longer sequencecatches changes smaller than a pixelThe consistency tests were mutation-tested too: hand-editing a generated copy and introducing a stray difference between variants each fail.
One honest note, recorded in the test file itself: the end-to-end redistribution test does not by itself discriminate between signature reductions, because the signature only covers the visible children, so widening item0 moves any reduction of it too. The cases that actually discriminate are the unit tests in
content-signature.test.ts.4. CI
Only deploy and publish ran before, so nothing checked a pull request — tests that never run guard nothing.
.github/workflows/ci.ymlruns the generation check, type-check, tests, build (which includesattw+publint), and the demo's type-check.Type-checking now includes the tests via
tsconfig.test.json, which immediately caught two real errors in them: passingchildrenalongsideitems, which the props union forbids, andArray.prototype.atbeing outside the configuredlib.Noted, not changed
useResizeObserverstores a fresh object per notification, so a ResizeObserver firing with an unchanged box still triggers a full measuring pass. Browsers only fire when the box actually changes, so this is wasted work rather than a bug, and comparing values beforesetStatewould fix it. Left alone here to keep this PR to tests and tooling; the behaviour is pinned by a test so a future change to it is deliberate.Still to come
The Storybook deploy, so previews can show the stories, is deliberately a separate PR — Netlify currently publishes only the docs app, so no preview shows the repro stories added in #23 and #24.
🤖 Generated with Claude Code