Skip to content

refactor: code quality improvements (dedup, error messages, Proxy screen, ?? fix)#10

Merged
Lojhan merged 2 commits into
pokujs:mainfrom
luvanovacodes:refactor/code-quality-improvements
Apr 1, 2026
Merged

refactor: code quality improvements (dedup, error messages, Proxy screen, ?? fix)#10
Lojhan merged 2 commits into
pokujs:mainfrom
luvanovacodes:refactor/code-quality-improvements

Conversation

@luvanovacodes
Copy link
Copy Markdown
Contributor

A few targeted refactors spotted during a code review. No behaviour changes intended.

Changes

plugin.ts

  • Extract maybePruneMetrics(): the pruning logic (if (metrics.length > topN * 10)) was duplicated in both the batch and single-metric branches of onTestProcess. Extracted to a local helper called after each push.
  • Honour result.shouldHandle in runner(): the runner was calling buildRunnerCommand but ignoring shouldHandle, always returning result.command. Now returns the original command when shouldHandle is false, matching the intent of BuildRunnerCommandOutput.

plugin-command.ts

  • Descriptive error for missing custom DOM adapter: resolveDomSetupPath with a { setupModule } adapter was silently returning a non-existent path. Now throws an Error with the resolved path and a hint pointing to poku.config.js, making misconfiguration immediately obvious.

react-testing.ts

  • Extract unmountMounted(): the try/finally teardown block (unmount root, remove container, delete from set) was copy-pasted between unmount() and cleanup(). Both now call a shared unmountMounted(mounted) helper.
  • Replace manual screen rebinding with a Proxy: the previous Object.keys loop manually rebound every function on getQueriesForElement(document.body). A Proxy is simpler, handles non-enumerable properties, and automatically forwards any queries added in future @testing-library/dom releases.
  • Fix renderHook initialProps coercion: options.initialProps || ({} as Props) coerces falsy values (null, 0, false, '') to {}. Changed to ?? so only undefined falls back.
  • Clarifying comment on export * shadowing: added a note that local named exports (screen, fireEvent, etc.) shadow same-named re-exports from the star export in ESM.

Gringo 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 Lojhan merged commit 1345aee into pokujs:main Apr 1, 2026
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.

2 participants