Skip to content

test: migrate to vitest #274

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

test: migrate to vitest #274

wants to merge 1 commit into from

Conversation

JounQin
Copy link
Member

@JounQin JounQin commented Mar 30, 2025

There is still a blocker I don't know how to resolve:

vitest-dev/vitest#3987 (comment)

Summary by CodeRabbit

  • Chores

    • Updated the continuous integration workflow to build the project before testing.
    • Streamlined package configurations by removing legacy testing dependencies.
  • Tests

    • Transitioned the test suite to a new testing framework with updated scripts and configurations.
    • Enhanced module resolution, timeout settings, and snapshot handling for improved test reliability.
  • Refactor

    • Revised linting and overall configuration to support the new testing framework and modern development practices.

Copy link

changeset-bot bot commented Mar 30, 2025

⚠️ No Changeset found

Latest commit: fc3a5bb

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

@JounQin JounQin requested review from SukkaW and Copilot March 30, 2025 15:16
Copy link

coderabbitai bot commented Mar 30, 2025

Walkthrough

This pull request migrates the project’s testing framework from Jest to Vitest. The CI workflow now builds the project before running tests, and ESLint configurations are updated with the Vitest plugin and test file settings. Jest configuration files and related dependencies have been removed from package.json while new Vitest entries have been added. Numerous test files and fixtures have been updated to replace Jest-specific APIs with Vitest alternatives, including timeout settings, alias changes, and enhanced type annotations. A new Vitest configuration and snapshot serializer have also been introduced.

Changes

