8000
  • test: migrate test suite from Jest to Vitest and improve assertions by J3m5 · Pull Request #151 · api-platform/api-doc-parser · GitHub
    [go: up one dir, main page]

    Skip to content

    test: migrate test suite from Jest to Vitest and improve assertions#151

    Merged
    J3m5 merged 3 commits intomainfrom
    vitest
    Jun 14, 2025
    Merged

    test: migrate test suite from Jest to Vitest and improve assertions#151
    J3m5 merged 3 commits intomainfrom
    vitest

    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, Copilot and dunglas June 6, 2025 16:22
    Copy link
    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

    @github-actions
    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 #217 for commit 13ed4b1 by the Vitest Coverage Report Action

    @J3m5 J3m5 force-pushed the typescript branch 2 times, most recently from 2733420 to 936896e Compare June 8, 2025 14:44
    @J3m5 J3m5 force-pushed the vitest branch 2 times, most recently from 1199fdb to 4435eb5 Compare June 8, 2025 14:46
    Base automatically changed from typescript to main June 14, 2025 17:31
    J3m5 added 3 commits June 14, 2025 19:51
    - 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
    @J3m5 J3m5 merged commit 827ea8a into main Jun 14, 2025
    1 check passed
    @J3m5 J3m5 deleted the vitest branch June 14, 2025 17:54
    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.

    3 participants

    0