Skip to content

test(web): add a DOM test environment and cover the core invariants - #38

Merged
PunGrumpy merged 6 commits into
mainfrom
advisor/004-web-test-environment
Aug 30, 2026
Merged

test(web): add a DOM test environment and cover the core invariants#38
PunGrumpy merged 6 commits into
mainfrom
advisor/004-web-test-environment

Conversation

@PunGrumpy

Copy link
Copy Markdown
Owner

Why

No hook, component, or provider in the web app had any test, because no DOM environment was installed and `renderHook` had nothing to render into. That left the app's core machinery unverified:

  • `hooks/use-optimizer.ts` owns object-URL lifetimes, batch supersession via a generation map, and the 300 ms quality debounce. A regression there silently leaks blob URLs or commits a stale result.
  • `lib/compress/pool.ts` documents two invariants (at most `limit` in flight, start order preserved) that nothing asserted.
  • The three limit constants in `lib/image/constants.ts` claim by comment to mirror `packages/core/types.go`, with a comment as the only enforcement.

What changed

  • `happy-dom` + `@happy-dom/global-registrator` + `@testing-library/react` as dev dependencies, registered through `bunfig.toml` preload. The 43 pre-existing tests pass unchanged under the DOM registration.
  • `pool.test.ts`: concurrency ceiling, start order, fewer-items-than-limit, and a characterization that a rejecting task rejects the whole batch (the documented contract).
  • `limits-parity.test.ts`: reads `packages/core/types.go`, parses the Go literals without `eval` (handles both `20 << 20` and `100_000_000` forms), and asserts equality with the TS constants. Drift in either language now fails `bun test`.
  • `use-optimizer.test.tsx`: five characterization tests through `renderHook` with deferred compression mocks: batch completion, supersession (the stale result is discarded and its URL revoked), removal mid-flight, unmount revoking every job URL, and the quality debounce under fake timers.

Notes for review

  • `mock.module` in Bun patches the module registry for the whole test process. The browser-module mock therefore re-exports the real `readPreview`/`targetDimensions` (captured before mocking) so `browser.test.ts` keeps testing the genuine implementations in the same run.
  • All five hook tests passed against the unmodified hook, so no behavior bug surfaced. They exist as the safety net for the upcoming cancellation work on this hook.
  • This branch and ci: fail on format drift, freeze installs, and fix turbo cache keys #35 both touch `bun.lock`; whichever merges second needs a trivial rebase.

Verification

`bun test` in `apps/web`: 55 pass, 0 fail, 92 assertions across 10 files. `bun run typecheck` and root `bun run check` exit 0.

@vercel

vercel Bot commented Aug 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pigo Ready Ready Preview Aug 30, 2026 2:09am
pigo-api Ready Ready Preview Aug 30, 2026 2:09am

@changeset-bot

changeset-bot Bot commented Aug 30, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 72e0fe8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 72e0fe8.

@PunGrumpy
PunGrumpy merged commit ed22807 into main Aug 30, 2026
10 checks passed
@PunGrumpy
PunGrumpy deleted the advisor/004-web-test-environment branch August 30, 2026 03:16
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