Files Change Summary
.github/workflows/ci.yml Updated “Build and Test” step command from yarn run-s test-compiled test to yarn run-s build test (build now precedes test execution)
eslint.config.js Added import for eslint-plugin-vitest and a new configuration block for test files; updated file pattern from jest.config.ts to vitest.config.ts
jest.config.ts
test/jest.serializer.cjs
Removed Jest-specific configuration and custom snapshot serializer files
package.json Replaced test script from Jest to Vitest; removed SWC/Jest-related dependencies and scripts; added vitest and eslint-plugin-vitest
patches/@swc-node+jest+1.8.13.patch Modified file extension matching regex and changed non-matching path return type from raw code to an object { code }
test/cli.spec.ts
test/node-resolver.spec.ts
test/rules/*.spec.ts
test/utils/*.spec.ts
test/utils/parse.spec.ts
test/utils/resolve.spec.ts
Updated tests to replace Jest methods (jest.fn(), jest.resetModules(), etc.) with Vitest equivalents (vi.fn(), vi.setConfig({ testTimeout: … }), etc.); adjusted timeouts and renamed duplicate describe blocks
test/fixtures/deep/cache-1-lib.js
test/fixtures/deep/cache-1-src.js
test/fixtures/deep/cache-1.js
test/fixtures/foo-bar-resolver-v1.js
test/fixtures/webpack.config.js
Introduced new re-export modules under the namespace b, removed redundant cache-1.js, added JSDoc type annotations, and updated Webpack alias from Jest to Vitest
test/global.d.ts Added reference directive for /// <reference types="vitest/globals" />
test/vitest.serializer.ts New file added to set up a Vitest snapshot serializer
vitest.config.ts New configuration file for Vitest defining test workspace settings, coverage reporters, and module aliasing

Sequence Diagram(s)

sequenceDiagram
    participant CI as CI Runner
    participant Build as Build Script
    participant Test as Vitest Runner

    CI->>Build: Execute build command (yarn run-s build)
    Build->>Test: Trigger test process (yarn run-s test)
    Test-->>CI: Return test results
Loading

Poem

Hi, I’m Bunny, hopping with delight,
Jest has hopped away in favor of Vitest light!
CI builds first, then tests take flight,
ESLint and modules all set up right.
With new configs and tests so neat,
I nibble on changes—oh, what a treat!
🐇✨ Hoppy coding to all in sight!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/rules/no-unused-modules.ts

Oops! Something went wrong! :(

ESLint: 9.23.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/lib/index.js' imported from /eslint.config.js
at finalizeResolution (node:internal/modules/esm/resolve:257:11)
at moduleResolve (node:internal/modules/esm/resolve:914:10)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)
(node:9841) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use node --trace-warnings ... to show where the warning was created)

eslint.config.js

Oops! Something went wrong! :(

ESLint: 9.23.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/lib/index.js' imported from /eslint.config.js
at finalizeResolution (node:internal/modules/esm/resolve:257:11)
at moduleResolve (node:internal/modules/esm/resolve:914:10)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)
(node:9840) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use node --trace-warnings ... to show where the warning was created)

test/cli.spec.ts

Oops! Something went wrong! :(

ESLint: 9.23.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/lib/index.js' imported from /eslint.config.js
at finalizeResolution (node:internal/modules/esm/resolve:257:11)
at moduleResolve (node:internal/modules/esm/resolve:914:10)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)
(node:9847) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use node --trace-warnings ... to show where the warning was created)

  • 14 others
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

socket-security bot commented Mar 30, 2025

New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@aashutoshrathi/[email protected] None 0 10.9 kB aashutoshrathi
npm/@eslint/[email protected]0.2.0 None 0 55.1 kB eslintbot
npm/@eslint/[email protected]3.3.1 None 0 691 kB eslintbot
npm/@humanwhocodes/[email protected] None 0 55.6 kB nzakas
npm/@jest/[email protected] None 0 6.07 kB simenb
npm/@nolyfill/[email protected] None 0 5.58 kB sukkaw
npm/@one-ini/[email protected] filesystem 0 111 kB hildjj
npm/@sinclair/[email protected] None 0 442 kB sinclair
npm/@total-typescript/[email protected] None 0 183 kB mpocock
npm/@types/[email protected] None 0 196 kB types
npm/@types/[email protected] None 0 3.57 kB types
npm/@types/[email protected] None 0 6.62 kB types
npm/@types/[email protected] None 0 5.3 kB types
npm/@typescript-eslint/[email protected] None +1 53.6 kB
npm/@typescript-eslint/[email protected] None 0 14.5 kB jameshenry
npm/@typescript-eslint/[email protected] None 0 137 kB jameshenry
npm/@typescript-eslint/[email protected] None 0 96.2 kB jameshenry
npm/@unts/[email protected] environment, filesystem +1 448 kB jounqin
npm/@yarnpkg/[email protected] environment, eval, filesystem 0 280 kB arcanis
npm/[email protected] None 0 35.9 kB blakeembrey
npm/[email protected] None 0 43.2 kB hirokiosame
npm/[email protected] None 0 8.54 kB samverschueren
npm/[email protected] None 0 46 kB simenb
npm/[email protected] None 0 37.8 kB hildjj
npm/[email protected] None 0 41 kB sokra
npm/[email protected] filesystem 0 54.1 kB ota-meshi
npm/[email protected] None 0 58.4 kB jounqin
npm/[email protected] None 0 159 kB bmishkin
npm/[email protected] None 0 54.3 kB alexgorbatchev, bradzacher, jounqin
npm/[email protected] filesystem Transitive: environment +2 138 kB ljharb
npm/[email protected] None 0 86.5 kB johno, remcohaszing, timneutkens, ...1 more
npm/[email protected] None 0 409 kB eslint-community-bot
npm/[email protected] filesystem 0 172 kB eslint-community-bot
npm/[email protected] None 0 14.9 kB abandeali
npm/[email protected] None 0 81.9 kB johno, remcohaszing, timneutkens, ...1 more
npm/[email protected] filesystem 0 467 kB weiran.zsd
npm/[email protected] None +1 112 kB jounqin
npm/[email protected] None 0 747 kB fisker, sindresorhus
npm/[email protected] None 0 392 kB veritem
npm/[email protected] None 0 288 kB ota-meshi
npm/[email protected]8.56.0 filesystem +1 3.04 MB eslintbot
npm/[email protected]9.23.0 None +2 2.94 MB eslintbot
npm/[email protected] environment 0 80.1 kB ehmicky
npm/[email protected] filesystem 0 5.27 kB jsdnxx
npm/[email protected] filesystem 0 16.7 kB bmishkin
npm/[email protected]3.3.1 None 0 40.3 kB webreflection
npm/[email protected] None 0 812 kB mattpauldavies
npm/[email protected] None 0 271 kB hermes-team
npm/[email protected] None 0 364 kB hermes-team
npm/[email protected] None 0 1.25 MB hermes-team
npm/[email protected] None 0 4.74 kB sindresorhus
npm/[email protected] None 0 14.9 kB phated
npm/[email protected] None 0 3.86 kB sindresorhus
npm/[email protected] None 0 21.9 kB sunset_techuila
npm/[email protected] filesystem 0 3.01 kB sindresorhus
npm/[email protected] None 0 4.12 kB sindresorhus
npm/[email protected] environment, filesystem 0 3.76 kB sindresorhus
npm/[email protected] None 0 78.5 kB simenb
npm/[email protected] None 0 3.79 kB simenb
npm/[email protected] None 0 26.1 kB kriszyp
npm/[email protected] None 0 10.4 kB manidlou
npm/[email protected] filesystem 0 18 kB antonk52
npm/[email protected] None 0 0 B
npm/[email protected] environment 0 276 kB cenk1cenk2
npm/[email protected] None 0 1.41 MB bnjmnt4n
npm/[email protected] None 0 684 kB streamich
npm/[email protected] None 0 24.8 kB sokra
npm/[email protected] environment, filesystem +1 658 kB bret
npm/[email protected] environment, filesystem, shell 0 41.9 kB sindresorhus
npm/[email protected] eval 0 78.7 kB sooniter
npm/[email protected] None 0 9.58 kB bpscott
npm/[email protected] None 0 60.7 kB simenb
npm/[email protected]0.2.10 None 0 23.9 kB antfu, sxzz
npm/[email protected] environment 0 24 kB gnoff
npm/[email protected] None 0 6.28 kB sindresorhus
npm/[email protected] None 0 290 kB phryneas
npm/[email protected] None 0 314 kB dmitrysoshnikov
npm/[email protected] None 0 14.7 kB wooorm
npm/[email protected] filesystem 0 13.6 kB toplenboren
npm/[email protected] None 0 3.64 kB sindresorhus
npm/[email protected] None 0 14.9 kB sokra
npm/[email protected] None 0 11 kB substack
npm/[email protected] environment, filesystem, unsafe 0 757 kB blakeembrey
npm/[email protected] None 0 81.6 kB jameshenry
npm/[email protected] None 0 22.9 MB typescript-bot
npm/[email protected] None 0 0 B
npm/[email protected] None 0 507 kB aeschli
npm/[email protected] None 0 91.7 kB ota-meshi
npm/[email protected] None 0 65.1 kB churpeau
npm/[email protected] None 0 699 kB colinhacks

🚮 Removed packages: npm/@eslint/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@node-rs/[email protected], npm/@swc-node/[email protected], npm/@swc-node/[email protected], npm/@swc-node/[email protected], npm/@types/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected]

View full report↗︎

Copy link

codesandbox-ci bot commented Mar 30, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

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. Key changes include:

  • Replacing Jest APIs (e.g., jest.fn, jest.setTimeout, jest.unstable_mockModule) with their Vitest equivalents (e.g., vi.fn, vi.setConfig, vi.doMock, vi.resetModules).
  • Updating file imports and test file configurations to include the new srcDir where needed.
  • Removing Jest configuration files and updating ESLint settings to recognize Vitest.

Reviewed Changes

Copilot reviewed 23 out of 27 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/utils/export-map.spec.ts Updated test logic to use Vitest APIs and adjusted file paths using srcDir.
test/rules/no-unused-modules.spec.ts Replaced Jest usage with Vitest and updated test naming for new file behavior.
test/rules/no-extraneous-dependencies.spec.ts Updated dependency imports and error messages from Jest to Vitest.
test/node-resolver.spec.ts Updated module resolution tests to reflect the migration to Vitest.
test/jest.serializer.cjs Removed unused Jest snapshot serializer.
test/fixtures/webpack.config.js Changed alias from Jest to Vitest for dependency testing.
test/fixtures/foo-bar-resolver-v1.js Added JSDoc comments for clarity.
test/fixtures/deep/cache-1.js, cache-1-src.js, cache-1-lib.js Adjusted cache files to support new srcDir usages.
test/cli.spec.ts Added a Vitest-specific ESLint-disable comment where needed.
jest.config.ts Removed Jest configuration in favor of Vitest.
eslint.config.js Enhanced configuration to include Vitest plugin settings for test files.
Files not reviewed (4)
  • package.json: Language not supported
  • patches/@swc-node+jest+1.8.13.patch: Language not supported
  • test/snapshots/fixtures.spec.ts.snap: Language not supported
  • test/snapshots/node-resolver.spec.ts.snap: Language not supported
Comments suppressed due to low confidence (3)

eslint.config.js:158

  • Ensure that 'vitest.config.ts' exists and is correctly configured, or update the ignore patterns if the Vitest configuration is handled differently.
'vitest.config.ts',

jest.config.ts:1

  • Review references to 'jest.config.ts' in CI/CD pipelines or scripts to ensure that its removal does not disrupt any workflows.
Entire file removed

test/rules/no-unused-modules.spec.ts:763

  • [nitpick] Consider using more descriptive test names instead of incremental identifiers (e.g., 'new file 0, 1, ...') to clearly indicate the differences between test cases.
describe('test behavior for new file 0', () => {

Copy link

pkg-pr-new bot commented Mar 30, 2025

Open in Stackblitz

npm i https://pkg.pr.new/eslint-plugin-import-x@274

commit: fc3a5bb

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
test/fixtures/foo-bar-resolver-v1.js (1)

3-8: Good addition of JSDoc comments for better type documentation.

Adding JSDoc type annotations improves code readability and enhances IDE type support. This is a positive change that aligns with the project's migration to a more type-aware environment.

However, the @returns tag doesn't specify the return type. Consider adding the return type information for completeness:

 /**
  * @param {string} modulePath
  * @param {string} sourceFile
  * @param {unknown} config
- * @returns
+ * @returns {string|undefined}
  */
