Skip to content

test: split e2e and unit cases #421

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

Merged
merged 1 commit into from
Mar 29, 2025
Merged

test: split e2e and unit cases #421

merged 1 commit into from
Mar 29, 2025

Conversation

JounQin
Copy link
Collaborator

@JounQin JounQin commented Mar 29, 2025

close #412

Summary by CodeRabbit

  • New Features

    • Introduced a new TypeScript configuration file to enhance project structure.
    • Enabled automatic import of testing utilities for a streamlined development experience.
    • Added a new ESLint configuration for specific directories to customize linting rules.
    • Added a new TypeScript configuration file for staged files to refine compilation settings.
    • Established a new end-to-end test suite for validating workflows and ESLint execution.
  • Tests

    • Expanded coverage by adding unit tests focused on module resolution and lint verification.
  • Chores

    • Updated environment settings and dependency scripts.
    • Refined configurations for linting, formatting, and TypeScript compilation.
    • Adjusted file ignore patterns for more precise formatting and dependency handling.
    • Removed obsolete ESLint configurations and settings.
    • Updated ESLint rules to enhance import management and organization.

Copy link

changeset-bot bot commented Mar 29, 2025

⚠️ No Changeset found

Latest commit: 40fd25d

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

Copy link

coderabbitai bot commented Mar 29, 2025

Walkthrough

This pull request updates various configurations and test setups. It removes a NODE_OPTIONS setting from the environment file, adjusts linting configurations and ignore patterns, and updates TypeScript settings including new tsconfig files. New global declarations for testing utilities and additional test suites for end-to-end and unit testing have been added. Package scripts and dependencies were also revised, and several obsolete ESLint configuration files were removed. Overall, the changes realign configurations and improve testing infrastructure without altering core application logic.

Changes

Files / Group Change Summary
Environment & Build Configs
(.env.yarn, tsconfig.base.json, tsconfig.json, tsconfig.staged.json, tests/.../absoluteAlias/tsconfig.json, package.json, tests/.../package.json)
Removed NODE_OPTIONS setting; updated TypeScript configurations (e.g., outDir, extends, new staged config); modified package.json scripts, module type, and added new dev dependencies.
Linting Configurations
(.lintstagedrc.js, .prettierignore, eslint.config.js, tests/.../importXResolverV3/eslint.config.js, tests/.../withJsExtension/.eslintrc.cjs, tests/.../withQuerystring/.eslintrc.cjs, tests/.../withoutPaths/.eslintrc.cjs, tests/.../withJsconfig/.eslintrc.cjs, tests/.../nestedPackageJson/.eslintrc.cjs)
Modified export structure and ignore patterns; updated ESLint config imports from “recommended” to “base”; added new ESLint configs and removed obsolete ones.
Test Suites & Global Declarations
(auto-imports.d.ts, tests/e2e/e2e.spec.ts, tests/unit/unit.spec.ts, tests/pnp/pnp.spec.ts)
Introduced a new global declaration file for Vitest; added new e2e and unit test suites; removed an outdated PnP test file.
Test File Import Adjustments
(tests/e2e/withJsExtension/index.ts, tests/e2e/withJsExtension/test.cjs)
Updated import paths from JSX to JS, added new module imports, and refined path resolutions.
Vitest Plugin Update
(vitest.config.ts)
Added an auto-import plugin configuration to automatically import the Vitest module.

Sequence Diagram(s)

sequenceDiagram
    participant TR as Test Runner
    participant DS as Directory Scanner
    participant YE as Yarn Executor
    participant ESL as ESLint Executor
    participant SM as Snapshot Matcher

    TR->>DS: Scan e2e directories (skip "__snapshots__")
    DS-->>TR: Return valid test directories
    TR->>YE: Check for yarn.lock & execute "yarn --immutable"
    TR->>ESL: Run ESLint (with custom config if present)
    ESL-->>TR: Return ESLint results
    TR->>SM: Compare results with stored snapshots
Loading

Assessment against linked issues

Objective Addressed Explanation
Add unit tests along with e2e tests (#412)

Poem

I'm a rabbit with a hop so light,
Celebrating changes deep into the night.
Configs refined and tests in flight,
Lemurs and lines align just right.
With a twitch of my nose, I say hooray—
Code improvements brighten my day!
🐇💻

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.

.lintstagedrc.js

Oops! Something went wrong! :(

ESLint: 9.23.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.js
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
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)

auto-imports.d.ts

Oops! Something went wrong! :(

ESLint: 9.23.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.js
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
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)

eslint.config.js

Oops! Something went wrong! :(

ESLint: 9.23.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.js
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
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)

  • 9 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

codesandbox-ci bot commented Mar 29, 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

socket-security bot commented Mar 29, 2025

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

Package New capabilities Transitives Size Publisher

🚮 Removed packages: npm/[email protected], npm/[email protected]

View full report↗︎

Copy link

pkg-pr-new bot commented Mar 29, 2025

Open in Stackblitz

npm i https://pkg.pr.new/eslint-import-resolver-typescript@421

commit: 53ddbf7

Copy link
Contributor

github-actions bot commented Mar 29, 2025

size-limit report 📦

Path Size
lib/index.js 1.35 KB (0%)

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: 1

🧹 Nitpick comments (4)
tests/unit/unit.spec.ts (1)

9-33: Consider improving test robustness.

While the test correctly validates PnP functionality, there are a few improvements to consider:

  1. The test depends on external yarn install which might cause flakiness in CI environments
  2. Consider adding cleanup after the test to remove any temporary files
  3. The snapshots contain absolute paths which might cause issues across different environments
 it('should work with pnp', async () => {
+  // Setup temporary directory or cleanup previous runs
   await exec('yarn', ['install'], {
     nodeOptions: {
       cwd: pnpDir,
     },
   })

   const resolver = createTypeScriptImportResolver()

   const testfile = path.resolve(pnpDir, '__test__.js')

   expect(resolver.resolve('pnpapi', testfile)).toMatchInlineSnapshot(`
       {
         "found": true,
-        "path": "<ROOT>/tests/unit/pnp/.pnp.cjs",
+        "path": ${expect.stringMatching(/.*\/\.pnp\.cjs$/)}",
       }
     `)

   expect(resolver.resolve('lodash.zip', testfile)).toMatchInlineSnapshot(`
       {
         "found": true,
-        "path": "<ROOT>/tests/unit/pnp/.yarn/cache/lodash.zip-npm-4.2.0-5299417ec8-cb06530d81.zip/node_modules/lodash.zip/index.js",
+        "path": ${expect.stringMatching(/.*\/lodash\.zip\/index\.js$/)}",
       }
     `)
+  
+  // Add cleanup if necessary
 }, 10_000)
tests/e2e/importXResolverV3/eslint.config.js (1)

18-35: Improve Node.js version check readability.

The current version check using unary plus and string splitting works, but could be made more readable for better maintainability.

-export default +process.versions.node.split('.')[0] <= 16
+// Extract the major Node.js version number
+const nodeMajorVersion = parseInt(process.versions.node.split('.')[0], 10)
+
+export default nodeMajorVersion <= 16
  ? {}
  : {
      files: ['**/*.ts', '**/*.tsx'],
      plugins: {
        'import-x': importX,
      },
      settings: {
        ...flatConfigs.typescript.settings,
        'import-x/resolver-next': [
          createTypeScriptImportResolver({
            project: absoluteGlobPath,
            noWarnOnMultipleProjects: true,
          }),
        ],
      },
      rules: base_().rules,
    }
tests/e2e/e2e.spec.ts (1)

19-23: Consider adding error handling for yarn command execution

While the code correctly checks for the existence of a yarn.lock file before running yarn, there's no error handling for the yarn command execution itself.

  if (tryFile('yarn.lock', false, absoluteDir)) {
-   await exec('yarn', ['--immutable'])
+   try {
+     await exec('yarn', ['--immutable'])
+   } catch (error) {
+     console.error(`Failed to run yarn in ${absoluteDir}:`, error)
+   }
  }
tests/e2e/withJsExtension/test.cjs (1)

2-2: Updated ESLint disable directive

The ESLint directive has been expanded to explicitly disable both no-require-imports and no-var-requires rules. The trailing comma in the directive should be removed.

-/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, */
+/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 990805c and b646c91.

⛔ Files ignored due to path filters (8)
  • tests/e2e/__snapshots__/e2e.spec.ts.snap is excluded by !**/*.snap
  • tests/e2e/nestedPackageJson/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • tests/e2e/withQuerystring/image.svg is excluded by !**/*.svg
  • tests/e2e/withQuerystring/subfolder/image.svg is excluded by !**/*.svg
  • tests/unit/pnp/.yarn/cache/lodash.zip-npm-4.2.0-5299417ec8-cb06530d81.zip is excluded by !**/.yarn/**, !**/*.zip
  • tests/unit/pnp/.yarn/releases/yarn-4.8.0.cjs is excluded by !**/.yarn/**
  • tests/unit/pnp/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (25)
  • .env.yarn (0 hunks)
  • .lintstagedrc.js (1 hunks)
  • .prettierignore (1 hunks)
  • auto-imports.d.ts (1 hunks)
  • eslint.config.js (2 hunks)
  • package.json (3 hunks)
  • tests/e2e/absoluteAlias/tsconfig.json (1 hunks)
  • tests/e2e/e2e.spec.ts (1 hunks)
  • tests/e2e/importXResolverV3/eslint.config.js (1 hunks)
  • tests/e2e/package.json (1 hunks)
  • tests/e2e/withJsExtension/.eslintrc.cjs (0 hunks)
  • tests/e2e/withJsExtension/index.ts (1 hunks)
  • tests/e2e/withJsExtension/test.cjs (2 hunks)
  • tests/e2e/withQuerystring/.eslintrc.cjs (1 hunks)
  • tests/e2e/withoutPaths/.eslintrc.cjs (1 hunks)
  • tests/importXResolverV3/eslint.config.cjs (0 hunks)
  • tests/nestedPackageJson/.eslintrc.cjs (0 hunks)
  • tests/pnp/pnp.spec.ts (0 hunks)
  • tests/tsconfig.json (1 hunks)
  • tests/unit/unit.spec.ts (1 hunks)
  • tests/withJsconfig/.eslintrc.cjs (0 hunks)
  • tsconfig.base.json (1 hunks)
  • tsconfig.json (1 hunks)
  • tsconfig.staged.json (1 hunks)
  • vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (6)
  • .env.yarn
  • tests/e2e/withJsExtension/.eslintrc.cjs
  • tests/withJsconfig/.eslintrc.cjs
  • tests/nestedPackageJson/.eslintrc.cjs
  • tests/pnp/pnp.spec.ts
  • tests/importXResolverV3/eslint.config.cjs
🔇 Additional comments (24)
vitest.config.ts (1)

1-1: Good addition of auto-import plugin for Vitest

Adding the auto-import plugin for Vitest functions is a good enhancement that will reduce boilerplate in test files. This change streamlines the testing experience by making common testing functions globally available without explicit imports.

Also applies to: 5-9

.prettierignore (2)

2-2: Appropriate ignore for auto-generated declaration file

Adding /auto-imports.d.ts to the ignore list is appropriate since this file is auto-generated by the unplugin-auto-import plugin and shouldn't be manually formatted.


4-5:

✅ Verification successful

Verify the updated ignore patterns

The pattern changes from more specific to more general (.pnp.*) and from more general to more specific (*.svg vs previous **/*.svg). Please verify that:

  1. The broader .pnp.* pattern won't accidentally ignore files that should be formatted
  2. The more restrictive *.svg pattern won't cause SVG files in subdirectories to be unexpectedly formatted if they should be ignored

