Skip to content

fix: repair cross-package test and type failures in monorepo - #120

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier3-2280-1786810078
Open

fix: repair cross-package test and type failures in monorepo#120
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier3-2280-1786810078

Conversation

@stooit

@stooit stooit commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all failing tests and type errors across the monorepo. Root run now reports 13 pass / 0 fail (bun test) and 0 errors (tsc --noEmit). No test files were modified and no dependencies were added.

The bugs spanned all three packages plus test configuration:

  • bunfig.toml — the [test] environment = "happy-dom" key is not recognised by Bun and was silently ignored, so bare bun test from the root registered no DOM and every @testing-library/react render() threw ReferenceError: document is not defined. Replaced with preload = ["./packages/ui/test/setup.ts"], which invokes the happy-dom GlobalRegistrator. (This was the root cause of the majority of failures.)
  • tsconfig.json — added "types": ["bun-types"] (already installed) to resolve the Cannot find module 'bun:test' errors in the test files.
  • apps/web/src/lib/api.ts — the useThrottle hook was renamed to useDebounce in packages/utils; fixed the stale import and the useSearchDebounce re-export alias. The exported symbol is byte-identical, so no downstream consumer changes.
  • packages/ui/.../Button.tsx — the component destructured ariaLabel but never applied it. Now applied to the <button>, with a fallback for the icon-only case and a dev-only console.warn (guarded against a missing process global for raw-browser safety).
  • packages/utils/src/format/date.ts — the en-AU locale already orders day-first; the only defect was a zero-padded day (01/03/2024). formatDate now strips the leading zero from the day part via formatToParts, yielding 1/03/2024 while keeping the padded month and 4-digit year. Corrected the misleading "MM/DD/YYYY" header comment.
  • packages/ui/.../DataTable.tsx — hardened the sort toggle to a functional setState (correct under React 18 automatic batching) and corrected the stale-closure comment.

Test plan

  • bun test → 13 pass / 0 fail
  • npx tsc --noEmit → exit 0 (clean)

Assumptions / decisions

  • bunfig.toml, tsconfig.json, and packages/ui/test/setup.ts are configuration, not test files — only *.test.ts(x) were treated as off-limits. The config change was necessary to register the DOM environment.
  • Date format kept as 1/03/2024 (4-digit year) rather than dateStyle:"short" (1/3/24). The test comment documents 1/03/2024 as the intent, and formatDate is re-exported app-wide, so preserving the 4-digit-year contract for existing consumers was the safer choice.
  • The DataTable change is robustness only — the test passed once the DOM was registered; the functional setState guards against a real batching hazard the file's own comment flagged.

Follow-ups (out of scope, non-blocking)

  • The --preload flag in the package.json test script is now redundant with the bunfig setting.
  • aria-label could be made a required prop for the icon-only variant via a discriminated union (compile-time enforcement instead of a runtime fallback) — an API change left for a separate PR.

- bunfig.toml: use `preload` instead of the ignored `environment` key so
  the happy-dom DOM environment registers for bare `bun test`
- tsconfig.json: add `bun-types` so `bun:test` imports type-check
- apps/web/src/lib/api.ts: follow the useThrottle→useDebounce rename at
  both the import and the useSearchDebounce re-export; merge duplicate import
- Button: apply aria-label to the button, with an icon-only fallback and a
  dev-only warning (guarded against a missing `process` global)
- date.ts: strip the leading zero from the en-AU day part so formatDate
  returns 1/03/2024; correct the stale MM/DD/YYYY comment
- DataTable: use a functional setState for the sort toggle to harden
  against React 18 batching; correct the stale-closure comment
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