test/rules/no-extraneous-dependencies.spec.ts (1)

1-589:

❓ Verification inconclusive

Consider adding a global timeout configuration for test suite.

The previous test configuration might have included a jest.setTimeout(10e3) call that needs to be replaced with its Vitest equivalent. This ensures tests have sufficient time to complete.

+ import { vi } from 'vitest';
+
+ // Set a longer timeout for all tests in this file
+ vi.setConfig({ testTimeout: 10000 });
+
  import fs from 'node:fs'
  import { createRequire } from 'node:module'

🏁 Script executed:

#!/bin/bash
# Check if there was a Jest timeout configuration in the previous version
git show HEAD~1:test/rules/no-extraneous-dependencies.spec.ts | grep -n "setTimeout"

Length of output: 84


Global Vitest Timeout Configuration Required

It seems that the previous commit did not include any timeout configuration (i.e. no jest.setTimeout(10e3) call was found). To ensure that tests have sufficient time to complete under Vitest, please add a global timeout configuration at the top of the file. For example:

+ import { vi } from 'vitest';
+ 
+ // Set a longer timeout for all tests in this file
+ vi.setConfig({ testTimeout: 10000 });
+
  import fs from 'node:fs'
  import { createRequire } from 'node:module'

Please verify manually that this change aligns with your intended test configuration setups.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6cba8eb and fc3a5bb.

