Skip to content

INTER-2278: migrate from jest to vitest#250

Merged
JuroUhlar merged 8 commits into
mainfrom
claude/jest-vitest-migration-a3158t
Jul 6, 2026
Merged

INTER-2278: migrate from jest to vitest#250
JuroUhlar merged 8 commits into
mainfrom
claude/jest-vitest-migration-a3158t

Conversation

@JuroUhlar

@JuroUhlar JuroUhlar commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Migrates the test runner from jest (ts-jest) to vitest. All tests pass; typecheck:source and lint stay green.

  • jest.config.jsvitest.config.ts (node env, v8 coverage, same lcov/json-summary/text reporters).
  • Scripts: testvitest run, added test:watch, test:coveragevitest run --coverage. Dropped jest/ts-jest/@types/jest, added vitest/@vitest/coverage-v8.
  • Swapped jest.* mocks for vi.* and added a shared mockFetch helper via vi.stubGlobal.
  • Regenerated the sealedResults snapshot (content unchanged, only the key separator differs).
  • Wired the reusable coverage-diff workflow to the Vitest JSON report.

Spec typechecking

Added tests/tsconfig.json + a typecheck:tests script (wired into test:dts) so spec files are typechecked separately. This avoids adding vitest/globals to the root types, which breaks typecheck:source under skipLibCheck: false.

Adjusted two assertions

Vitest's Error matchers compare cause/structure, not just .message: the getEvent bad-JSON message now matches Node's actual output, and the all-invalid-keys case asserts UnsealAggregateError.errors contents explicitly.

Known CI failure

The first coverage-diff run can fail while this PR is compared against main, because the workflow runs test:coverage:diff on both head and base and main doesn't have that script yet. Resolves once merged.

No changeset

Test-only change, no version bump intended.

Replace jest/ts-jest with vitest and @vitest/coverage-v8.

- Add vitest.config.ts (node env, globals, coverage via v8 with
  lcov, json-summary and text reporters) replacing jest.config.js
- Update test/test:coverage scripts to use vitest run
- Swap jest.* APIs in specs for vi.* (spyOn, fn, Mock type)
- Regenerate sealedResults snapshot in vitest format
- Fix getEvent bad-JSON assertion to match Node's actual SyntaxError
  message (jest's message-only toMatchObject masked the mismatch)
- Assert UnsealAggregateError by type since vitest toThrow does a
  full structural comparison rather than jest's message-only check
- Update contributing docs to reference vitest

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R9fEEUCxkFEnvjZApRNt33
@changeset-bot

changeset-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4b6e1bc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 runner from Jest (ts-jest) to Vitest, updating configuration, scripts, and test code to use vi APIs and Vitest snapshot format while keeping coverage outputs consistent with existing tooling.

Changes:

  • Replaced Jest/ts-jest tooling with Vitest + @vitest/coverage-v8, updating package.json scripts and lockfile.
  • Added vitest.config.ts (node env, globals, test include pattern, v8 coverage + reporters).
  • Updated tests and snapshots to use Vitest (vi.*, Vitest snapshot keys) and adjusted a few assertions for Vitest matcher semantics.

Reviewed changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vitest.config.ts Adds Vitest runner + coverage configuration.
package.json Switches test / test:coverage scripts to vitest run and updates devDependencies.
pnpm-lock.yaml Removes Jest-related deps and adds Vitest-related deps.
jest.config.js Removes the Jest configuration file.
contributing.md Updates contributor docs to reference Vitest and the snapshot update flag.
tests/unit-tests/serverApiClientTests.spec.ts Replaces Jest mocks with vi mocks.
tests/unit-tests/sealedResults.spec.ts Updates a throw assertion for Vitest behavior (and removes an unused import).
tests/unit-tests/snapshots/sealedResults.spec.ts.snap Regenerates snapshot header/key format for Vitest.
tests/mocked-responses-tests/updateEventTests.spec.ts Switches global fetch spying/mocking to Vitest APIs/types.
tests/mocked-responses-tests/searchEventsTests.spec.ts Switches global fetch spying/mocking to Vitest APIs/types.
tests/mocked-responses-tests/getEventTests.spec.ts Switches global fetch spying/mocking to Vitest APIs/types and adjusts an error message literal.
tests/mocked-responses-tests/deleteVisitorDataTests.spec.ts Switches global fetch spying/mocking to Vitest APIs/types.

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

Comment thread tests/unit-tests/sealedResults.spec.ts Outdated
JuroUhlar and others added 5 commits July 2, 2026 13:17
Add tests/tsconfig.json for test typechecking and drop globals mode.
Add test typecheck to CI, shared mockFetch helper, clearMocks, and test:watch.
Address review feedback: instead of only checking the thrown error is an
UnsealAggregateError, validate that it wraps one UnsealError per provided
decryption key and preserves the key association, without relying on
toThrow(errorInstance) structural equality.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R9fEEUCxkFEnvjZApRNt33
Resolved conflicts in package.json (kept vitest scripts, took main's tsx
generate.mts) and regenerated pnpm-lock.yaml.
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 100% 347/347
🟢 Branches 100% 113/113
🟢 Functions 100% 34/34
🟢 Lines 100% 347/347

Test suite run success

76 tests passing in 22 suites.

Report generated by 🧪jest coverage report action from 4b6e1bc

Show full coverage report
St File % Stmts % Branch % Funcs % Lines Uncovered Line #s
🟢 All files 100 100 100 100
🟢  src 100 100 100 100
🔴   ...edApiTypes.ts 0 0 0 0
🟢   index.ts 100 100 100 100
🟢   sealedResults.ts 100 100 100 100
🟢   ...rApiClient.ts 100 100 100 100
🟢   types.ts 100 100 100 100
🟢   urlUtils.ts 100 100 100 100
🟢   webhook.ts 100 100 100 100
🟢  src/errors 100 100 100 100
🟢   apiErrors.ts 100 100 100 100
🟢   ...orResponse.ts 100 100 100 100
🟢   toError.ts 100 100 100 100
🟢   unsealError.ts 100 100 100 100

…gration-a3158t

# Conflicts:
#	.github/workflows/coverage-diff.yml
@JuroUhlar JuroUhlar marked this pull request as ready for review July 2, 2026 18:45
- Assert cause with expect.any(SyntaxError) instead of the engine-specific
  V8 error message in the bad-JSON tests
- Restore semantic JSON.parse comparison for the updateEvent request body
- Stub global fetch via a vitest setup file instead of a side-effect import
- Consolidate mock cleanup into a single mockReset: true config option
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

⚠️ This PR doesn't contain any changesets. If there are user-facing changes, don't forget to run:

pnpm exec changeset

to create a changeset.

@JuroUhlar JuroUhlar changed the title test: migrate from jest to vitest INTER-2278: migrate from jest to vitest Jul 2, 2026
@JuroUhlar JuroUhlar merged commit 3a84f71 into main Jul 6, 2026
19 of 20 checks passed
@JuroUhlar JuroUhlar deleted the claude/jest-vitest-migration-a3158t branch July 6, 2026 13:50
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.

4 participants