Skip to content

test: generate the demo's registry copies, and cover the measurement machine - #25

Merged
Eliav2 merged 1 commit into
mainfrom
chore/generate-registry-copies-and-tests
Aug 8, 2026
Merged

Eliav2 merged 1 commit into
mainfrom
chore/generate-registry-copies-and-tests

Conversation

@Eliav2

@Eliav2 Eliav2 commented Aug 8, 2026

Copy link
Copy Markdown
Owner

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, so scripts/sync-registry-copies.mjs emits 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:check fails on a stale or hand-edited copy, runs in CI, and is also wired into the demo's prebuild so the demo can never build against a stale copy.

2. Tests for what generation cannot cover

assertion why
the two registry variants differ only by declared exemptions they wrap different popover libraries but are otherwise one component
each declared exemption is present in exactly one variant otherwise an exemption silently hides nothing, or hides a real difference in both
both variants expose the same public API
every files[].path in each registry.json exists a broken path breaks shadcn add silently

The 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. getBoundingClientRect returns all zeros and getClientRects returns an empty list. Under those values getRowPositionsData filters 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: auto flex 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 real renderItemVisibility prop), #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:

reversion caught by
measure every child (undo #23) 9 tests
never re-measure on a signature change (undo #21) 3 tests
reduce the signature to a plain sum catches a redistribution that leaves the total unchanged
reduce it to a position-weighted sum catches a redistribution that leaves a position-weighted total unchanged
drop the length check from the comparison catches a longer sequence
reintroduce a 0.5px tolerance catches changes smaller than a pixel

The 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.yml runs the generation check, type-check, tests, build (which includes attw + 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: passing children alongside items, which the props union forbids, and Array.prototype.at being outside the configured lib.

Noted, not changed

useResizeObserver stores 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 before setState would 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

…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>
@codesandbox

codesandbox Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web Editor • VS Code • Insiders

Open Preview

@netlify

netlify Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for react-responsive-overflow-list ready!

Name Link
🔨 Latest commit 0b1774f
🔍 Latest deploy log https://app.netlify.com/projects/react-responsive-overflow-list/deploys/6a7771bed9762a0008a0be5a
😎 Deploy Preview https://deploy-preview-25--react-responsive-overflow-list.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Eliav2, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a46369ad-b9d7-42ac-ab6b-e681e250b78c

📥 Commits

Reviewing files that changed from the base of the PR and between 1ee49e9 and 0b1774f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • .github/workflows/ci.yml
  • demo/package.json
  • demo/src/components/shadcn-base-ui/overflow-list-base.tsx
  • demo/src/components/shadcn-radix-ui/overflow-list-radix.tsx
  • package.json
  • scripts/sync-registry-copies.mjs
  • tests/consistency/registry-copies.test.ts
  • tests/dom/content-signature.test.ts
  • tests/dom/layout-harness.ts
  • tests/dom/overflow-list.test.tsx
  • tsconfig.test.json
  • vitest.config.ts

Comment @coderabbitai help to get the list of available commands.

@Eliav2
Eliav2 merged commit 5b4aaaf into main Aug 8, 2026
6 checks passed
@Eliav2
Eliav2 deleted the chore/generate-registry-copies-and-tests branch August 8, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant