Skip to content

refactor: replace jest with vitest#24

Merged
jonathannorris merged 7 commits intomainfrom
refactor/replace-jest-with-vitest
Apr 1, 2026
Merged

refactor: replace jest with vitest#24
jonathannorris merged 7 commits intomainfrom
refactor/replace-jest-with-vitest

Conversation

@jonathannorris
Copy link
Copy Markdown
Member

Summary

  • Replace Jest + ts-jest + ts-node with Vitest as the test runner
  • Remove jest.config.ts, add vitest.config.ts with equivalent alias, coverage, and glob config
  • Migrate jest.fn() / jest.spyOn() / jest.useFakeTimers() calls to vi.* equivalents in 3 test files
  • All 82 tests pass, 4 test files needed zero changes (vitest globals API is compatible)

Motivation

Vitest is faster, has native TypeScript/ESM support (no ts-jest/ts-node needed), and reduces the devDependency footprint. The test API is nearly identical to Jest with globals: true, so the migration is minimal.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request migrates the testing framework from Jest to Vitest, involving updates to dependencies, test scripts, and mock implementations across the codebase. Feedback includes identifying a missing @vitest/coverage-v8 dependency required for coverage reports, suggesting that coverage be explicitly enabled in the configuration to maintain parity with the previous setup, and recommending the use of expect.fail in test utilities to ensure clearer error messages when expected failures do not occur.

Comment thread package.json Outdated
Comment thread vitest.config.ts
Comment thread packages/js-ofrep-worker/test/invalid-config-test-utils.ts Outdated
Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
…kers

Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
…t outside try/catch

Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
@jonathannorris jonathannorris force-pushed the refactor/replace-jest-with-vitest branch from 10fb31f to d9be6a5 Compare April 1, 2026 19:09
Copy link
Copy Markdown

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 repository’s test tooling from Jest/ts-jest to Vitest, updating configuration and adapting the existing test suite (plus adding a worker-level integration test suite for the example Cloudflare Worker).

Changes:

  • Replaced jest.config.ts with a root vitest.config.ts (aliases, includes, coverage settings).
  • Updated test files to use vi.* APIs and adjusted TS test typings (Vitest globals).
  • Added a Vitest-based test setup for examples/js-worker and wired it into CI.

Reviewed changes

Copilot reviewed 13 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vitest.config.ts Adds root Vitest configuration (aliasing, test glob, coverage settings).
packages/js-ofrep-worker/tsconfig.spec.json Switches test typings from Jest to Vitest globals.
packages/js-ofrep-worker/test/r2Path.spec.ts Migrates mocks/spies/restores from jest.* to vi.*.
packages/js-ofrep-worker/test/ofrep-contract.spec.ts Migrates fake timers from jest.* to vi.*.
packages/js-ofrep-worker/test/invalid-config-test-utils.ts Reworks invalid-config assertion helper to avoid Jest-only fail() usage.
packages/js-ofrep-worker/package.json Updates package test script to run Vitest with the root config.
package.json Replaces root jest script/deps with vitest, adds test:worker script and coverage plugin dep.
jest.config.ts Removes Jest configuration.
examples/js-worker/vitest.config.mts Adds Vitest config using Cloudflare’s workers pool plugin.
examples/js-worker/test/worker.spec.ts Adds integration tests for the example worker’s endpoints and behavior.
examples/js-worker/test/tsconfig.json Adds test TS config for the example worker test directory.
examples/js-worker/test/env.d.ts Adds Cloudflare workers env typing augmentation for tests.
examples/js-worker/package.json Adds vitest run test script and Cloudflare pool dev dependency.
.github/workflows/ci.yml Runs the new example worker test suite in CI (npm run test:worker).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread vitest.config.ts
Comment thread examples/js-worker/package.json
@jonathannorris
Copy link
Copy Markdown
Member Author

/gemini review

Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request migrates the project's testing framework from Jest to Vitest. The changes include replacing Jest configurations and dependencies with Vitest equivalents, updating test scripts in various package.json files, and refactoring test utilities and specs to use Vitest's vi utility instead of jest. Additionally, a comprehensive test suite and specific Vitest configuration were added for the js-worker example. Feedback suggests improving consistency in workspace script naming and generalizing the test inclusion pattern in the root Vitest configuration to better support the monorepo structure.

Comment thread package.json Outdated
Comment thread vitest.config.ts Outdated
…attern

Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
@jonathannorris jonathannorris merged commit 89e5657 into main Apr 1, 2026
4 checks passed
@jonathannorris jonathannorris deleted the refactor/replace-jest-with-vitest branch April 1, 2026 19:41
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