Skip to content

Conversation

@deboer-tim
Copy link
Contributor

What does this PR do?

Cleans up some issues in tests:

  • Adds missing getUidGid and listVMs mocks.
  • Simplify ResizeObserver mocking using the same pattern as Podman Desktop renderer.
  • Import correct beforeEach.
  • Import node types to avoid NodeJS import warnings.

Screenshot / video of UI

N/A

What issues does this PR fix or reference?

Fixes #2115.

How to test this PR?

Code looks ok; tests green.

Cleans up some issues in tests:
- Adds missing getUidGid and listVMs mocks.
- Simplify ResizeObserver mocking using the same pattern as Podman Desktop renderer.
- Import correct beforeEach.
- Import node types to avoid NodeJS import warnings.

Fixes podman-desktop#2115.

Signed-off-by: Tim deBoer <git@tdeboer.ca>
@deboer-tim deboer-tim requested a review from a team as a code owner December 2, 2025 22:22
@deboer-tim deboer-tim requested review from MarsKubeX, benoitf and gastoner and removed request for a team December 2, 2025 22:22
@coderabbitai
Copy link

coderabbitai bot commented Dec 2, 2025

📝 Walkthrough

Walkthrough

Test infrastructure consolidation: moved ResizeObserver mocking to centralized setup file, updated timer type annotations to browser-compatible equivalents (ReturnType<typeof setInterval/setTimeout>), standardized test utility imports from vitest, and added deterministic VM list mock setup.

Changes

Cohort / File(s) Change Summary
Test setup centralization
packages/frontend/vite.tests.setup.js
Added ResizeObserver mock implementation to global test setup for @floating-ui/dom compatibility.
Test file mock and setup adjustments
packages/frontend/src/Build.spec.ts, packages/frontend/src/CreateVM.spec.ts, packages/frontend/src/lib/disk-image/DiskImageDetailsBuild.spec.ts, packages/frontend/src/lib/disk-image/DiskImageDetailsVirtualMachine.spec.ts, packages/frontend/src/lib/disk-image/DiskImagesList.spec.ts
Removed ResizeObserver mock definitions from individual test files, fixed vitest import statements (removed beforeAll where unused, standardized beforeEach source), added bootcClient.listVMs deterministic mock in CreateVM.spec.ts, updated test assertions to use local variables.
Type annotation updates
packages/frontend/src/lib/disk-image/DiskImageDetailsBuild.svelte, packages/frontend/src/stores/rpcReadable.ts
Changed timer variable type annotations from NodeJS.Timeout to ReturnType<typeof setInterval> and ReturnType<typeof setTimeout> for browser environment compatibility.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Type annotation migration: Verify that ReturnType<typeof setInterval> and ReturnType<typeof setTimeout> are used consistently and correctly across all affected files; ensure no edge cases with type compatibility in browser contexts.
  • ResizeObserver mock relocation: Confirm that moving the mock from individual test files to the centralized setup file does not break any test-specific mocking requirements or test isolation.
  • Test assertion changes: Review DiskImageDetailsBuild.spec.ts to ensure the switch from hardcoded path string to variable-based assertion maintains test correctness and intent.

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'chore: test cleanup' accurately describes the main focus of the PR, which involves cleaning up test files and mocks.
Description check ✅ Passed The description clearly explains what the PR does and directly references the linked issue #2115, detailing the specific test cleanup fixes.
Linked Issues check ✅ Passed All objectives from issue #2115 are met: getUidGid and listVMs mocks added, ResizeObserver mocking centralized in setup file, beforeEach import corrected, and NodeJS types imported for browser compatibility.
Out of Scope Changes check ✅ Passed All changes are directly related to the test cleanup objectives. Type annotation updates in DiskImageDetailsBuild.svelte and rpcReadable.ts align with the goal of importing Node types and ensuring browser compatibility.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e0012b2 and 84453af.

📒 Files selected for processing (2)
  • packages/frontend/src/lib/disk-image/DiskImageDetailsBuild.svelte (1 hunks)
  • packages/frontend/src/stores/rpcReadable.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: linter, formatter, and tests / windows-2022
  • GitHub Check: linter, formatter, and tests / macos-14
  • GitHub Check: e2e tests
🔇 Additional comments (2)
packages/frontend/src/stores/rpcReadable.ts (1)

31-32: LGTM! Browser-compatible timer types.

The change from NodeJS.Timeout to ReturnType<typeof setTimeout> correctly aligns these timer variables with browser DOM APIs and eliminates the need for Node.js type imports in frontend code.

packages/frontend/src/lib/disk-image/DiskImageDetailsBuild.svelte (1)

28-28: LGTM! Correct interval timer typing.

The change from NodeJS.Timeout to ReturnType<typeof setInterval> properly aligns the interval timer with browser DOM APIs and matches the usage pattern at lines 90 and 112.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
packages/frontend/tsconfig.json (1)

