Skip to content

fix: resolve setupFile edge cases#780

Merged
9aoy merged 2 commits intomainfrom
setup-file-resolve
Dec 17, 2025
Merged

fix: resolve setupFile edge cases#780
9aoy merged 2 commits intomainfrom
setup-file-resolve

Conversation

@9aoy
Copy link
Collaborator

@9aoy 9aoy commented Dec 17, 2025

Summary

fix resolve setupFile edge cases

  • should resolve setup file correctly when setupFile is pure es module
  • should resolve setup file correctly when setupFile path with file protocol

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings December 17, 2025 09:53
@netlify
Copy link

netlify bot commented Dec 17, 2025

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit 7c4e1ca
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/69427d9f1d2eea00085178c4
😎 Deploy Preview https://deploy-preview-780--rstest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

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 fixes edge cases in setup file resolution by refactoring the getSetupFiles function into a separate module with enhanced resolver capabilities. The changes enable support for pure ES modules and file:// protocol paths in setup file configurations.

Key Changes:

  • Replaced Node.js createRequire resolver with rspack's enhanced resolver to support ESM-first resolution with proper condition names
  • Added support for file:// protocol paths by converting them using fileURLToPath before resolution
  • Moved getSetupFiles to a separate module with dynamic imports to defer expensive rspack loading

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/core/src/utils/getSetupFiles.ts New module with enhanced setup file resolver using rspack's ResolverFactory for ESM support
packages/core/src/utils/testFiles.ts Removed old getSetupFiles implementation (moved to separate module)
packages/core/src/core/runTests.ts Changed to dynamic import of getSetupFiles for lazy loading
packages/core/src/core/listTests.ts Changed to dynamic import of getSetupFiles for lazy loading
e2e/setup/index.test.ts Added test cases for file:// protocol and pure ESM setup files
e2e/setup/fixtures/package-name/rstest.fileProtocol.config.ts Test config using import.meta.resolve with file:// protocol
e2e/setup/fixtures/package-name/rstest.esm.config.ts Test config for pure ESM package resolution
e2e/setup/fixtures/package-name/test-setup-esm-fixtures/package.json ESM-only package.json with "import" condition in exports
e2e/setup/fixtures/package-name/test-setup-esm-fixtures/index.js Setup file for ESM test case
pnpm-lock.yaml Added entry for new test fixture package
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const esmFirstResolver = new resolver.ResolverFactory({
conditionNames: ['node', 'import', 'require'],
});
const { path: resolvedPath } = esmFirstResolver.sync(rootPath, request);
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The return value destructuring assumes resolver.sync always returns an object with a 'path' property. If the resolver returns undefined, null, or an object without a 'path' property, this will cause a runtime error. Add validation to check if the resolved result is valid before destructuring.

Copilot uses AI. Check for mistakes.
@9aoy 9aoy merged commit 855c787 into main Dec 17, 2025
23 checks passed
@9aoy 9aoy deleted the setup-file-resolve branch December 17, 2025 11:24
@9aoy 9aoy mentioned this pull request Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant