Skip to content

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

Open
wants to merge 3 commits into
base: typescript
Choose a base branch
from

Conversation

J3m5
Copy link
Contributor

@J3m5 J3m5 commented Jun 6, 2025

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 as vi.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

  • migrate test files to Vitest and improve assertion patterns
    • 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

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

  • update tsconfig.json to remove Jest types

  • remove all Jest dependencies from package.json

  • add Vitest and msw dependencies

  • update test script in package.json to use Vitest

  • update pnpm-workspace.yaml onlyBuiltDependencies to include esbuild and msw

  • configure coverage

    • add config in vitest.config.ts
    • add test:coverage in package.json
    • remove unconventional scripts
    • configure CI to report coverage

    blocked by chore: modernize package.json and TypeScript configuration #150

@J3m5 J3m5 self-assigned this Jun 6, 2025
@J3m5 J3m5 requested review from alanpoulain, dunglas and Copilot June 6, 2025 16:22
Copy link

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

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

Copy link

github-actions bot commented Jun 6, 2025

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 71.96% (🎯 70%) 290 / 403
🟢 Statements 71.28% (🎯 70%) 293 / 411
🟢 Functions 71.42% (🎯 70%) 60 / 84
🟢 Branches 58.65% (🎯 58%) 200 / 341
File CoverageNo changed files found.
Generated in workflow #208 for commit 4435eb5 by the Vitest Coverage Report Action

J3m5 added 3 commits June 8, 2025 16:46
- 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
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.

1 participant