-
-
Notifications
You must be signed in to change notification settings - Fork 74
test: migrate test suite from Jest to Vitest and improve assertions #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: typescript
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR migrates the test suite from Jest to Vitest, refactoring test files to use Vitest’s assertion patterns and integrating msw for HTTP mocking. Key changes include updating configuration files, refactoring test files to async/await with try/catch blocks and assert usage, and removing deprecated Jest dependencies and configurations.
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
vitest.setup.ts | Sets up msw server with Vitest lifecycle hooks |
vitest.config.ts | Provides Vitest configuration including coverage settings |
src/utils/getResources.test.ts | Updates test file to use Vitest imports |
src/swagger/handleJson.test.ts | Migrates test assertions from Jest to Vitest using assert |
src/openapi3/handleJson.test.ts | Refactors file to Vitest, adding appropriate test imports |
src/hydra/fetchJsonLd.test.ts | Converts tests to async/await with msw usage and proper error handling |
pnpm-workspace.yaml | Updates built dependencies to include esbuild and msw |
package.json | Updates scripts and dependencies, removing Jest and adding Vitest |
jest.setup.ts & jest.config.ts | Removes obsolete Jest configuration files |
.github/workflows/ci.yml | Adjusts CI to run tests with Vitest coverage reporting |
Coverage Report
File CoverageNo changed files found. |
2733420
to
936896e
Compare
- Switch test runner assertions from Jest to Vitest - Add Vitest imports and remove Jest-specific ones - Replace jest-fetch-mock with msw for HTTP mocking - Use type narrowing with asserts instead of type assertions - Change string payloads to objects, use HttpResponse.json from msw - Refactor .then/.catch chains to async/await with try/catch where applicable - Add assertions for unexpected branches in try/catch blocks
- add config in vitest.config.ts - add test:coverage in package.json - remove unconventional scripts\- configure ci to report coverage
Benefits of Vitest over Jest
Below are the key benefits of using Vitest instead of Jest:
⚡ Faster startup & watch mode: Vitest reuses Vite’s esbuild pipeline and cache, yielding significantly quicker cold starts and only rerunning affected tests in watch mode.
🚀 Native TypeScript & ESM support: There’s no need for ts-jest or Babel—Vitest handles TypeScript and ES modules out of the box.
🧩 Jest-compatible API: Vitest mirrors Jest’s core API (
describe
,expect
,mock
asvi.mock
), making migration nearly drop-in with minimal code changes.🎁 Built-in coverage & simpler mocking: Coverage via C8 is integrated by default, and Vitest’s mocking layer reduces dependencies compared to Jest’s plugins.
Changelog
🚨 test
🧹 chore
remove Jest config and setup files (
jest.config.ts
,jest.setup.ts
)add Vitest configuration and setup files (
vitest.config.ts
,vitest.setup.ts
)update
.gitignore
to include Vitest coverage directoryupdate
tsconfig.json
to remove Jest typesremove all Jest dependencies from
package.json
add Vitest and msw dependencies
update test script in
package.json
to use Vitestupdate
pnpm-workspace.yaml
onlyBuiltDependencies to includeesbuild
andmsw
configure coverage
blocked by chore: modernize package.json and TypeScript configuration #150