chore: migrate from Jest to Vitest and upgrade @actions/core to v3#409
chore: migrate from Jest to Vitest and upgrade @actions/core to v3#409
Conversation
- Replace Jest with Vitest for native ESM support, resolving @actions/core v3 (ESM-only) compatibility - Remove jest, @types/jest, jest-mock, ts-jest, ts-node dependencies - Add @vitest/eslint-plugin with recommended rules for test files - Migrate jest.mock/spyOn/mocked to vi.mock/spyOn/mocked across all test files - Fix duplicate test title in pr/index.spec.ts detected by vitest/no-identical-title Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Migrates the test runner from Jest to Vitest to support ESM (needed for @actions/core v3), updates test mocks/spies accordingly, and refreshes linting/deps to match the new tooling.
Changes:
- Added Vitest configuration and global type declarations for Vitest globals.
- Migrated test mocking/spying from
jest.*tovi.*across the suite. - Updated tooling dependencies/scripts (remove Jest stack, add Vitest + Vitest ESLint plugin, upgrade
@actions/core), and removedjest.config.ts.
Reviewed changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| vitest.config.ts | Introduces Vitest runner configuration (globals, clearMocks, coverage include). |
| src/vitest.d.ts | Adds Vitest globals type reference for TypeScript. |
| src/push/postCommits.spec.ts | Converts jest.spyOn usage to vi.spyOn for fetch mocking. |
| src/push/index.spec.ts | Migrates module mocks and mocked() helper usage to vi.*. |
| src/pr/postComments.spec.ts | Converts jest.spyOn usage to vi.spyOn for fetch mocking. |
| src/pr/index.spec.ts | Migrates mocks to vi.* and adjusts one test title. |
| src/main/fetchEvent.spec.ts | Switches fs mocking to Vitest (vi.mock, vi.mocked) and node: import. |
| src/main.spec.ts | Migrates mocks to vi.* across main integration tests. |
| package.json | Switches test script to Vitest, removes Jest deps, adds Vitest deps, upgrades @actions/core. |
| jest.config.ts | Removes Jest configuration. |
| eslint.config.mjs | Adds Vitest ESLint plugin + recommended rules for *.spec.ts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let fetchSpy = vi.spyOn(global, "fetch"); | ||
|
|
||
| beforeEach(() => { | ||
| fetchSpy = jest.spyOn(global, "fetch"); | ||
| fetchSpy = vi.spyOn(global, "fetch"); | ||
| fetchSpy.mockImplementation( |
There was a problem hiding this comment.
This creates a fetch spy at module load time (let fetchSpy = vi.spyOn(...)) and then re-creates another spy in beforeEach without restoring the original. This leaves an extra spy attached to global.fetch for the lifetime of the test file and can make call counts / behavior harder to reason about. Prefer declaring fetchSpy without initializing it and create/restore the spy in beforeEach/afterEach (or use vi.restoreAllMocks() in teardown).
| let fetchSpy = vi.spyOn(global, "fetch"); | ||
|
|
||
| beforeEach(() => { | ||
| fetchSpy = jest.spyOn(global, "fetch"); | ||
| fetchSpy = vi.spyOn(global, "fetch"); | ||
| fetchSpy.mockImplementation( |
There was a problem hiding this comment.
Same pattern here: fetchSpy is initialized with vi.spyOn(...) at module scope and then replaced in beforeEach without restoring the initial spy. To avoid leaking an extra spy and to keep test setup deterministic, declare fetchSpy without initialization and set up/tear down the spy in beforeEach/afterEach (or call vi.restoreAllMocks() in teardown).
Summary
@actions/corev3 (ESM-only) compatibilityjest,@types/jest,jest-mock,ts-jest,ts-nodedependencies (-256 packages)@vitest/eslint-pluginwith recommended rules for test filesjest.mock/spyOn/mockedtovi.mock/spyOn/mockedacross all test filespr/index.spec.tsdetected byvitest/no-identical-titleTest plan
pnpm testpnpm lint)pnpm run build)🤖 Generated with Claude Code