-
Notifications
You must be signed in to change notification settings - Fork 43
chore(ci): speed up tests that use polling with long intervals #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR focuses on speeding up tests that use long interval polling by replacing waiting with manual triggering of interval callbacks.
- Replace long timeouts using waitFor with manual triggering helpers.
- Introduce interval spies (setInterval/clearInterval) and corresponding trigger functions in multiple test files.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/pages/Tasks.test.jsx | Introduces interval mocking and triggerIntervals helper to speed up polling tests. |
| tests/components/SnapshotEstimation.test.jsx | Implements interval mocking and adds a helper to trigger intervals after component load. |
| tests/components/Logs.test.jsx | Applies interval mocking to control polling, replacing timed waits with manual triggering. |
tests/pages/Tasks.test.jsx
Outdated
| intervalCallbacks = []; | ||
| intervalId = 0; | ||
|
|
||
| intervalSpy = vi.spyOn(window, "setInterval").mockImplementation((callback, delay) => { |
Copilot
AI
Jun 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The interval mocking logic is duplicated; consider extracting it into a shared helper to reduce code duplication across tests.
| let intervalSpy; | ||
| let clearIntervalSpy; | ||
| let intervalCallbacks = []; | ||
| let intervalId = 0; | ||
|
|
||
| beforeEach(() => { | ||
| serverMock = setupAPIMock(); | ||
| resetRouterMocks(); | ||
| vi.clearAllMocks(); | ||
|
|
||
| // Mock setInterval and clearInterval to control timing | ||
| intervalCallbacks = []; | ||
| intervalId = 0; | ||
|
|
||
| intervalSpy = vi.spyOn(window, "setInterval").mockImplementation((callback, delay) => { | ||
| const id = ++intervalId; | ||
| intervalCallbacks.push({ id, callback, delay }); | ||
| return id; | ||
| }); | ||
|
|
||
| clearIntervalSpy = vi.spyOn(window, "clearInterval").mockImplementation((id) => { | ||
| intervalCallbacks = intervalCallbacks.filter((item) => item.id !== id); | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| serverMock.reset(); | ||
| intervalSpy.mockRestore(); | ||
| clearIntervalSpy.mockRestore(); | ||
| intervalCallbacks = []; |
Copilot
AI
Jun 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider refactoring the repeated interval mocking setup into a common utility to enhance maintainability across tests.
| let intervalSpy; | |
| let clearIntervalSpy; | |
| let intervalCallbacks = []; | |
| let intervalId = 0; | |
| beforeEach(() => { | |
| serverMock = setupAPIMock(); | |
| resetRouterMocks(); | |
| vi.clearAllMocks(); | |
| // Mock setInterval and clearInterval to control timing | |
| intervalCallbacks = []; | |
| intervalId = 0; | |
| intervalSpy = vi.spyOn(window, "setInterval").mockImplementation((callback, delay) => { | |
| const id = ++intervalId; | |
| intervalCallbacks.push({ id, callback, delay }); | |
| return id; | |
| }); | |
| clearIntervalSpy = vi.spyOn(window, "clearInterval").mockImplementation((id) => { | |
| intervalCallbacks = intervalCallbacks.filter((item) => item.id !== id); | |
| }); | |
| }); | |
| afterEach(() => { | |
| serverMock.reset(); | |
| intervalSpy.mockRestore(); | |
| clearIntervalSpy.mockRestore(); | |
| intervalCallbacks = []; | |
| let intervalMock; | |
| beforeEach(() => { | |
| serverMock = setupAPIMock(); | |
| resetRouterMocks(); | |
| vi.clearAllMocks(); | |
| // Initialize interval mocking utility | |
| intervalMock = mockInterval(); | |
| }); | |
| afterEach(() => { | |
| serverMock.reset(); | |
| intervalMock.restore(); |
tests/components/Logs.test.jsx
Outdated
| intervalCallbacks = []; | ||
| intervalId = 0; | ||
|
|
||
| intervalSpy = vi.spyOn(window, "setInterval").mockImplementation((callback, delay) => { |
Copilot
AI
Jun 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The repeated interval mocking pattern here could be extracted into a shared helper to reduce duplication and simplify future maintenance.
No description provided.