Skip to content

Conversation

@samuv
Copy link
Collaborator

@samuv samuv commented Oct 29, 2025

Breaking Changes Fixed

Vitest 4 requires vi.fn() mocks to use function/class constructors instead of arrow functions.

Changes

  • Updated Vitest monorepo to v4
  • Added memfs for file system mocking
  • Fixed mock implementations across all test files:
    • Changed vi.fn().mockImplementation(() => {}) to vi.fn(function Mock() {})
    • Updated Node.js built-in module mocks (node:child_process, node:fs, node:net) to use importOriginal and share mock instances between named/default exports
    • Migrated to memfs for file system mocking

Files Updated

Renderer:

  • use-chat-streaming.test.ts, use-download-file.test.ts, logs-tab.test.tsx, group-selector-form.test.tsx, use-mcp-secrets.test.ts, theme-provider.test.tsx

Main:

  • auto-update.test.ts, graceful-exit.test.ts, toolhive-manager.test.ts

All tests passing ✅

Copilot AI review requested due to automatic review settings October 29, 2025 09:32
@samuv samuv self-assigned this Oct 29, 2025
Copy link
Contributor

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 upgrades Vitest from v3.x to v4.x and introduces memfs for mocking the file system in tests. Key changes include updating test mock implementations to use named functions for better debugging and replacing direct node:fs mocks with memfs.

  • Upgraded vitest from ^3.1.4 to ^4.0.0 and @vitest/coverage-istanbul from ^3.1.4 to ^4.0.0
  • Added memfs (^4.50.0) for file system mocking
  • Refactored vi.fn().mockImplementation() to use named function expressions in test mocks
  • Created reusable __mocks__ files for fs and fs/promises using memfs
  • Updated test setup in toolhive-manager.test.ts to use vol from memfs for file system state management

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
package.json Updated Vitest and coverage dependencies to v4.x, added memfs package
pnpm-lock.yaml Updated lockfile with new dependency versions and their transitive dependencies
renderer/src/features/meta-mcp/components/tests/group-selector-form.test.tsx Refactored mock to use named function expression
renderer/src/features/chat/hooks/tests/use-chat-streaming.test.ts Refactored mock to use named function expression
renderer/src/common/hooks/tests/use-mcp-secrets.test.ts Refactored mocks to use named function expressions
renderer/src/common/hooks/tests/use-download-file.test.ts Refactored Blob mock to use named function expression
renderer/src/common/components/theme/tests/theme-provider.test.tsx Refactored matchMedia mock to use named function expression
renderer/src/common/components/settings/tabs/tests/logs-tab.test.tsx Refactored Blob mock to use named function expression
main/src/tests/toolhive-manager.test.ts Replaced existsSync mocks with memfs, refactored mocks to use named functions, exported binPath for testing
main/src/tests/graceful-exit.test.ts Refactored ElectronStore mock to use named function expression
main/src/tests/auto-update.test.ts Refactored ElectronStore mock to use named function expression
mocks/fs/promises.cjs Created mock for node:fs/promises using memfs
mocks/fs.cjs Created mock for node:fs using memfs
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

peppescg
peppescg previously approved these changes Oct 29, 2025
@samuv samuv merged commit a74d40f into main Oct 29, 2025
13 checks passed
@samuv samuv deleted the bump-vitest branch October 29, 2025 10:18
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.

3 participants