🏁 Script executed:

#!/bin/bash
# Find all .pnp.* files to verify the new ignore pattern covers all intended files
echo "All .pnp.* files in the repository:"
fd ".pnp\."

# Find all SVG files to check if any exist in subdirectories that might be affected
echo -e "\nAll SVG files in the repository:"
fd ".svg$"

Length of output: 270


Ignore pattern verification successful

  • The .pnp.* pattern did not match any files, indicating it isn’t inadvertently ignoring files that should be formatted.
  • The *.svg pattern, although seemingly more restrictive than **/*.svg, correctly ignores SVG files in all directories (as confirmed by the presence of SVG files in subdirectories whose basenames match the pattern).
eslint.config.js (1)

3-3:

❓ Verification inconclusive

Verify the impact of switching from 'recommended' to 'base' ESLint config

This change switches from using the 'recommended' configuration to the 'base' configuration from '@1stg/eslint-config'. This could significantly alter the linting behavior of the project.

Let's check the difference between these configurations:

Also applies to: 13-13


🏁 Script executed:

#!/bin/bash
# Check what these configurations actually contain by examining the package
echo "Checking for '@1stg/eslint-config' in package.json"
grep -A 5 "@1stg/eslint-config" package.json

echo -e "\nTrying to find the configuration definitions:"
# Look for exported configurations in the package
npx eslint-config-info@latest '@1stg/eslint-config'

# Alternative approach if the above doesn't work
echo -e "\nAlternative check:"
find node_modules/@1stg/eslint-config -type f -name "*.js" | xargs cat | grep -A 10 -B 10 "recommended\|base"

Length of output: 718


Manual Verification Required: Confirm ESLint Configuration Impact

The changes in eslint.config.js (Line 3 importing 'base' instead of 'recommended' and the corresponding spread change on Line 13) switch the ESLint config from a likely more opinionated setup to a minimal one. Our automated check on the contents of @1stg/eslint-config was inconclusive (no output and errors were encountered), so we cannot determine the exact differences between the 'base' and 'recommended' configurations.

Please verify manually that:

  • The 'base' configuration provides the intended set of essential linting rules.
  • There are no unintended relaxations or tightenings in linting behaviors that might adversely impact the project.

Review the package documentation or source (if available) to ensure this switch aligns with your linting strategy.

.lintstagedrc.js (1)

1-7: Good enhancement for e2e test type checking

This change improves the lint-staged configuration by adding specific TypeScript checking for e2e test files. Running the TypeScript compiler with --noEmit on staged e2e test files will help catch type errors earlier in the development process, which aligns well with the PR objective of improving test infrastructure.

tests/e2e/package.json (1)

1-5: Module System Update: Changing to ECMAScript Modules
The update of the "type" field from "commonjs" to "module" properly aligns the e2e tests with ECMAScript module semantics. Ensure that any related tooling, imports, or scripts are also updated for ESM compatibility.

tests/e2e/withoutPaths/.eslintrc.cjs (1)

1-2: ESLint Configuration Inheritance
This new ESLint configuration file correctly leverages the base configuration by passing __dirname to it. This ensures consistency and centralized management of ESLint rules across different test directories.

tsconfig.json (1)

1-7: TypeScript OutDir Specification
The addition of the "outDir": "./lib" property within compilerOptions is a clear and useful enhancement. It directs the compiled TypeScript files to the designated output directory. Please verify that all build or deployment scripts reference the new output folder as needed.

tsconfig.staged.json (1)

1-5: Staged TSConfig for Environment-specific Compilation
Introducing tsconfig.staged.json to extend the base configuration while excluding tests/e2e/absoluteAlias is a good move towards refining and isolating TypeScript behavior for staged processes. Just ensure that this configuration is integrated into your CI/build pipeline as intended.

tests/e2e/withQuerystring/.eslintrc.cjs (1)

1-2: Consistent ESLint Configuration Setup
This file reuses the base ESLint configuration by requiring ../base.eslintrc.cjs with the current directory. This consistent approach helps maintain uniform linting behavior across different testing environments.

tests/e2e/absoluteAlias/tsconfig.json (1)

2-2: Good addition of base configuration.

Extending from a base TypeScript configuration ensures consistency across the project and reduces duplication. This change follows best practices for TypeScript project organization.

tests/tsconfig.json (1)

1-7: Well-structured test configuration.

This new configuration appropriately extends the base config while setting up the test-specific structure. Including both e2e and unit test directories along with auto-imports declaration aligns perfectly with the PR objective of splitting test cases.

tests/e2e/importXResolverV3/eslint.config.js (1)

6-6:

✅ Verification successful

Verify the base configuration import.

Ensure that the imported base_.js returns a function as it's being called in line 34 with base_().rules.


🏁 Script executed:

#!/bin/bash
# Verify the structure of the base ESLint configuration file
cat tests/e2e/base.eslintrc.cjs || cat tests/base.eslintrc.cjs

Length of output: 1078


Action: Confirm the base config import.

The ESLint base config located at tests/e2e/base.eslintrc.cjs is verified to export a function. When this function is invoked (as in line 34 with base_().rules), it returns an object containing the rules property as expected. No changes are needed in the import or its usage.

tests/e2e/e2e.spec.ts (3)

1-6: Clean import organization

The imports are well-structured with Node.js native modules separated from external dependencies. The code properly uses the newer 'node:' prefix for Node.js built-in modules, which is a good practice.


7-17: Well-structured test suite with directory filtering

The test suite is well-organized, using async/await pattern appropriately with the describe block. The directory filtering logic correctly excludes the snapshot directory and non-directory entries.


25-50: Robust ESLint configuration detection and execution

The test case properly detects whether to use a custom ESLint config or default settings based on the presence of an eslint.config.js file. It also correctly sets up the environment variables needed for different ESLint modes.

The snapshot matching approach is a good way to detect changes in ESLint output across test runs.

tsconfig.base.json (1)

4-5: Appropriate TypeScript configuration updates

The addition of rootDir and verbatimModuleSyntax settings is appropriate:

  1. rootDir: "." establishes the base directory for TypeScript compilation, which is useful for properly organizing output files.
  2. verbatimModuleSyntax: false allows more flexibility in imports without requiring explicit 'import type' syntax.

These changes align well with a project that's reorganizing its test structure.

tests/e2e/withJsExtension/test.cjs (2)

7-7: Updated import path reflects new directory structure

The import path has been changed to accommodate the restructured test directory organization, which aligns with the PR's goal of splitting e2e and unit tests.


131-131: Path correction for dummy.js symlink

The path to the dummy.js symlink has been updated to reflect the new relative positioning after the test reorganization.

package.json (3)

61-61: Simplified prepare script

The prepare script has been streamlined to focus on essential setup tasks without running yarn in nested directories. This change simplifies the development workflow.


63-63: Updated test script to include both e2e and unit tests

The test script now explicitly runs both a specific e2e test and the Vitest test suite, which aligns perfectly with the PR's goal of separating but maintaining both test types.


93-117: New dependencies to support testing infrastructure

The addition of @pkgr/core and unplugin-auto-import supports the enhanced testing structure:

  1. @pkgr/core is used in the e2e tests for file operations (as seen in the tryFile function)
  2. unplugin-auto-import likely helps with automatically importing test utilities

These dependencies are appropriate for the changes being made to the test infrastructure.

auto-imports.d.ts (1)

1-22: Well-structured global declarations for testing utilities.

This auto-generated declaration file properly sets up global TypeScript types for Vitest testing functions, which will allow test files to use these functions without explicit imports. This is a good pattern that reduces boilerplate and supports the PR's objective of improving the testing infrastructure.

tests/e2e/withJsExtension/index.ts (1)

3-3: Good expansion of test cases.

The updated extension in the import and the additional import paths will help test more scenarios for the resolver, improving test coverage for different file extension patterns and nested directory structures.

Also applies to: 6-9

@JounQin JounQin force-pushed the chore/split_e2e_unit branch 2 times, most recently from 7372c12 to f1c8b6d Compare March 29, 2025 11:53
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: 1

🧹 Nitpick comments (4)
tsconfig.base.json (1)

4-5: Module Syntax Configuration Verification.
The addition of "verbatimModuleSyntax": false here changes how module imports are emitted by the compiler. Since several options were removed in this base config, please verify that this setting appropriately aligns with your project’s module-handling requirements and that any derived configurations override it as intended if necessary.

tests/e2e/e2e.spec.ts (3)

21-23: Consider checking the exit code of yarn command.

The yarn installation is being executed but its result isn't being checked. If yarn fails, the test might proceed with an incomplete environment.

-    if (tryFile('yarn.lock', false, absoluteDir)) {
-      await exec('yarn', ['--immutable'])
-    }
+    if (tryFile('yarn.lock', false, absoluteDir)) {
+      const { exitCode } = await exec('yarn', ['--immutable'])
+      if (exitCode !== 0) {
+        throw new Error(`Failed to install dependencies in ${absoluteDir}`)
+      }
+    }

44-44: Consider making NODE_OPTIONS configurable.

The --no-warnings=ESLintRCWarning option is hardcoded, which might be too specific and could mask other useful warnings.

-                NODE_OPTIONS: '--no-warnings=ESLintRCWarning',
+                NODE_OPTIONS: process.env.E2E_NODE_OPTIONS || '--no-warnings=ESLintRCWarning',

7-24: Consider using describe.each for cleaner test organization.

The current implementation uses a for-loop to dynamically create tests, but Vitest supports a more declarative approach with describe.each.

Here's how you could refactor this part:

describe('e2e cases', () => {
  const { dirname } = import.meta

  beforeAll(async () => {
    const dirents = await fs.readdir(dirname, { withFileTypes: true })
    const testDirs = dirents
      .filter(dirent => dirent.isDirectory() && dirent.name !== '__snapshots__')
      .map(dirent => dirent.name)
    
    // Install dependencies for all test directories with yarn.lock files
    for (const dirName of testDirs) {
      const absoluteDir = path.resolve(dirname, dirName)
      if (tryFile('yarn.lock', false, absoluteDir)) {
        await exec('yarn', ['--immutable'], {
          nodeOptions: { cwd: absoluteDir }
        })
      }
    }
  })

  it.each(/* array of test directories */)(
    'should exec eslint successfully for %s',
    async (dirName) => {
      // Test implementation
    }
  )
})
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b646c91 and f1c8b6d.

