refactor: code quality improvements (dedup, error messages, Proxy screen, ?? fix)#10
Merged
Lojhan merged 2 commits intoApr 1, 2026
Conversation
added 2 commits
April 1, 2026 10:13
- plugin.ts: extract maybePruneMetrics() to deduplicate pruning logic in
onTestProcess (batch and single metric paths)
- plugin.ts: use result.shouldHandle in runner() instead of ignoring it
- plugin-command.ts: throw descriptive error in resolveDomSetupPath when
custom DOM adapter setupModule path does not exist
- react-testing.ts: extract unmountMounted() helper, used by both unmount()
and cleanup() to eliminate duplicated try/finally teardown block
- react-testing.ts: replace manual screen rebinding loop with a Proxy so
future @testing-library/dom queries are forwarded automatically
- react-testing.ts: fix renderHook initialProps to use ?? instead of ||,
preventing falsy values (null, 0, '') from being coerced to {}
- react-testing.ts: add clarifying comment on export * shadowing behaviour
Lojhan
approved these changes
Apr 1, 2026
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.
A few targeted refactors spotted during a code review. No behaviour changes intended.
Changes
plugin.tsmaybePruneMetrics(): the pruning logic (if (metrics.length > topN * 10)) was duplicated in both the batch and single-metric branches ofonTestProcess. Extracted to a local helper called after each push.result.shouldHandleinrunner(): the runner was callingbuildRunnerCommandbut ignoringshouldHandle, always returningresult.command. Now returns the originalcommandwhenshouldHandleis false, matching the intent ofBuildRunnerCommandOutput.plugin-command.tsresolveDomSetupPathwith a{ setupModule }adapter was silently returning a non-existent path. Now throws anErrorwith the resolved path and a hint pointing topoku.config.js, making misconfiguration immediately obvious.react-testing.tsunmountMounted(): thetry/finallyteardown block (unmount root, remove container, delete from set) was copy-pasted betweenunmount()andcleanup(). Both now call a sharedunmountMounted(mounted)helper.screenrebinding with aProxy: the previousObject.keysloop manually rebound every function ongetQueriesForElement(document.body). AProxyis simpler, handles non-enumerable properties, and automatically forwards any queries added in future@testing-library/domreleases.renderHookinitialProps coercion:options.initialProps || ({} as Props)coerces falsy values (null,0,false,'') to{}. Changed to??so onlyundefinedfalls back.export *shadowing: added a note that local named exports (screen,fireEvent, etc.) shadow same-named re-exports from the star export in ESM.