Skip to content

chore: migrate from Jest to Vitest and upgrade @actions/core to v3#409

Merged
bicstone merged 1 commit intomasterfrom
migrate-jest-to-vitest
Mar 3, 2026
Merged

chore: migrate from Jest to Vitest and upgrade @actions/core to v3#409
bicstone merged 1 commit intomasterfrom
migrate-jest-to-vitest

Conversation

@bicstone
Copy link
Owner

@bicstone bicstone commented Mar 3, 2026

Summary

  • 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 (-256 packages)
  • 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

Test plan

  • All 766 tests pass with pnpm test
  • ESLint passes with 0 errors (pnpm lint)
  • Build succeeds (pnpm run build)

🤖 Generated with Claude Code

- 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>
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

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.* to vi.* across the suite.
  • Updated tooling dependencies/scripts (remove Jest stack, add Vitest + Vitest ESLint plugin, upgrade @actions/core), and removed jest.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.

Comment on lines +69 to 73
let fetchSpy = vi.spyOn(global, "fetch");

beforeEach(() => {
fetchSpy = jest.spyOn(global, "fetch");
fetchSpy = vi.spyOn(global, "fetch");
fetchSpy.mockImplementation(
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Comment on lines +107 to 111
let fetchSpy = vi.spyOn(global, "fetch");

beforeEach(() => {
fetchSpy = jest.spyOn(global, "fetch");
fetchSpy = vi.spyOn(global, "fetch");
fetchSpy.mockImplementation(
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
@bicstone bicstone merged commit 0550d5b into master Mar 3, 2026
6 checks passed
@bicstone bicstone deleted the migrate-jest-to-vitest branch March 3, 2026 01:53
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