⛔ Files ignored due to path filters (8)
  • tests/e2e/__snapshots__/e2e.spec.ts.snap is excluded by !**/*.snap
  • tests/e2e/nestedPackageJson/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • tests/e2e/withQuerystring/image.svg is excluded by !**/*.svg
  • tests/e2e/withQuerystring/subfolder/image.svg is excluded by !**/*.svg
  • tests/unit/pnp/.yarn/cache/lodash.zip-npm-4.2.0-5299417ec8-cb06530d81.zip is excluded by !**/.yarn/**, !**/*.zip
  • tests/unit/pnp/.yarn/releases/yarn-4.8.0.cjs is excluded by !**/.yarn/**
  • tests/unit/pnp/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (25)
  • .env.yarn (0 hunks)
  • .lintstagedrc.js (1 hunks)
  • .prettierignore (1 hunks)
  • auto-imports.d.ts (1 hunks)
  • eslint.config.js (2 hunks)
  • package.json (3 hunks)
  • tests/e2e/absoluteAlias/tsconfig.json (1 hunks)
  • tests/e2e/e2e.spec.ts (1 hunks)
  • tests/e2e/importXResolverV3/eslint.config.js (1 hunks)
  • tests/e2e/package.json (1 hunks)
  • tests/e2e/withJsExtension/.eslintrc.cjs (0 hunks)
  • tests/e2e/withJsExtension/index.ts (1 hunks)
  • tests/e2e/withJsExtension/test.cjs (2 hunks)
  • tests/e2e/withQuerystring/.eslintrc.cjs (1 hunks)
  • tests/e2e/withoutPaths/.eslintrc.cjs (1 hunks)
  • tests/importXResolverV3/eslint.config.cjs (0 hunks)
  • tests/nestedPackageJson/.eslintrc.cjs (0 hunks)
  • tests/pnp/pnp.spec.ts (0 hunks)
  • tests/tsconfig.json (1 hunks)
  • tests/unit/unit.spec.ts (1 hunks)
  • tests/withJsconfig/.eslintrc.cjs (0 hunks)
  • tsconfig.base.json (1 hunks)
  • tsconfig.json (1 hunks)
  • tsconfig.staged.json (1 hunks)
  • vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (6)
  • .env.yarn
  • tests/e2e/withJsExtension/.eslintrc.cjs
  • tests/nestedPackageJson/.eslintrc.cjs
  • tests/withJsconfig/.eslintrc.cjs
  • tests/pnp/pnp.spec.ts
  • tests/importXResolverV3/eslint.config.cjs
🚧 Files skipped from review as they are similar to previous changes (14)
  • tests/e2e/package.json
  • tests/e2e/absoluteAlias/tsconfig.json
  • tsconfig.staged.json
  • tests/e2e/withQuerystring/.eslintrc.cjs
  • tests/tsconfig.json
  • vitest.config.ts
  • tests/e2e/withoutPaths/.eslintrc.cjs
  • tests/e2e/importXResolverV3/eslint.config.js
  • eslint.config.js
  • .lintstagedrc.js
  • .prettierignore
  • auto-imports.d.ts
  • tests/e2e/withJsExtension/test.cjs
  • tests/e2e/withJsExtension/index.ts
🧰 Additional context used
🪛 GitHub Check: Lint and Test with Node.js 20 on ubuntu-latest
tests/e2e/e2e.spec.ts

[failure] 49-49: tests/e2e/e2e.spec.ts > e2e cases > should exec eslint successfully
Error: Snapshot e2e cases > should exec eslint successfully > nestedPackageJson 1 mismatched

  • Expected
  • Received

    {

  • "exitCode": 0,
  • "exitCode": 1,
    "stderr": "",
  • "stdout": "",
  • "stdout": "
  • /tests/e2e/nestedPackageJson/test.ts
  • 1:25 error Unable to resolve path to module '@atlaskit/pragmatic-drag-and-drop/combine' import-x/no-unresolved
  • ✖ 1 problem (1 error, 0 warnings)
  • ",
    }

❯ tests/e2e/e2e.spec.ts:49:9

🪛 GitHub Check: Lint and Test with Node.js 22 on macos-latest
tests/e2e/e2e.spec.ts

[failure] 49-49: tests/e2e/e2e.spec.ts > e2e cases > should exec eslint successfully
Error: Snapshot e2e cases > should exec eslint successfully > nestedPackageJson 1 mismatched

  • Expected
  • Received

    {

  • "exitCode": 0,
  • "exitCode": 1,
    "stderr": "",
  • "stdout": "",
  • "stdout": "
  • /tests/e2e/nestedPackageJson/test.ts
  • 1:25 error Unable to resolve path to module '@atlaskit/pragmatic-drag-and-drop/combine' import-x/no-unresolved
  • ✖ 1 problem (1 error, 0 warnings)
  • ",
    }

❯ tests/e2e/e2e.spec.ts:49:9

🪛 GitHub Check: Lint and Test with Node.js 20 on macos-latest
tests/e2e/e2e.spec.ts

[failure] 49-49: tests/e2e/e2e.spec.ts > e2e cases > should exec eslint successfully
Error: Snapshot e2e cases > should exec eslint successfully > nestedPackageJson 1 mismatched

  • Expected
  • Received

    {

  • "exitCode": 0,
  • "exitCode": 1,
    "stderr": "",
  • "stdout": "",
  • "stdout": "
  • /tests/e2e/nestedPackageJson/test.ts
  • 1:25 error Unable to resolve path to module '@atlaskit/pragmatic-drag-and-drop/combine' import-x/no-unresolved
  • ✖ 1 problem (1 error, 0 warnings)
  • ",
    }

❯ tests/e2e/e2e.spec.ts:49:9

🪛 GitHub Check: Lint and Test with Node.js 22 on windows-latest
tests/e2e/e2e.spec.ts

[failure] 49-49: tests/e2e/e2e.spec.ts > e2e cases > should exec eslint successfully
Error: Snapshot e2e cases > should exec eslint successfully > nestedPackageJson 1 mismatched

  • Expected
  • Received

    {

  • "exitCode": 0,
  • "exitCode": 1,
    "stderr": "",
  • "stdout": "",
  • "stdout": "
  • /tests/e2e/nestedPackageJson/test.ts
  • 1:25 error Unable to resolve path to module '@atlaskit/pragmatic-drag-and-drop/combine' import-x/no-unresolved
  • ✖ 1 problem (1 error, 0 warnings)
  • ",
    }

❯ tests/e2e/e2e.spec.ts:49:9

🪛 GitHub Check: Lint and Test with Node.js 18 on windows-latest
tests/e2e/e2e.spec.ts

[failure] 49-49: tests/e2e/e2e.spec.ts > e2e cases > should exec eslint successfully
Error: Snapshot e2e cases > should exec eslint successfully > nestedPackageJson 1 mismatched

  • Expected
  • Received

    {

  • "exitCode": 0,
  • "exitCode": 1,
    "stderr": "",
  • "stdout": "",
  • "stdout": "
  • /tests/e2e/nestedPackageJson/test.ts
  • 1:25 error Unable to resolve path to module '@atlaskit/pragmatic-drag-and-drop/combine' import-x/no-unresolved
  • ✖ 1 problem (1 error, 0 warnings)
  • ",
    }

❯ tests/e2e/e2e.spec.ts:49:9

🪛 GitHub Check: Lint and Test with Node.js 18 on macos-latest
tests/e2e/e2e.spec.ts

[failure] 49-49: tests/e2e/e2e.spec.ts > e2e cases > should exec eslint successfully
Error: Snapshot e2e cases > should exec eslint successfully > nestedPackageJson 1 mismatched

  • Expected
  • Received

    {

  • "exitCode": 0,
  • "exitCode": 1,
    "stderr": "",
  • "stdout": "",
  • "stdout": "
  • /tests/e2e/nestedPackageJson/test.ts
  • 1:25 error Unable to resolve path to module '@atlaskit/pragmatic-drag-and-drop/combine' import-x/no-unresolved
  • ✖ 1 problem (1 error, 0 warnings)
  • ",
    }

❯ tests/e2e/e2e.spec.ts:49:9

🪛 GitHub Check: Lint and Test with Node.js 22 on ubuntu-latest
tests/e2e/e2e.spec.ts

[failure] 49-49: tests/e2e/e2e.spec.ts > e2e cases > should exec eslint successfully
Error: Snapshot e2e cases > should exec eslint successfully > nestedPackageJson 1 mismatched

  • Expected
  • Received

    {

  • "exitCode": 0,
  • "exitCode": 1,
    "stderr": "",
  • "stdout": "",
  • "stdout": "
  • /tests/e2e/nestedPackageJson/test.ts
  • 1:25 error Unable to resolve path to module '@atlaskit/pragmatic-drag-and-drop/combine' import-x/no-unresolved
  • ✖ 1 problem (1 error, 0 warnings)
  • ",
    }

❯ tests/e2e/e2e.spec.ts:49:9

🪛 GitHub Check: Lint and Test with Node.js 20 on windows-latest
tests/e2e/e2e.spec.ts

[failure] 49-49: tests/e2e/e2e.spec.ts > e2e cases > should exec eslint successfully
Error: Snapshot e2e cases > should exec eslint successfully > nestedPackageJson 1 mismatched

  • Expected
  • Received

    {

  • "exitCode": 0,
  • "exitCode": 1,
    "stderr": "",
  • "stdout": "",
  • "stdout": "
  • /tests/e2e/nestedPackageJson/test.ts
  • 1:25 error Unable to resolve path to module '@atlaskit/pragmatic-drag-and-drop/combine' import-x/no-unresolved
  • ✖ 1 problem (1 error, 0 warnings)
  • ",
    }

❯ tests/e2e/e2e.spec.ts:49:9

🪛 GitHub Check: Lint and Test with Node.js 18 on ubuntu-latest
tests/e2e/e2e.spec.ts

[failure] 49-49: tests/e2e/e2e.spec.ts > e2e cases > should exec eslint successfully
Error: Snapshot e2e cases > should exec eslint successfully > nestedPackageJson 1 mismatched

  • Expected
  • Received

    {

  • "exitCode": 0,
  • "exitCode": 1,
    "stderr": "",
  • "stdout": "",
  • "stdout": "
  • /tests/e2e/nestedPackageJson/test.ts
  • 1:25 error Unable to resolve path to module '@atlaskit/pragmatic-drag-and-drop/combine' import-x/no-unresolved
  • ✖ 1 problem (1 error, 0 warnings)
  • ",
    }

❯ tests/e2e/e2e.spec.ts:49:9

🪛 GitHub Actions: CI
tests/e2e/e2e.spec.ts

[error] 49-49: Snapshot e2e cases > should exec eslint successfully > nestedPackageJson 1 mismatched. Expected exitCode: 0, Received exitCode: 1. Error: Unable to resolve path to module '@atlaskit/pragmatic-drag-and-drop/combine' (import-x/no-unresolved)

🔇 Additional comments (7)
package.json (4)

61-61: Revise Prepare Script Changes

The prepare script now runs:

"prepare": "simple-git-hooks && yarn-berry-deduplicate || exit 0"

This change removes the previous directory change and yarn call. Please verify that this omission is intentional and that none of the setup steps in the tests/nestedPackageJson directory are required anymore. Additionally, ensure that using || exit 0 as a fallback does not inadvertently mask potential issues with these commands.


63-63: Clarify Test Script Flow

The updated test script now executes:

"test": "node tests/e2e/withJsExtension/test.cjs && vitest --run"

This clearly separates end-to-end tests from unit tests by running the specified e2e test file first followed by running Vitest. Confirm that the sequential execution is intended, as any failure in the e2e tests will prevent the unit tests from running. If independent execution is desired, consider whether a parallel or grouped execution might be more appropriate.


93-93: New Dev Dependency: @pkgr/core

The addition of "@pkgr/core": "^0.2.0" in devDependencies suggests that new build or packaging tasks might be leveraging this dependency. Please ensure that its usage is properly documented and integrated within the relevant scripts or configuration files.


117-117: New Dev Dependency: unplugin-auto-import

The dependency "unplugin-auto-import": "^19.1.2" is added to support automatic imports (likely for testing utilities or global declarations). Verify that the corresponding configuration (e.g., in your vitest.config.ts or similar configuration files) has been updated accordingly, and confirm that this addition aligns with your intended testing setup improvements.

tsconfig.json (2)

3-6: Compiler Options Override Check.
In this configuration, you’ve reintroduced "outDir": "./lib" and explicitly set "verbatimModuleSyntax": true under "compilerOptions". Note that this diverges from the base configuration (which sets "verbatimModuleSyntax": false). Please confirm that this override is deliberate and that the intended module syntax behavior is achieved during the build process.


7-8: Include Paths Verification.
The "include": ["src", "eslint.config.js"] setting appears to restrict compilation to specific sources. Ensure that excluding test files or other directories here is intentional and that it aligns with the overall testing and build strategy outlined by the PR objectives.

tests/unit/unit.spec.ts (1)

1-34: Well-structured unit test for PnP functionality.

This is a good implementation of a unit test that verifies the TypeScript import resolver's compatibility with Yarn's Plug'n'Play. The test properly sets up the environment, executes the resolver with relevant modules, and validates the results with snapshots.

@JounQin
Copy link
Collaborator Author

JounQin commented Mar 29, 2025

image

@ljharb Can you help to install codecov GitHub App?

@JounQin JounQin force-pushed the chore/split_e2e_unit branch from f1c8b6d to 4507350 Compare March 29, 2025 12:05
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 (7)
package.json (1)

61-61: Review the prepare Script for Error Suppression.
The updated prepare script now only runs:

"prepare": "simple-git-hooks && yarn-berry-deduplicate || exit 0"

Please verify if intentionally using || exit 0 to suppress errors from simple-git-hooks or yarn-berry-deduplicate. This pattern may mask critical failures, so if errors should be caught instead, consider adjusting the logic or adding logging.

tests/unit/unit.spec.ts (6)

6-8: Consider documenting the PnP testing purpose

The PnP (Plug'n'Play) testing setup could benefit from a brief comment explaining what aspects of the resolver are being tested with PnP and why this is important.


9-14: Add error handling for Yarn installation

The exec call for Yarn installation lacks error handling. Consider adding specific error handling to provide clearer feedback if the installation fails.

-    await exec('yarn', ['install'], {
+    try {
+      await exec('yarn', ['install'], {
+        nodeOptions: {
+          cwd: pnpDir,
+        },
+      })
+    } catch (error) {
+      console.error('Failed to install PnP dependencies:', error)
+      throw error
+    }
-      nodeOptions: {
-        cwd: pnpDir,
-      },
-    })

16-19: Consider caching the resolver instance

Since the resolver is created without arguments, it could potentially be shared across multiple tests if more tests are added in the future.


33-34: Consider documentation for the long timeout

The 10-second timeout is appropriate for a test involving file operations, but a brief comment explaining why this longer timeout is necessary would improve maintainability.

-  }, 10_000)
+  }, 10_000) // Longer timeout for Yarn install operations

1-34: Add cleanup step after test completion

The test creates or modifies files in the PnP directory but doesn't clean up afterward. Consider adding a cleanup step to restore the environment to its original state, especially important for CI environments.

+ afterAll(async () => {
+   // Clean up PnP installation artifacts if needed
+   try {
+     await exec('rm', ['-rf', path.resolve(pnpDir, '.yarn')], {
+       nodeOptions: {
+         cwd: pnpDir,
+       },
+     })
+   } catch (error) {
+     console.warn('Failed to clean up PnP artifacts:', error)
+   }
+ })

1-34: Consider optimization for repeated test runs

The test currently runs yarn install on every execution. Consider adding a check to skip installation if the PnP setup already exists, which would speed up test execution during development.

import { exec } from 'tinyexec'
+ import fs from 'node:fs'

import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript'
import path from 'node:path'

describe('createTypeScriptImportResolver', () => {
  const pnpDir = path.resolve(import.meta.dirname, 'pnp')

  it('should work with pnp', async () => {
+   const pnpSetupExists = fs.existsSync(path.resolve(pnpDir, '.pnp.cjs'))
+   
+   if (!pnpSetupExists) {
      await exec('yarn', ['install'], {
        nodeOptions: {
          cwd: pnpDir,
        },
      })
+   }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f1c8b6d and 4507350.

⛔ Files ignored due to path filters (8)
  • tests/e2e/__snapshots__/e2e.spec.ts.snap is excluded by !**/*.snap
  • tests/e2e/nestedPackageJson/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • tests/e2e/withQuerystring/image.svg is excluded by !**/*.svg
  • tests/e2e/withQuerystring/subfolder/image.svg is excluded by !**/*.svg
  • tests/unit/pnp/.yarn/cache/lodash.zip-npm-4.2.0-5299417ec8-cb06530d81.zip is excluded by !**/.yarn/**, !**/*.zip
  • tests/unit/pnp/.yarn/releases/yarn-4.8.0.cjs is excluded by !**/.yarn/**
  • tests/unit/pnp/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (25)
  • .env.yarn (0 hunks)
  • .lintstagedrc.js (1 hunks)
  • .prettierignore (1 hunks)
  • auto-imports.d.ts (1 hunks)
  • eslint.config.js (2 hunks)
  • package.json (3 hunks)
  • tests/e2e/absoluteAlias/tsconfig.json (1 hunks)
  • tests/e2e/e2e.spec.ts (1 hunks)
  • tests/e2e/importXResolverV3/eslint.config.js (1 hunks)
  • tests/e2e/package.json (1 hunks)
  • tests/e2e/withJsExtension/.eslintrc.cjs (0 hunks)
  • tests/e2e/withJsExtension/index.ts (1 hunks)
  • tests/e2e/withJsExtension/test.cjs (2 hunks)
  • tests/e2e/withQuerystring/.eslintrc.cjs (1 hunks)
  • tests/e2e/withoutPaths/.eslintrc.cjs (1 hunks)
  • tests/importXResolverV3/eslint.config.cjs (0 hunks)
  • tests/nestedPackageJson/.eslintrc.cjs (0 hunks)
  • tests/pnp/pnp.spec.ts (0 hunks)
  • tests/tsconfig.json (1 hunks)
  • tests/unit/unit.spec.ts (1 hunks)
  • tests/withJsconfig/.eslintrc.cjs (0 hunks)
  • tsconfig.base.json (1 hunks)
  • tsconfig.json (1 hunks)
  • tsconfig.staged.json (1 hunks)
  • vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (6)
  • .env.yarn
  • tests/withJsconfig/.eslintrc.cjs
  • tests/e2e/withJsExtension/.eslintrc.cjs
  • tests/nestedPackageJson/.eslintrc.cjs
  • tests/pnp/pnp.spec.ts
  • tests/importXResolverV3/eslint.config.cjs
🚧 Files skipped from review as they are similar to previous changes (16)
  • tests/e2e/withoutPaths/.eslintrc.cjs
  • tests/e2e/absoluteAlias/tsconfig.json
  • tests/e2e/withQuerystring/.eslintrc.cjs
  • tsconfig.json
  • tests/e2e/importXResolverV3/eslint.config.js
  • tests/tsconfig.json
  • eslint.config.js
  • tests/e2e/e2e.spec.ts
  • tsconfig.base.json
  • .prettierignore
  • tests/e2e/package.json
  • tests/e2e/withJsExtension/test.cjs
  • .lintstagedrc.js
  • vitest.config.ts
  • tests/e2e/withJsExtension/index.ts
  • auto-imports.d.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
🔇 Additional comments (6)
tsconfig.staged.json (1)

1-7: Well-structured new TypeScript configuration.
The file correctly extends from the base configuration (./tsconfig.base), specifies the rootDir as ".", and excludes "tests/e2e/absoluteAlias" from compilation. Please verify that the exclusion of the absoluteAlias folder is in line with the intended separation of end-to-end and unit tests.

package.json (3)

63-63: Validate the Updated Test Command Workflow.
The test script has been updated to:

"test": "node tests/e2e/withJsExtension/test.cjs && vitest run"

This change indicates that an end-to-end test is executed before running unit tests with Vitest, aligning with the PR objective of splitting e2e and unit cases. Please confirm that this sequential approach is intended and that it covers all necessary test scenarios.


93-93: Confirm the Addition of @pkgr/core.
A new devDependency has been added:

"@pkgr/core": "^0.2.0"

Ensure that this dependency is required for our build/test processes and that its versioning aligns with project expectations.


117-117: Confirm the Addition of unplugin-auto-import.
A new devDependency has been introduced:

"unplugin-auto-import": "^19.1.2"

This dependency supports auto-import functionality (likely configured in vitest.config.ts). Please verify that this version meets our requirements and is properly integrated into our testing setup.

tests/unit/unit.spec.ts (2)

1-5: Imports look appropriate for the test

The imports provide all necessary functionality: exec for running Yarn commands, the resolver function being tested, and path utilities.


20-32: Use of inline snapshots is appropriate

The inline snapshots effectively verify the resolver's behavior with PnP modules. Note that the paths in the snapshots use <ROOT> which appears to be a path normalization helper, which is good practice.

@JounQin JounQin force-pushed the chore/split_e2e_unit branch from 4507350 to 628e792 Compare March 29, 2025 12:49
@JounQin JounQin requested a review from Copilot March 29, 2025 12:50
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

A PR to split end-to-end and unit tests by updating and refining related ESLint and lint-staged configurations.

  • Updated the e2e ESLint configuration by replacing node import rules with an import order rule and modifying file override patterns.
  • Renamed and updated imported configuration variables in both eslint.config.js and .lintstagedrc.js for consistency.
  • Added a custom tsc command for linting e2e tests with absolute aliases.

Reviewed Changes

Copilot reviewed 172 out of 178 changed files in this pull request and generated no comments.

File Description
tests/e2e/base.eslintrc.cjs Replaced node import rules with a new rule and updated file override pattern.
eslint.config.js Renamed the imported ESLint configuration from "recommended" to "base".
.lintstagedrc.js Modified the lint-staged config to include a custom command for e2e tests.
Files not reviewed (6)
  • .env.yarn: Language not supported
  • .prettierignore: Language not supported
  • .vscode/settings.json: Language not supported
  • package.json: Language not supported
  • tests/e2e/snapshots/e2e.spec.ts.snap: Language not supported
  • tests/e2e/absoluteAlias/tsconfig.json: Language not supported
Comments suppressed due to low confidence (3)

tests/e2e/base.eslintrc.cjs:32

  • Ensure that the removal of 'node/no-extraneous-import' and 'node/no-missing-import' is intentional, as this change could affect import validation. Consider adding an inline comment for clarity if this change is deliberate.
    'node/no-extraneous-import': 0,

eslint.config.js:3

  • [nitpick] The variable name was changed from 'recommended' to 'base'. Verify that this naming change is consistently reflected in all related documentation and configuration references.
import base from '@1stg/eslint-config'

.lintstagedrc.js:5

  • [nitpick] Verify that the glob pattern for 'tests/e2e/absoluteAlias/**/*.ts?(x)' covers all intended files. Adjust the pattern if necessary to ensure that no relevant test files are omitted.
