Skip to content

Conversation

@jkowalski
Copy link
Contributor

No description provided.

@jkowalski jkowalski requested a review from Copilot June 7, 2025 04:48
Copy link

Copilot AI left a 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.

intervalCallbacks = [];
intervalId = 0;

intervalSpy = vi.spyOn(window, "setInterval").mockImplementation((callback, delay) => {
Copy link

Copilot AI Jun 7, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines 66 to 95
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 = [];
Copy link

Copilot AI Jun 7, 2025

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.

Suggested change
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();

Copilot uses AI. Check for mistakes.
intervalCallbacks = [];
intervalId = 0;

intervalSpy = vi.spyOn(window, "setInterval").mockImplementation((callback, delay) => {
Copy link

Copilot AI Jun 7, 2025

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.

Copilot uses AI. Check for mistakes.
@jkowalski jkowalski merged commit 1a4f53f into kopia:main Jun 7, 2025
2 checks passed
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.

1 participant