Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

Migrate from vitest 3.2.4 to 4.0.6.

Mock Setup Changes

Vitest 4 requires factory functions for vi.mock() to properly initialize mocked modules:

// Before
vi.mock("fs/promises");
const mockFs = vi.mocked(fs);

// After
vi.mock("fs/promises", () => ({
  default: { readFile: vi.fn(), writeFile: vi.fn() },
  readFile: vi.fn(),
  writeFile: vi.fn(),
}));
const mockFs = fs;

Updated add-new-setting.spec.js and update_translation.spec.js accordingly.

Strict Function Wrapping

Vitest 4 enforces that vi.fn() wraps actual functions or classes. Replaced arrow functions with function expressions:

// Before
window.FileReader = vi.fn(() => mockFileReader);
global.Blob = vi.fn((content, options) => mockBlob);

// After
window.FileReader = function() { return mockFileReader; };
global.Blob = vi.fn(function(content, options) { return mockBlob; });

Updated UploadFileComponent.spec.js and export.spec.js.

Setup File Handling

Renamed vite.config.setup.test.jsvite.config.setup.js to prevent vitest from treating it as a test file (new behavior in v4).

Original prompt

Can you migrate vitest to vitest 4 ?


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Oct 31, 2025
Copilot AI changed the title [WIP] Migrate Vitest to version 4 chore: Migrate to vitest 4 Oct 31, 2025
Copilot AI requested a review from theotime2005 October 31, 2025 18:26
Copilot finished work on behalf of theotime2005 October 31, 2025 18:26
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.

2 participants