'tests/e2e/absoluteAlias/**/*.ts?(x)': () => 'tsc -p tests/e2e/absoluteAlias --noEmit',

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)
package.json (2)

61-61: Refine the "prepare" script.
The updated "prepare" script now only runs simple-git-hooks && yarn-berry-deduplicate || exit 0. This simplification is acceptable if the removal of the directory change and extra commands was intentional. However, consider if silently swallowing errors (via || exit 0) might hide issues that you want to catch during preparation.


63-63: Review the "test" script execution order.
The "test" script now executes node tests/e2e/withJsExtension/test.cjs && vitest run, which sequentially runs the end-to-end tests before the unit tests. Ensure that this ordering is intentional, as any failure in the e2e tests will prevent the unit tests from running. If sequential execution is desired, then this is fine; otherwise, you might consider running them concurrently.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4507350 and 628e792.

⛔ Files ignored due to path filters (8)
  • tests/e2e/__snapshots__/e2e.spec.ts.snap is excluded by !**/*.snap
  • tests/e2e/nestedPackageJson/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • tests/e2e/withQuerystring/image.svg is excluded by !**/*.svg
  • tests/e2e/withQuerystring/subfolder/image.svg is excluded by !**/*.svg
  • tests/unit/pnp/.yarn/cache/lodash.zip-npm-4.2.0-5299417ec8-cb06530d81.zip is excluded by !**/.yarn/**, !**/*.zip
  • tests/unit/pnp/.yarn/releases/yarn-4.8.0.cjs is excluded by !**/.yarn/**
  • tests/unit/pnp/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (27)
  • .env.yarn (0 hunks)
  • .lintstagedrc.js (1 hunks)
  • .prettierignore (1 hunks)
  • .vscode/settings.json (0 hunks)
  • auto-imports.d.ts (1 hunks)
  • eslint.config.js (2 hunks)
  • package.json (3 hunks)
  • tests/e2e/absoluteAlias/tsconfig.json (1 hunks)
  • tests/e2e/base.eslintrc.cjs (1 hunks)
  • tests/e2e/e2e.spec.ts (1 hunks)
  • tests/e2e/importXResolverV3/eslint.config.js (1 hunks)
  • tests/e2e/package.json (1 hunks)
  • tests/e2e/withJsExtension/.eslintrc.cjs (0 hunks)
  • tests/e2e/withJsExtension/index.ts (1 hunks)
  • tests/e2e/withJsExtension/test.cjs (2 hunks)
  • tests/e2e/withQuerystring/.eslintrc.cjs (1 hunks)
  • tests/e2e/withoutPaths/.eslintrc.cjs (1 hunks)
  • tests/importXResolverV3/eslint.config.cjs (0 hunks)
  • tests/nestedPackageJson/.eslintrc.cjs (0 hunks)
  • tests/pnp/pnp.spec.ts (0 hunks)
  • tests/tsconfig.json (1 hunks)
  • tests/unit/unit.spec.ts (1 hunks)
  • tests/withJsconfig/.eslintrc.cjs (0 hunks)
  • tsconfig.base.json (1 hunks)
  • tsconfig.json (1 hunks)
  • tsconfig.staged.json (1 hunks)
  • vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (7)
  • .vscode/settings.json
  • tests/e2e/withJsExtension/.eslintrc.cjs
  • .env.yarn
  • tests/withJsconfig/.eslintrc.cjs
  • tests/pnp/pnp.spec.ts
  • tests/importXResolverV3/eslint.config.cjs
  • tests/nestedPackageJson/.eslintrc.cjs
🚧 Files skipped from review as they are similar to previous changes (18)
  • tests/e2e/package.json
  • tests/e2e/withoutPaths/.eslintrc.cjs
  • tests/e2e/absoluteAlias/tsconfig.json
  • tests/e2e/withQuerystring/.eslintrc.cjs
  • tsconfig.staged.json
  • tests/tsconfig.json
  • tests/e2e/importXResolverV3/eslint.config.js
  • tsconfig.json
  • eslint.config.js
  • tsconfig.base.json
  • vitest.config.ts
  • .lintstagedrc.js
  • tests/e2e/e2e.spec.ts
  • .prettierignore
  • tests/e2e/withJsExtension/test.cjs
  • auto-imports.d.ts
  • tests/unit/unit.spec.ts
  • tests/e2e/withJsExtension/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
🔇 Additional comments (4)
tests/e2e/base.eslintrc.cjs (2)

35-43: Good improvement: Adding the import-x/order rule enhances code quality.

Adding the import-x/order rule with alphabetization and newlines between import groups will ensure consistent import ordering across the codebase. This improves readability and maintainability.


47-47: Good pattern update to include TypeScript CommonJS files.

Changing the file pattern from a potential dot-prefixed pattern to explicitly include both .cjs and .cts files ensures proper application of the ESLint rules to TypeScript CommonJS files.

package.json (2)

93-93: New devDependency: "@pkgr/core".
The addition of "@pkgr/core": "^0.2.0" in the devDependencies appears valid. Please confirm that the new dependency integrates well with your build or test workflows and that the version constraint aligns with your project's needs.


117-117: New devDependency: "unplugin-auto-import".
Adding "unplugin-auto-import": "^19.1.2" will help facilitate auto-imports for the Vitest testing utilities, as indicated by your TypeScript declarations. This is a useful enhancement that aligns with your testing infrastructure improvements.

@JounQin JounQin force-pushed the chore/split_e2e_unit branch from 628e792 to 5470f74 Compare March 29, 2025 12:58
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)
tests/unit/unit.spec.ts (2)

9-41: Consider optimizing the PnP test for reliability and speed

The test runs an actual yarn install command which makes it:

  1. Dependent on network connectivity
  2. Slower than a typical unit test (hence the 10s timeout)
  3. Potentially brittle if package versions change

Consider one of these approaches:

  • Mock the filesystem interactions to avoid actual yarn install
  • Use a pre-built fixture that can be copied rather than generated
  • Add cleanup logic to ensure the test environment is reset between runs
  • Consider caching the yarn install step to avoid redundant installations
 describe('createTypeScriptImportResolver', () => {
   const pnpDir = path.resolve(import.meta.dirname, 'pnp')
+  // Consider adding beforeAll/afterAll hooks for setup/cleanup
+  beforeAll(async () => {
+    // Check if already installed to avoid redundant operations
+    if (!existsSync(path.resolve(pnpDir, '.pnp.cjs'))) {
+      await exec('yarn', ['install'], {
+        nodeOptions: {
+          cwd: pnpDir,
+        },
+      })
+    }
+  })

   it(
     'should work with pnp',
     async () => {
-      await exec('yarn', ['install'], {
-        nodeOptions: {
-          cwd: pnpDir,
-        },
-      })

       const resolver = createTypeScriptImportResolver()

25-37: Consider using path-independent assertions

The inline snapshots contain absolute paths that might vary across different environments, potentially causing test failures.

Instead of using inline snapshots with specific paths, consider validating just the essential properties:

-      expect(resolver.resolve('pnpapi', testfile)).toMatchInlineSnapshot(`
-        {
-          "found": true,
-          "path": "<ROOT>/tests/unit/pnp/.pnp.cjs",
-        }
-      `)
+      const pnpapiResult = resolver.resolve('pnpapi', testfile);
+      expect(pnpapiResult.found).toBe(true);
+      expect(pnpapiResult.path).toMatch(/\.pnp\.cjs$/);

-      expect(resolver.resolve('lodash.zip', testfile)).toMatchInlineSnapshot(`
-        {
-          "found": true,
-          "path": "<ROOT>/tests/unit/pnp/.yarn/cache/lodash.zip-npm-4.2.0-5299417ec8-cb06530d81.zip/node_modules/lodash.zip/index.js",
-        }
-      `)
+      const lodashResult = resolver.resolve('lodash.zip', testfile);
+      expect(lodashResult.found).toBe(true);
+      expect(lodashResult.path).toMatch(/lodash\.zip.*index\.js$/);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 628e792 and 5470f74.

⛔ Files ignored due to path filters (8)
  • tests/e2e/__snapshots__/e2e.spec.ts.snap is excluded by !**/*.snap
  • tests/e2e/nestedPackageJson/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • tests/e2e/withQuerystring/image.svg is excluded by !**/*.svg
  • tests/e2e/withQuerystring/subfolder/image.svg is excluded by !**/*.svg
  • tests/unit/pnp/.yarn/cache/lodash.zip-npm-4.2.0-5299417ec8-cb06530d81.zip is excluded by !**/.yarn/**, !**/*.zip
  • tests/unit/pnp/.yarn/releases/yarn-4.8.0.cjs is excluded by !**/.yarn/**
  • tests/unit/pnp/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (27)
  • .env.yarn (0 hunks)
  • .lintstagedrc.js (1 hunks)
  • .prettierignore (1 hunks)
  • .vscode/settings.json (0 hunks)
  • auto-imports.d.ts (1 hunks)
  • eslint.config.js (2 hunks)
  • package.json (3 hunks)
  • tests/e2e/absoluteAlias/tsconfig.json (1 hunks)
  • tests/e2e/base.eslintrc.cjs (1 hunks)
  • tests/e2e/e2e.spec.ts (1 hunks)
  • tests/e2e/importXResolverV3/eslint.config.js (1 hunks)
  • tests/e2e/package.json (1 hunks)
  • tests/e2e/withJsExtension/.eslintrc.cjs (0 hunks)
  • tests/e2e/withJsExtension/index.ts (1 hunks)
  • tests/e2e/withJsExtension/test.cjs (2 hunks)
  • tests/e2e/withQuerystring/.eslintrc.cjs (1 hunks)
  • tests/e2e/withoutPaths/.eslintrc.cjs (1 hunks)
  • tests/importXResolverV3/eslint.config.cjs (0 hunks)
  • tests/nestedPackageJson/.eslintrc.cjs (0 hunks)
  • tests/pnp/pnp.spec.ts (0 hunks)
  • tests/tsconfig.json (1 hunks)
  • tests/unit/unit.spec.ts (1 hunks)
  • tests/withJsconfig/.eslintrc.cjs (0 hunks)
  • tsconfig.base.json (1 hunks)
  • tsconfig.json (1 hunks)
  • tsconfig.staged.json (1 hunks)
  • vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (7)
  • tests/nestedPackageJson/.eslintrc.cjs
  • .env.yarn
  • tests/e2e/withJsExtension/.eslintrc.cjs
  • .vscode/settings.json
  • tests/withJsconfig/.eslintrc.cjs
  • tests/importXResolverV3/eslint.config.cjs
  • tests/pnp/pnp.spec.ts
🚧 Files skipped from review as they are similar to previous changes (17)
  • tests/e2e/package.json
  • tests/e2e/absoluteAlias/tsconfig.json
  • tests/e2e/withoutPaths/.eslintrc.cjs
  • tsconfig.staged.json
  • tests/e2e/withQuerystring/.eslintrc.cjs
  • .lintstagedrc.js
  • vitest.config.ts
  • tsconfig.json
  • tests/tsconfig.json
  • tsconfig.base.json
  • tests/e2e/importXResolverV3/eslint.config.js
  • eslint.config.js
  • tests/e2e/e2e.spec.ts
  • .prettierignore
  • tests/e2e/base.eslintrc.cjs
  • auto-imports.d.ts
  • tests/e2e/withJsExtension/test.cjs
🔇 Additional comments (4)
tests/e2e/withJsExtension/index.ts (1)

3-3: Expanded import test cases for TSX files.

The addition of import './tsxImportee.js' complements the existing import of the JSX version, following the established pattern used for other import tests in this file. This ensures testing coverage for both extension resolution scenarios.

package.json (3)

63-63: Test script now correctly separates e2e and unit tests

The updated test script now explicitly runs the e2e test separately before running vitest, which aligns with the PR objective of splitting e2e and unit tests.

This separation makes the testing process more organized and potentially allows for more targeted test runs in the future.


93-93:

✅ Verification successful

New dependencies support the updated testing structure

The addition of these development dependencies supports the reorganized test structure:

  • @pkgr/core: Provides package management utilities
  • unplugin-auto-import: Enables automatic imports of testing utilities

These dependencies help streamline the testing infrastructure, particularly with auto-imports reducing the need for repetitive import statements in test files.

Also applies to: 117-117


🏁 Script executed:

#!/bin/bash
# Check how unplugin-auto-import is configured in the project
fd -t f -e ts -e js "vitest.config" .

Length of output: 56


Approved: Updated testing dependencies integrated successfully

The changes in package.json (lines 93 and 117) introducing the @pkgr/core and unplugin-auto-import dependencies are correctly supporting the updated testing structure. We confirmed the presence of a Vitest configuration file (vitest.config.ts), which indicates that the auto-import functionality is properly configured for the tests.


61-61:

❓ Verification inconclusive

Simplified prepare script removes nested package test

The prepare script has been simplified to only run git hooks and yarn deduplication.

Are the nested package JSON tests that were previously run during prepare now integrated into the regular test suite? Let's check:


🏁 Script executed:

#!/bin/bash
# Check if nestedPackageJson tests are now handled elsewhere
fd -t d "nestedPackageJson" tests
grep -r "nestedPackageJson" tests --include="*.ts" --include="*.js"

Length of output: 130


Action: Verify Integration of Nested Package JSON Tests

The simplified prepare script now only runs git hooks and deduplication. However, we still see an existing directory at tests/e2e/nestedPackageJson/, and our grep search didn’t reveal any explicit references to “nestedPackageJson” inside test files. This makes it unclear if those tests are now being executed as part of the regular test suite.

  • Verify that the tests in tests/e2e/nestedPackageJson/ are being picked up and run by your main test runner (e.g., check your test configuration like jest.config.js or similar).
  • If these tests are meant to be integrated into the regular suite, ensure that their execution is confirmed via the test runner’s output.
  • Otherwise, confirm that it is intentional to remove them from the prepare script and that their removal won’t reduce test coverage.

Please manually verify the integration of these tests to ensure the intended behavior.

@JounQin JounQin force-pushed the chore/split_e2e_unit branch from 5470f74 to 40fd25d Compare March 29, 2025 13:08
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 (1)
package.json (1)

61-61: Prepare Script Simplification
The prepare script has been simplified to run simple-git-hooks && yarn-berry-deduplicate || exit 0. Note that the || exit 0 ensures that even if one of these commands fails, the script exits with a success status. Please confirm that ignoring potential failures here is intentional; if not, consider removing the fallback so that errors propagate.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5470f74 and 40fd25d.

⛔ Files ignored due to path filters (8)
  • tests/e2e/__snapshots__/e2e.spec.ts.snap is excluded by !**/*.snap
  • tests/e2e/nestedPackageJson/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • tests/e2e/withQuerystring/image.svg is excluded by !**/*.svg
  • tests/e2e/withQuerystring/subfolder/image.svg is excluded by !**/*.svg
  • tests/unit/pnp/.yarn/cache/lodash.zip-npm-4.2.0-5299417ec8-cb06530d81.zip is excluded by !**/.yarn/**, !**/*.zip
  • tests/unit/pnp/.yarn/releases/yarn-4.8.0.cjs is excluded by !**/.yarn/**
  • tests/unit/pnp/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (27)
  • .env.yarn (0 hunks)
  • .lintstagedrc.js (1 hunks)
  • .prettierignore (1 hunks)
  • .vscode/settings.json (0 hunks)
  • auto-imports.d.ts (1 hunks)
  • eslint.config.js (2 hunks)
  • package.json (3 hunks)
  • tests/e2e/absoluteAlias/tsconfig.json (1 hunks)
  • tests/e2e/base.eslintrc.cjs (1 hunks)
  • tests/e2e/e2e.spec.ts (1 hunks)
  • tests/e2e/importXResolverV3/eslint.config.js (1 hunks)
  • tests/e2e/package.json (1 hunks)
  • tests/e2e/withJsExtension/.eslintrc.cjs (0 hunks)
  • tests/e2e/withJsExtension/index.ts (1 hunks)
  • tests/e2e/withJsExtension/test.cjs (2 hunks)
  • tests/e2e/withQuerystring/.eslintrc.cjs (1 hunks)
  • tests/e2e/withoutPaths/.eslintrc.cjs (1 hunks)
  • tests/importXResolverV3/eslint.config.cjs (0 hunks)
  • tests/nestedPackageJson/.eslintrc.cjs (0 hunks)
  • tests/pnp/pnp.spec.ts (0 hunks)
  • tests/tsconfig.json (1 hunks)
  • tests/unit/unit.spec.ts (1 hunks)
  • tests/withJsconfig/.eslintrc.cjs (0 hunks)
  • tsconfig.base.json (1 hunks)
  • tsconfig.json (1 hunks)
  • tsconfig.staged.json (1 hunks)
  • vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (7)
  • .vscode/settings.json
  • tests/e2e/withJsExtension/.eslintrc.cjs
  • .env.yarn
  • tests/nestedPackageJson/.eslintrc.cjs
  • tests/withJsconfig/.eslintrc.cjs
  • tests/pnp/pnp.spec.ts
  • tests/importXResolverV3/eslint.config.cjs
🚧 Files skipped from review as they are similar to previous changes (19)
  • tests/e2e/package.json
  • tests/e2e/withoutPaths/.eslintrc.cjs
  • tests/e2e/absoluteAlias/tsconfig.json
  • tsconfig.staged.json
  • tests/tsconfig.json
  • tests/e2e/withQuerystring/.eslintrc.cjs
  • eslint.config.js
  • vitest.config.ts
  • tests/e2e/withJsExtension/index.ts
  • tsconfig.json
  • .prettierignore
  • tests/unit/unit.spec.ts
  • .lintstagedrc.js
  • tests/e2e/base.eslintrc.cjs
  • tests/e2e/withJsExtension/test.cjs
  • tsconfig.base.json
  • auto-imports.d.ts
  • tests/e2e/importXResolverV3/eslint.config.js
  • tests/e2e/e2e.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
🔇 Additional comments (3)
package.json (3)

63-63: Test Script Update
The test script now sequentially runs an end-to-end test (node tests/e2e/withJsExtension/test.cjs) before executing vitest run for unit tests. Keep in mind that if the e2e test fails, the subsequent unit tests won’t run. Please verify that this behavior aligns with your testing strategy; if independent execution is desired, you might consider splitting these into separate scripts or using parallel execution.


93-93: New Dependency: @pkgr/core
A new devDependency, "@pkgr/core": "^0.2.0", has been added. Ensure that this package is required by your tooling or build process and that its usage is adequately documented.


117-117: New Dependency: unplugin-auto-import
The addition of "unplugin-auto-import": "^19.1.2" is aligned with enabling automatic imports (likely used in your vitest.config.ts). Please confirm that the version is compatible with your other dev tools and that its behavior is as expected.

@JounQin JounQin force-pushed the chore/split_e2e_unit branch from 40fd25d to 53ddbf7 Compare March 29, 2025 13:14
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 (5)
package.json (2)

61-61: Review the simplified prepare script and fallback behavior.
The updated script "prepare": "simple-git-hooks && yarn-berry-deduplicate || exit 0" is more concise; however, note that using || exit 0 will suppress any failure from the preceding commands. Please confirm that suppressing errors from yarn-berry-deduplicate is intended and that critical failures (if any) will not go unnoticed.


63-63: Verify the new test script's separation of e2e and unit tests.
The test script now executes "node tests/e2e/withJsExtension/test.cjs && vitest run", clearly separating e2e tests from unit tests. Ensure that if the e2e tests fail, the entire test process fails as expected and that the ordering meets your overall testing strategy.

tests/unit/unit.spec.ts (3)

7-15: Consider handling async setup more consistently

The test is using top-level await within the describe callback. While this works in environments that support top-level await in test files, it might be better to:

  1. Move the async setup into a beforeAll hook
  2. Add explicit error handling for the Yarn command
  3. Consider setting a specific timeout for this setup
-describe('createTypeScriptImportResolver', async () => {
+describe('createTypeScriptImportResolver', () => {
   const pnpDir = path.resolve(import.meta.dirname, 'pnp')
 
-  await exec('yarn', [], {
-    nodeOptions: {
-      cwd: pnpDir,
-    },
-  })
+  beforeAll(async () => {
+    try {
+      await exec('yarn', [], {
+        nodeOptions: {
+          cwd: pnpDir,
+        },
+      })
+    } catch (error) {
+      console.error('Failed to set up PnP environment:', error)
+      throw error
+    }
+  }, 30000) // Explicit timeout for Yarn command

18-34: Add timeout to PnP test case

The test relies on external module resolution which could potentially be slow. Add an explicit timeout to prevent test failures due to performance issues.

-  it('should work with pnp', async () => {
+  it('should work with pnp', async () => {
     const testfile = path.resolve(pnpDir, '__test__.js')
 
     expect(resolver.resolve('pnpapi', testfile)).toMatchInlineSnapshot(`
       {
         "found": true,
         "path": "<ROOT>/tests/unit/pnp/.pnp.cjs",
       }
     `)
 
     expect(resolver.resolve('lodash.zip', testfile)).toMatchInlineSnapshot(`
       {
         "found": true,
         "path": "<ROOT>/tests/unit/pnp/.yarn/cache/lodash.zip-npm-4.2.0-5299417ec8-cb06530d81.zip/node_modules/lodash.zip/index.js",
       }
     `)
-  })
+  }, 10000) // Add explicit timeout for potentially slow resolution

1-36: Consider adding cleanup and more robust testing

The test creates files but doesn't clean them up, which could affect subsequent test runs. Also, it only tests the "happy path" without testing error scenarios.

Consider adding:

  1. An afterAll hook to clean up after tests
  2. Additional test cases for error scenarios (e.g., resolving non-existent modules)
  3. Verification that testfile exists before using it
// Example afterAll hook to add
afterAll(async () => {
  // Clean up any files or directories created during testing if needed
})

// Example additional test case
it('should handle non-existent modules correctly', async () => {
  const testfile = path.resolve(pnpDir, '__test__.js')
  const result = resolver.resolve('non-existent-module', testfile)
  expect(result.found).toBe(false)
})
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 40fd25d and 53ddbf7.

⛔ Files ignored due to path filters (8)
  • tests/e2e/__snapshots__/e2e.spec.ts.snap is excluded by !**/*.snap
  • tests/e2e/nestedPackageJson/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • tests/e2e/withQuerystring/image.svg is excluded by !**/*.svg
  • tests/e2e/withQuerystring/subfolder/image.svg is excluded by !**/*.svg
  • tests/unit/pnp/.yarn/cache/lodash.zip-npm-4.2.0-5299417ec8-cb06530d81.zip is excluded by !**/.yarn/**, !**/*.zip
  • tests/unit/pnp/.yarn/releases/yarn-4.8.0.cjs is excluded by !**/.yarn/**
  • tests/unit/pnp/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (27)
  • .env.yarn (0 hunks)
  • .lintstagedrc.js (1 hunks)
  • .prettierignore (1 hunks)
  • .vscode/settings.json (0 hunks)
  • auto-imports.d.ts (1 hunks)
  • eslint.config.js (2 hunks)
  • package.json (3 hunks)
  • tests/e2e/absoluteAlias/tsconfig.json (1 hunks)
  • tests/e2e/base.eslintrc.cjs (1 hunks)
  • tests/e2e/e2e.spec.ts (1 hunks)
  • tests/e2e/importXResolverV3/eslint.config.js (1 hunks)
  • tests/e2e/package.json (1 hunks)
  • tests/e2e/withJsExtension/.eslintrc.cjs (0 hunks)
  • tests/e2e/withJsExtension/index.ts (1 hunks)
  • tests/e2e/withJsExtension/test.cjs (2 hunks)
  • tests/e2e/withQuerystring/.eslintrc.cjs (1 hunks)
  • tests/e2e/withoutPaths/.eslintrc.cjs (1 hunks)
  • tests/importXResolverV3/eslint.config.cjs (0 hunks)
  • tests/nestedPackageJson/.eslintrc.cjs (0 hunks)
  • tests/pnp/pnp.spec.ts (0 hunks)
  • tests/tsconfig.json (1 hunks)
  • tests/unit/unit.spec.ts (1 hunks)
  • tests/withJsconfig/.eslintrc.cjs (0 hunks)
  • tsconfig.base.json (1 hunks)
  • tsconfig.json (1 hunks)
  • tsconfig.staged.json (1 hunks)
  • vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (7)
  • .env.yarn
  • tests/e2e/withJsExtension/.eslintrc.cjs
  • .vscode/settings.json
  • tests/withJsconfig/.eslintrc.cjs
  • tests/nestedPackageJson/.eslintrc.cjs
  • tests/pnp/pnp.spec.ts
  • tests/importXResolverV3/eslint.config.cjs
🚧 Files skipped from review as they are similar to previous changes (18)
  • tests/e2e/package.json
  • tests/e2e/withoutPaths/.eslintrc.cjs
  • tsconfig.staged.json
  • tests/e2e/withQuerystring/.eslintrc.cjs
  • tests/tsconfig.json
  • tsconfig.json
  • tests/e2e/withJsExtension/index.ts
  • eslint.config.js
  • tests/e2e/e2e.spec.ts
  • tests/e2e/importXResolverV3/eslint.config.js
  • tests/e2e/base.eslintrc.cjs
  • tests/e2e/absoluteAlias/tsconfig.json
  • .lintstagedrc.js
  • tsconfig.base.json
  • .prettierignore
  • auto-imports.d.ts
  • vitest.config.ts
  • tests/e2e/withJsExtension/test.cjs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
🔇 Additional comments (4)
package.json (2)

93-93: Confirm the necessity of the new @pkgr/core dependency.
The new dev dependency "@pkgr/core": "^0.2.0" appears to have been added for build or packaging enhancements. Please verify that this package is required and that its version meets the project’s requirements.


117-117: Ensure proper integration of unplugin-auto-import.
The addition of "unplugin-auto-import": "^19.1.2" in devDependencies aligns with its usage in the testing configuration (e.g., in vitest.config.ts). Confirm that the auto-import configuration is updated accordingly and that it benefits the intended test automation.

tests/unit/unit.spec.ts (2)

1-5: LGTM: Import statements are clear and appropriate

The import statements are properly organized with Node.js built-ins first, followed by external dependencies, and finally the module under test.


9-9:

✅ Verification successful

Verify the PnP directory existence

Make sure the PnP directory exists before attempting to execute commands in it.


🏁 Script executed:

#!/bin/bash
# Check if the PnP directory exists in the expected location
if [ ! -d "tests/unit/pnp" ]; then
  echo "Error: PnP directory not found at tests/unit/pnp"
  exit 1
else
  echo "PnP directory exists at tests/unit/pnp"
  ls -la tests/unit/pnp
fi

Length of output: 727


PNP Directory Check Verified

The verification script confirmed that the "tests/unit/pnp" directory exists and contains the expected files. No further actions are required regarding the directory existence check in the tests.

@JounQin JounQin merged commit cb4f85f into master Mar 29, 2025
35 checks passed
@JounQin JounQin deleted the chore/split_e2e_unit branch March 29, 2025 13:18
@ljharb
Copy link
Member

ljharb commented Mar 29, 2025

Codecov has always been enabled for every repo in this org.

@JounQin
Copy link
Collaborator Author

JounQin commented Mar 29, 2025

Codecov has always been enabled for every repo in this org.

@ljharb Oh, great, then can you help to add CODECOV_TOKEN into the secrets?

error - 2025-03-29 13:59:45,680 -- Upload failed: {"message":"Token required because branch is protected"}

@ljharb
Copy link
Member

ljharb commented Mar 29, 2025

You can add yours in https://github.com/import-js/eslint-import-resolver-typescript/settings/secrets/actions - i use the tokenless one.

@JounQin
Copy link
Collaborator Author

JounQin commented Mar 29, 2025

You can add yours in import-js/eslint-import-resolver-typescript/settings/secrets/actions - i use the tokenless one.

image

@ljharb I don't have permission on Codecov's side.

@ljharb
Copy link
Member

ljharb commented Mar 29, 2025

k, done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add unit tests along with e2e tests
2 participants