⛔ Files ignored due to path filters (3)
  • test/__snapshots__/fixtures.spec.ts.snap is excluded by !**/*.snap
  • test/__snapshots__/node-resolver.spec.ts.snap is excluded by !**/*.snap
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (23)
  • .github/workflows/ci.yml (1 hunks)
  • eslint.config.js (3 hunks)
  • jest.config.ts (0 hunks)
  • package.json (3 hunks)
  • patches/@swc-node+jest+1.8.13.patch (0 hunks)
  • src/rules/no-unused-modules.ts (2 hunks)
  • test/cli.spec.ts (1 hunks)
  • test/fixtures/deep/cache-1-lib.js (1 hunks)
  • test/fixtures/deep/cache-1-src.js (1 hunks)
  • test/fixtures/deep/cache-1.js (0 hunks)
  • test/fixtures/foo-bar-resolver-v1.js (1 hunks)
  • test/fixtures/webpack.config.js (1 hunks)
  • test/global.d.ts (1 hunks)
  • test/jest.serializer.cjs (0 hunks)
  • test/node-resolver.spec.ts (1 hunks)
  • test/rules/no-extraneous-dependencies.spec.ts (3 hunks)
  • test/rules/no-unused-modules.spec.ts (8 hunks)
  • test/utils/export-map.spec.ts (8 hunks)
  • test/utils/hash.spec.ts (1 hunks)
  • test/utils/parse.spec.ts (11 hunks)
  • test/utils/resolve.spec.ts (4 hunks)
  • test/vitest.serializer.ts (1 hunks)
  • vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (4)
  • test/jest.serializer.cjs
  • test/fixtures/deep/cache-1.js
  • jest.config.ts
  • patches/@swc-node+jest+1.8.13.patch
