test(ui): extract shared test helpers to reduce boilerplate - #6928
Merged
Conversation
Add `createTestWrapper()` and `renderHookWithClient()` to `src/tests/wrapper.tsx`, replacing 30 ad-hoc `createWrapper` / `createQueryWrapper` helpers scattered across test files. `renderHookWithRouter` now delegates to `createTestWrapper` instead of duplicating the `QueryClient` + `MemoryRouter` setup.
…s/sdk.ts` Replaces 15 local `mockSdkResponse` definitions, 13 local `SdkResponse` type aliases, and 5 local `makeSdkError` helpers with shared imports.
Code Review CompleteThe automated review ran but did not post an updated summary — this usually means no new issues were found since the previous review. If you've pushed changes and want a fresh pass, 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.
What
Shared test utilities in
src/tests/replace duplicated boilerplate scattered across ~50 console test files, cutting ~500 net lines.Why
The console test suite had identical helper definitions copied across dozens of files —
createWrapper/createQueryWrapper(30 copies with config drift),mockSdkResponse(15 copies),makeSdkError(5 copies),LocationProbe(3 copies), andmockUserAuth(3 copies). Each copy was slightly different (4 distinctQueryClientconfigs, varying error shapes), making it hard to know which was correct and easy to introduce subtle test bugs.Partial work toward shellhub-io/team#216
Changes
src/tests/wrapper.tsx:createTestWrapper()— composable wrapper factory accepting optionalqueryClientandinitialEntries(forMemoryRouter).renderHookWithClient()— convenience for hook tests. SupersetQueryClientconfig (retry: false,gcTime: 0) eliminates config drift across the 4 variants that existed before.src/tests/sdk.ts:mockSdkResponse<T>()with optionalheadersparameter (superset of the simple and with-headers variants),makeSdkError()that properly creates anErrorwithstatusandheaders(some local copies only had{ status }withoutErrororHeaders), and theSdkResponsetype alias.src/tests/LocationProbe.tsx: callback-styleLocationProbecomponent for URL assertion in routing tests (3 duplicates replaced; the single-use DOM variant inCommandPalette.test.tsxwas intentionally left local).src/tests/userAuth.ts:mockUserAuth()factory forUserAuthfixtures (3 duplicates replaced).src/tests/renderHookWithRouter.tsx: refactored to delegate tocreateTestWrapperinstead of duplicating theQueryClient+MemoryRoutersetup.Testing
npm run --workspace apps/console test— all 211 test files pass. The shared helpers themselves have unit tests insrc/tests/__tests__/.