Skip to content

refactor: migrate jest to vitest#1998

Merged
tatomyr merged 105 commits intov2from
refactor/vitest-migration
Mar 19, 2025
Merged

refactor: migrate jest to vitest#1998
tatomyr merged 105 commits intov2from
refactor/vitest-migration

Conversation

@tatomyr
Copy link
Collaborator

@tatomyr tatomyr commented Mar 10, 2025

What/Why/How?

Migrated from Jest to Vitest.

Here's a short guidance:

jest-to-vitest migration guide

jest.fn

  1. Replace jest.fn() with vi.fn()

jest.SpyInstance

  1. The file needs to include import { MockInstance } from 'vitest';
  2. Replace let spy: jest.SpyInstance; with let spy: MockInstance;

vi.spyOn

  1. When spying on path, needed to use this hack (doesn't work without shallow copying):
vi.mock('node:path', async () => {
  const actual = await vi.importActual('node:path');
  return { ...actual };
});

vi.mocked

  1. Replace this:
existsSync as jest.Mock<any, any>

with this:

vi.mocked(existsSync)

This passes the actual types down to the mocked function and helps maintain consistency.


Reference

Testing

Screenshots (optional)

Check yourself

  • Code changed? - Tested with redoc/reference-docs/workflows (internal)
  • All new/updated code is covered with tests
  • New package installed? - Tested in different environments (browser/node)

Security

  • Security impact of change has been considered
  • Code follows company security practices and guidelines

@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2025

⚠️ No Changeset found

Latest commit: 553a76e

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2025

Coverage report

Multiple errors occurred

 1 | Error: The process '/opt/hostedtoolcache/node/20.18.3/x64/bin/npm' failed with exit code 1
 2 | Coverage output file not found. (file "report.json" not found)
 3 | Getting code coverage data failed.
St.
Category Percentage Covered / Total
🟢 Statements 81.16% 6751/8318
🟡 Branches 69.63% 2784/3998
🟡 Functions 76.68% 1105/1441
🟢 Lines 81.57% 6434/7888

Test suite run success

1278 tests passing in 189 suites.

Report generated by 🧪jest coverage report action from 5a185d8

@andriimredocly andriimredocly force-pushed the refactor/vitest-migration branch from f644954 to 859ab90 Compare March 11, 2025 06:29
@andriimredocly andriimredocly force-pushed the refactor/vitest-migration branch from ade8a22 to fe5dae3 Compare March 11, 2025 08:23
@andriimredocly andriimredocly force-pushed the refactor/vitest-migration branch from fe5dae3 to 35d76cb Compare March 11, 2025 08:24
@tatomyr tatomyr changed the title refactor: migrate to vitest refactor: migrate jest to vitest Mar 19, 2025
@tatomyr tatomyr marked this pull request as ready for review March 19, 2025 10:55
@tatomyr tatomyr requested a review from a team as a code owner March 19, 2025 10:55
@tatomyr tatomyr merged commit f6ce716 into v2 Mar 19, 2025
11 of 37 checks passed
@tatomyr tatomyr deleted the refactor/vitest-migration branch March 19, 2025 10:57
@tatomyr tatomyr restored the refactor/vitest-migration branch March 19, 2025 10:57
tatomyr added a commit that referenced this pull request Mar 19, 2025
tatomyr added a commit that referenced this pull request Mar 20, 2025
andriimredocly pushed a commit that referenced this pull request Apr 1, 2025
andriimredocly pushed a commit that referenced this pull request Apr 9, 2025
tatomyr added a commit that referenced this pull request Apr 16, 2025
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