🧰 Additional context used
🧬 Code Definitions (1)
test/utils/resolve.spec.ts (1)
test/utils.ts (1)
  • srcDir (236-236)
🪛 GitHub Actions: CI
test/utils/parse.spec.ts

[error] 4-4: RollupError: Parse failure: Expected ',', got ':'

🔇 Additional comments (41)
test/global.d.ts (1)

1-1: LGTM: Correctly added Vitest types reference

This change properly sets up TypeScript to recognize Vitest's global types, which is essential for the testing framework migration.

eslint.config.js (3)

12-12: LGTM: Properly imported Vitest ESLint plugin

The import follows the same pattern as other plugin imports and correctly brings in the Vitest linting rules.


112-115: LGTM: Added appropriate ESLint configuration for Vitest tests

The configuration correctly targets test files and extends the recommended Vitest ruleset, which will enforce Vitest best practices in test files.


158-158: LGTM: Updated file pattern for Vitest config

Correctly updated the file pattern to reference the new Vitest configuration file instead of the previous Jest configuration.

src/rules/no-unused-modules.ts (2)

10-10: Minor style improvement in comment formatting

Removed unnecessary space before comma in the ESLint directive comment, improving style consistency.


25-25: Minor style improvement in comment formatting

Similarly removed unnecessary space before comma in this ESLint directive comment for consistent style.

package.json (2)

64-64: LGTM: Updated test script for Vitest

The test script has been properly updated to use Vitest instead of Jest. The command includes appropriate flags to suppress unnecessary warnings.


137-137:

❓ Verification inconclusive

LGTM: Added required Vitest dependencies

Both Vitest and its ESLint plugin have been added as dev dependencies with recent versions.

Given that the PR mentions a blocker related to Vitest, let's verify if there are any known issues with the specific versions:

Also applies to: 156-156


🏁 Script executed:

#!/bin/bash
# Check for any relevant issues with the Vitest versions used

# Get the specific issue mentioned in the PR
echo "Checking the specific Vitest issue mentioned in the PR:"
curl -s "https://api.github.com/repos/vitest-dev/vitest/issues/3987" | jq -r '.title, .state, .html_url'

# Check for any open issues related to the version 3.0.9
echo -e "\nChecking for issues related to Vitest 3.0.9:"
curl -s "https://api.github.com/search/issues?q=repo:vitest-dev/vitest+is:issue+is:open+3.0.9+in:title,body" | jq -r '.items[] | "\(.title) - \(.html_url)"'

Length of output: 1422


Vitest Dependencies Verified – Proceed with Caution

