fix: repair cross-package test and type failures in monorepo - #120
Open
stooit wants to merge 1 commit into
Open
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 barebun testfrom the root registered no DOM and every@testing-library/reactrender()threwReferenceError: document is not defined. Replaced withpreload = ["./packages/ui/test/setup.ts"], which invokes the happy-domGlobalRegistrator. (This was the root cause of the majority of failures.)tsconfig.json— added"types": ["bun-types"](already installed) to resolve theCannot find module 'bun:test'errors in the test files.apps/web/src/lib/api.ts— theuseThrottlehook was renamed touseDebounceinpackages/utils; fixed the stale import and theuseSearchDebouncere-export alias. The exported symbol is byte-identical, so no downstream consumer changes.packages/ui/.../Button.tsx— the component destructuredariaLabelbut never applied it. Now applied to the<button>, with a fallback for the icon-only case and a dev-onlyconsole.warn(guarded against a missingprocessglobal for raw-browser safety).packages/utils/src/format/date.ts— theen-AUlocale already orders day-first; the only defect was a zero-padded day (01/03/2024).formatDatenow strips the leading zero from the day part viaformatToParts, yielding1/03/2024while 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 functionalsetState(correct under React 18 automatic batching) and corrected the stale-closure comment.Test plan
bun test→ 13 pass / 0 failnpx tsc --noEmit→ exit 0 (clean)Assumptions / decisions
bunfig.toml,tsconfig.json, andpackages/ui/test/setup.tsare configuration, not test files — only*.test.ts(x)were treated as off-limits. The config change was necessary to register the DOM environment.1/03/2024(4-digit year) rather thandateStyle:"short"(1/3/24). The test comment documents1/03/2024as the intent, andformatDateis re-exported app-wide, so preserving the 4-digit-year contract for existing consumers was the safer choice.setStateguards against a real batching hazard the file's own comment flagged.Follow-ups (out of scope, non-blocking)
--preloadflag in thepackage.jsontest script is now redundant with the bunfig setting.aria-labelcould 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.