Skip to content

fix: repair test environment and four cross-package bugs - #177

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier3-2174-1789575571
Open

stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier3-2174-1789575571

Conversation

@stooit

@stooit stooit commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes the full suite pass (bun test → 13 pass / 0 fail) and clears all tsc --noEmit errors (exit 0). Fixes two test-environment/config gaps and four source bugs spanning all three packages. No test files were modified and no dependencies were added.

Changes

Config (unblocked 8 of the failures)

  • bunfig.toml — [test].environment = "happy-dom" is Vitest syntax that Bun silently ignores, so tests ran with no DOM (document is not defined). Replaced with preload of the existing happy-dom setup.ts, so bare bun test now has DOM globals.
  • tsconfig.json — added "types": ["bun-types"]. The package is installed but not under @types, so TS never auto-included it, causing Cannot find module 'bun:test'.

Source bugs

  • apps/web/src/lib/api.ts — useThrottle → useDebounce. The hook was renamed in @e2e/utils (only useDebounce is exported; the implementation is a trailing debounce, and the consumer is a search input, so debounce is the correct primitive). Merged the duplicate @e2e/utils imports.
  • packages/ui/.../Button.tsx — icon-only buttons now forward an aria-label (explicit label → string children → fallback), with a dev-only warning when unlabelled. Text buttons receive undefined so React omits the attribute and their accessible name still derives from visible text. [WCAG 4.1.2, 2.5.3]
  • packages/ui/.../DataTable.tsx — sort handler uses the functional setSortDir(prev => …) form, removing a stale-closure/batched-render hazard.
  • packages/utils/.../date.ts — formatDate emits day-first en-AU output without a leading-zero day, using formatToParts to preserve a 4-digit year (avoids dateStyle: "short" truncating to 1/3/24).

Verification

  • bun test → 13 pass / 0 fail (each package also passes standalone).
  • bunx tsc --noEmit → exit 0.
  • Each change was independently confirmed load-bearing (reverting it reintroduces a failure), except the DataTable change which is safe hardening.

Assumptions / follow-ups (out of scope)

  • Date format is a hybrid D/MM/YYYY (unpadded day, padded month) — the least-bad way to satisfy the existing /^1/ assertion without truncating the year. A follow-up should align on one canonical format and adjust the test.
  • "Button" aria-label fallback satisfies WCAG's letter but conveys little; the dev warning steers callers to pass a meaningful label. A compile-time requirement wasn't possible because a test renders an unlabelled icon button.
  • Pre-existing timezone fragility in formatDate (ambient TZ) is retained; it passes on UTC/AU runners but would flake at UTC+13/+14.
  • Root package.json pins bun-types to latest; now load-bearing for tsc, worth pinning later.

Wire happy-dom via bunfig preload and add bun-types to tsconfig so the
test suite has DOM globals and TS resolves bun:test. Fix four source
bugs the tests catch:

- api.ts: useThrottle -> useDebounce (hook was renamed in @e2e/utils)
- Button: forward an aria-label for icon-only buttons [WCAG-4.1.2]
- DataTable: use functional setState in sort handler (stale closure)
- formatDate: emit day-first en-AU format without leading-zero day

No test files modified, no dependencies added.
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