The added Vitest and ESLint plugin dependencies in package.json (lines 137 and 156) are correctly using recent versions. Our verification confirms that the specific issue reported in the PR (fails to run/parse .cts source files, issue #3987) remains open. Additionally, several open issues affecting Vitest 3.0.9 were found (e.g., errors with server.deps.inline, vi.mock behavior, and others).

  • The dependency updates are correct and complete.
  • Known Issues:

While these issues are upstream and do not block this PR, please continue to monitor their potential impact on our test suite and adjust if necessary.

vitest.config.ts (3)

1-52: Well-structured Vitest configuration

The configuration is well-organized with a reusable function for workspace setup and proper coverage configuration. The alias mappings are comprehensive and will ensure correct module resolution during testing for both compiled and source code.


6-41: Good abstraction with getTestWorkspace

Creating a function to handle both compiled and source test configurations reduces duplication and makes the configuration more maintainable. The function is well-typed and properly handles the differences between compiled and source code testing environments.


43-52: Comprehensive test configuration

The test configuration properly sets up Istanbul coverage reporting with appropriate reporters and includes both source and compiled workspaces. The setupFiles points to the serializer which is also part of this PR.

test/fixtures/deep/cache-1-src.js (1)

1-2: Simple and clear module re-export

This fixture correctly imports and re-exports the module for testing purposes.

test/fixtures/deep/cache-1-lib.js (1)

1-2: Simple and clear module re-export

This fixture correctly imports and re-exports the module for testing compiled code.

test/vitest.serializer.ts (1)

1-3: Snapshot serializer configuration

The serializer is properly set up using the Vitest-compatible expect global. This is the correct approach for migrating from Jest to Vitest as it maintains compatibility with existing snapshot tests.

test/utils/hash.spec.ts (1)

1-1: Appropriate rule disabling for Vitest migration

The ESLint rule vitest/expect-expect is correctly disabled for this file since it uses a custom expectHash function that internally uses expect statements, which may not be directly recognized by the linter.

test/fixtures/webpack.config.js (1)

6-6: Correctly updated alias for testing framework

The alias has been properly updated from Jest to Vitest as part of the migration, maintaining the same functionality for no-extraneous-dependencies tests.

.github/workflows/ci.yml (1)

55-55: Build command properly updated for Vitest workflow

The CI workflow has been correctly updated to run build before test instead of test-compiled before test. This change aligns with the Vitest migration and ensures that compiled artifacts are available before running tests.

test/node-resolver.spec.ts (1)

50-50:

❓ Verification inconclusive

Test case properly updated for Vitest

The test case has been correctly updated to check for resolution of vitest instead of jest, consistent with the migration to Vitest.

Ensure that snapshots have been updated elsewhere in the PR, as changing this expectation from 'jest' to 'vitest' will affect the snapshot test results.


🏁 Script executed:

#!/bin/bash
# Check if snapshot files have been updated in this PR
git diff --name-only HEAD~1 | grep -E '\.snap$'

Length of output: 49


Test case updated for Vitest but snapshot updates need verification

  • The test now correctly checks for the resolution of vitest instead of jest, which aligns with the migration.
  • However, the snapshot diff command (git diff --name-only HEAD~1 | grep -E '\.snap$') did not return any results—this raises uncertainty about whether the snapshot files were updated accordingly.

Please verify manually that the necessary snapshot updates have been made in this PR to ensure consistency with the test change.

test/cli.spec.ts (3)

8-8: LGTM! Improved formatting for ESLint directive.

The change removes unnecessary spaces before the comment dash for better consistency.


13-13: LGTM! Improved formatting for ESLint directive.

The change removes unnecessary spaces before the comment dash for better consistency.


20-20: LGTM! Appropriate Vitest ESLint directive added.

Adding the vitest/expect-expect rule suppression is appropriate for this test since it's validating that no error is thrown rather than explicitly asserting on a result.

test/utils/parse.spec.ts (5)

25-27: LGTM! Updated resolver paths with .cjs extension.

The paths now explicitly include the CommonJS file extension, which is more accurate and helps with module resolution.


52-52: LGTM! Updated mock functions from Jest to Vitest.

These changes correctly replace Jest's mocking functions with their Vitest equivalents:

  • jest.fn()vi.fn()
  • Type annotations for mock functions are properly maintained

This is a key part of the migration to Vitest.

Also applies to: 94-96, 98-98, 147-147, 291-291, 313-313, 319-319, 349-349, 369-369


84-84: LGTM! Updated module reset function from Jest to Vitest.

The module reset function has been updated from Jest to Vitest:

  • jest.resetModules()vi.resetModules()

This ensures test isolation by clearing the module cache between tests.

Also applies to: 139-140


231-231: LGTM! Updated test description to match correct functionality.

The test description has been updated to reference parseForESLint instead of parse, which more accurately reflects the function being tested.


4-4:

❓ Verification inconclusive

Fix RollupError in TypeScript import.

There's a pipeline failure indicating a parse error on this line.

This is likely related to the TypeScript type import syntax. Since this file isn't shown in the diff, please check if there's a syntax error in an import statement, possibly related to how types are imported.


🏁 Script executed:

RollupError: Parse failure: Expected ',', got ':'

Length of output: 150


🏁 Script executed:

#!/bin/bash
# Check first few lines of the file to look for import syntax errors
head -n 10 test/utils/parse.spec.ts

Length of output: 310


Action: Review Rollup Configuration for Type-Only Imports

The file test/utils/parse.spec.ts shows a valid TypeScript type import:

import type { TSESLint } from '@typescript-eslint/utils'

However, the Rollup error

Parse failure: Expected ',', got ':'

indicates that Rollup is misinterpreting the import type syntax. This is typically because the bundler isn’t configured to handle TypeScript’s type-only imports.

Recommendations:

  • Verify Rollup Plugins:
    Ensure that your Rollup configuration includes an appropriate TypeScript plugin (e.g., @rollup/plugin-typescript or a compatible alternative) that properly handles type-only imports.

  • Exclude Test Files:
    If these tests aren’t meant to be bundled, consider updating the Rollup config to exclude files under test/ (or similar patterns) from the build process.

  • Double Check Build Pipeline:
    Confirm that the error arises during bundling and not due to any local syntax issue. The file itself appears syntactically correct, so the issue likely lies with how Rollup is processing it.

Please review your Rollup build configuration to ensure it properly handles TypeScript syntax or excludes test files as necessary.

🧰 Tools
🪛 GitHub Actions: CI

[error] 4-4: RollupError: Parse failure: Expected ',', got ':'

test/rules/no-extraneous-dependencies.spec.ts (2)

96-96: LGTM! Updated import statements from Jest to Vitest.

Import statements in test cases have been correctly updated to use vitest instead of jest, ensuring the tests validate the correct dependency configuration.

Also applies to: 101-101, 106-106, 312-312, 318-318, 324-324, 330-330, 418-418


315-315: LGTM! Updated error messages to reference Vitest.

The expected error messages have been updated to check for vitest instead of jest in dependency validation failures, maintaining test accuracy.

Also applies to: 321-321, 327-327, 333-333, 422-422

test/utils/resolve.spec.ts (3)

9-9: Import updated to include srcDir

The import statement has been updated to include srcDir, which is now used to dynamically construct file paths for tests.


493-493: File paths now use dynamic srcDir variable

This change makes the test more flexible by dynamically constructing file paths based on the source directory, which allows tests to work correctly whether running against compiled code ('lib') or source code ('src').


534-534: Jest timeout replaced with Vitest configuration

The timeout configuration has been updated from Jest to Vitest as part of the migration between testing frameworks. This pattern is consistent with Vitest's API for configuring test timeouts.

Also applies to: 547-547

test/utils/export-map.spec.ts (6)

6-6: Import updated to include srcDir

The import statement now includes srcDir, which is used for dynamic file path construction in the tests.


145-152: Simplified file modification test with synchronous approach

The test for checking cached copies after modification has been changed from using a callback pattern to a synchronous approach with fs.utimesSync. This simplifies the control flow while maintaining the same test functionality.


308-309: Dynamic file path construction with srcDir

File paths are now constructed dynamically using the srcDir variable, which makes the tests adaptable to different environments (compiled or source code).

Also applies to: 318-319


329-329: Consistent synchronous file operations

File operations have been updated to use synchronous versions when appropriate, maintaining a consistent approach throughout the test file.

Also applies to: 342-342


400-400: Jest timeout replaced with Vitest configuration

The timeout configuration has been updated to use Vitest's API instead of Jest's.


402-407: Mocking framework updated from Jest to Vitest

All mocking functionality has been migrated from Jest to Vitest, including function mocks, module mocks, module resets, and spying.

Also applies to: 444-444, 489-489

test/rules/no-unused-modules.spec.ts (4)

7-8: Updated import comment for clarity

The eslint-disable comment has been updated for the eslint8UnsupportedApi import to clarify the reason for the rule exclusion.


285-285: Jest timeout replaced with Vitest configuration

The timeout configuration has been updated from Jest to Vitest, maintaining consistent timeout settings during the framework migration.


685-690: Simplified commented-out test code

The commented-out test code has been simplified while still preserving the original intention of the commented section.


763-763: Improved describe block structure

Describe blocks have been renamed and restructured to improve clarity and avoid potential conflicts in the test suite organization.

Also applies to: 879-879, 921-921, 952-952, 1010-1010

@SukkaW
Copy link
Collaborator

SukkaW commented Mar 31, 2025

IMHO, let's keep jest for now? Let's revisit vitest later after we replace cts with mts as much as possible.

@JounQin
Copy link
Member Author

JounQin commented Mar 31, 2025

IMHO, let's keep jest for now? Let's revisit vitest later after we replace cts with mts as much as possible.

Sure!

@JounQin JounQin marked this pull request as draft March 31, 2025 03:08
Copy link

sonarqubecloud bot commented Apr 1, 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.

2 participants