22-22: Node typings now available globally in frontend TS

Adding "node" to compilerOptions.types satisfies the editor warnings goal and is consistent with the PR description, but it also makes Node globals (e.g., process, Buffer) typecheck in all frontend sources. If you’d prefer to keep browser code guarded from accidental Node usage, consider scoping Node types to a test-specific tsconfig instead (e.g., a dedicated tsconfig.vitest.json that extends this one).

packages/frontend/src/CreateVM.spec.ts (1)

22-48: Deterministic default listVMs mock via beforeEach

Importing beforeEach from vitest and setting bootcClient.listVMs to resolve to [] before every test gives all cases a sane default and removes the missing-mock noise described in the issue. Tests that need a non-empty VM list can still override this mock as you do later in the file; for extra clarity, you might consider setting those overrides before calling render so the component never briefly sees the default list, but that’s optional given current behavior.

packages/frontend/vite.tests.setup.js (1)

21-28: Centralized ResizeObserver mock is good; consider also setting global.ResizeObserver

The ResizeObserverMock with no-op methods is sufficient for tests that just need the API surface (e.g., @floating-ui/dom) and centralizing it here removes duplication from individual specs. To make this more robust against code that references ResizeObserver directly (without window.), you could also assign the mock to the global symbol:

-class ResizeObserverMock {
-  observe() {}
-  unobserve() {}
-  disconnect() {}
-}
-
-global.window.ResizeObserver = ResizeObserverMock;
+class ResizeObserverMock {
+  observe() {}
+  unobserve() {}
+  disconnect() {}
+}
+
+global.window.ResizeObserver = ResizeObserverMock;
+global.ResizeObserver = ResizeObserverMock;
packages/frontend/src/lib/disk-image/DiskImageDetailsBuild.spec.ts (1)

67-73: Use of folderLocation variable in expectation reduces duplication

Asserting loadLogsFromFolder with folderLocation instead of a string literal keeps the test aligned with the prop passed into render and avoids drift if the folder path changes later. If you want to go further, you could apply the same pattern to the error-message assertion in the “Handles empty logs correctly” test, but that’s purely a readability improvement.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7bcda3c and e0012b2.

📒 Files selected for processing (7)
  • packages/frontend/src/Build.spec.ts (1 hunks)
  • packages/frontend/src/CreateVM.spec.ts (2 hunks)
  • packages/frontend/src/lib/disk-image/DiskImageDetailsBuild.spec.ts (1 hunks)
  • packages/frontend/src/lib/disk-image/DiskImageDetailsVirtualMachine.spec.ts (1 hunks)
  • packages/frontend/src/lib/disk-image/DiskImagesList.spec.ts (1 hunks)
  • packages/frontend/tsconfig.json (1 hunks)
  • packages/frontend/vite.tests.setup.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/frontend/src/CreateVM.spec.ts (1)
packages/frontend/src/api/client.ts (1)
  • bootcClient (28-28)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: linter, formatter, and tests / macos-14
  • GitHub Check: linter, formatter, and tests / windows-2022
  • GitHub Check: e2e tests
🔇 Additional comments (3)
packages/frontend/src/Build.spec.ts (1)

100-117: bootcClient.getUidGid mock completes the test client surface

Adding getUidGid: vi.fn() to the local bootcClient mock matches the expected API and should eliminate missing-method noise when Build uses chown-related options in tests. For any tests that depend on a specific UID/GID, you can still override this mock with mockResolvedValue in those specs.

packages/frontend/src/lib/disk-image/DiskImageDetailsVirtualMachine.spec.ts (1)

18-20: Vitest import now matches actual usage and shared test setup

Switching the import to { vi, test, expect } and relying on the global test setup for DOM shims (like ResizeObserver) keeps this spec minimal and consistent with the rest of the suite. No remaining hooks here depend on the removed per-file setup.

packages/frontend/src/lib/disk-image/DiskImagesList.spec.ts (1)

18-18: Use of vitest’s beforeEach aligns lifecycle hooks with the test runner

Importing beforeEach from vitest (instead of Node’s test module) makes the lifecycle hook consistent with the rest of the suite and with the mocking utilities from vi. This should avoid subtle issues from mixing different test frameworks.

Copy link

@MarsKubeX MarsKubeX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

"allowJs": true,
"checkJs": true,
"types": ["@testing-library/jest-dom"]
"types": ["@testing-library/jest-dom", "node"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: is that sage to use node in the frontend ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should not use node on frontend yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed node types and replaced code instances with ReturnType<typeof ...> to avoid any typing errors.

Copy link
Contributor

@gastoner gastoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codewise LGTM

Replaces NodeJS types with node/javascript compatible types.

Signed-off-by: Tim deBoer <git@tdeboer.ca>
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.

Test cleanup

5 participants