Fix 16 test failures blocking coverage-hourly suite#11183
Conversation
Hooks (useReplicaSets, useStatefulSets, useDaemonSets, useCronJobs, useHPAs, usePodLogs) were migrated from api.get() to agentFetch() but tests still asserted on mockApiGet. Updated test mocks to use a hoisted mockAgentFetch with Response-shaped return values matching the agentFetch contract (resp.ok + resp.json()). Signed-off-by: Andrew Anderson <[email protected]>
- fetcherUtils: create fresh Response per call to avoid consumed body - fetcherUtils: set up cluster context for SSE partial failure fallback - useLastRoute: advance fake timers for setTimeout-based scroll restore Signed-off-by: Andrew Anderson <[email protected]>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellarconsole ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
There was a problem hiding this comment.
Pull request overview
Addresses failing frontend test coverage in the coverage-hourly suite by updating mocks/expectations to match recent behavior changes (notably the api.get → agentFetch migration and async timing in useLastRoute).
Changes:
- Updated
fetcherUtilscoverage tests to avoidResponsebody reuse and to correctly exercise/expect the REST fallback partial-failure path. - Migrated
workloads.extendedtests frommockApiGet-based expectations tomockAgentFetchto reflect the new REST path implementation. - Stabilized a
useLastRoutescroll-restore test by using fake timers to advance the internalsetTimeout.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| web/src/lib/cache/tests/fetcherUtils-coverage.test.ts | Fixes response-mocking semantics and aligns partial-failure expectation with the REST fallback behavior. |
| web/src/hooks/mcp/tests/workloads.extended.test.ts | Updates mocks/assertions to validate URL/query params via agentFetch instead of api.get. |
| web/src/hooks/tests/useLastRoute.test.ts | Uses fake timers to deterministically trigger the delayed scroll restoration. |
| vi.useFakeTimers() | ||
| localStorage.setItem('kubestellar-remember-position', JSON.stringify({ '/clusters': true })) | ||
| localStorage.setItem('kubestellar-scroll-positions', JSON.stringify({ | ||
| '/clusters': { position: 400, cardTitle: undefined } | ||
| })) | ||
| mockPathname = '/clusters' | ||
| renderHook(() => useLastRoute()) | ||
| // restoreScrollPosition is called inside a setTimeout(…, 50) in the navigation effect | ||
| vi.advanceTimersByTime(100) | ||
| // scrollTo should be called with the saved position | ||
| expect(main.scrollTo).toHaveBeenCalledWith(expect.objectContaining({ top: 400 })) | ||
| vi.useRealTimers() |
There was a problem hiding this comment.
vi.useRealTimers() is called at the end of the test body, so if an assertion throws earlier the file can be left in fake-timer mode and leak into subsequent tests. Wrap the fake-timer section in a try/finally (or add a local afterEach that always calls vi.useRealTimers()) so timers are reliably restored even on failure.
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
❌ Post-Merge Verification: failedCommit: |
|
Post-merge build verification passed ✅ Both Go and frontend builds compiled successfully against merge commit |
* Fix 13 failing tests: migrate from mockApiGet to mockAgentFetch Hooks (useReplicaSets, useStatefulSets, useDaemonSets, useCronJobs, useHPAs, usePodLogs) were migrated from api.get() to agentFetch() but tests still asserted on mockApiGet. Updated test mocks to use a hoisted mockAgentFetch with Response-shaped return values matching the agentFetch contract (resp.ok + resp.json()). Signed-off-by: Andrew Anderson <[email protected]> * Fix 3 test failures in fetcherUtils-coverage and useLastRoute - fetcherUtils: create fresh Response per call to avoid consumed body - fetcherUtils: set up cluster context for SSE partial failure fallback - useLastRoute: advance fake timers for setTimeout-based scroll restore Signed-off-by: Andrew Anderson <[email protected]> --------- Signed-off-by: Andrew Anderson <[email protected]> Signed-off-by: lightyagami2109 <[email protected]>
Fixes 16 test failures across 3 files blocking coverage-hourly. Badge stuck at 90%. Details: workloads.extended (13 fails, api.get→agentFetch migration), fetcherUtils-coverage (2 fails, Response body reuse + missing cluster context), useLastRoute (1 fail, setTimeout timing).