INTER-2278: migrate from jest to vitest#250
Conversation
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
|
There was a problem hiding this comment.
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, updatingpackage.jsonscripts 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.
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.
Coverage report
Test suite run success76 tests passing in 22 suites. Report generated by 🧪jest coverage report action from 4b6e1bc Show full coverage report
|
…gration-a3158t # Conflicts: # .github/workflows/coverage-diff.yml
- 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
pnpm exec changesetto create a changeset. |
Migrates the test runner from jest (
ts-jest) to vitest. All tests pass;typecheck:sourceandlintstay green.jest.config.js→vitest.config.ts(node env, v8 coverage, samelcov/json-summary/textreporters).test→vitest run, addedtest:watch,test:coverage→vitest run --coverage. Droppedjest/ts-jest/@types/jest, addedvitest/@vitest/coverage-v8.jest.*mocks forvi.*and added a sharedmockFetchhelper viavi.stubGlobal.sealedResultssnapshot (content unchanged, only the key separator differs).Spec typechecking
Added
tests/tsconfig.json+ atypecheck:testsscript (wired intotest:dts) so spec files are typechecked separately. This avoids addingvitest/globalsto the roottypes, which breakstypecheck:sourceunderskipLibCheck: false.Adjusted two assertions
Vitest's
Errormatchers comparecause/structure, not just.message: the getEvent bad-JSON message now matches Node's actual output, and the all-invalid-keys case assertsUnsealAggregateError.errorscontents explicitly.Known CI failure
The first coverage-diff run can fail while this PR is compared against
main, because the workflow runstest:coverage:diffon both head and base andmaindoesn't have that script yet. Resolves once merged.No changeset
Test-only change, no version bump intended.