Skip to content

fix: don't resolve setupFiles from parent directory#9960

Merged
sheremet-va merged 3 commits intovitest-dev:mainfrom
hi-ogawa:fix-don-t-resolve-from-parent-directory
Mar 24, 2026
Merged

fix: don't resolve setupFiles from parent directory#9960
sheremet-va merged 3 commits intovitest-dev:mainfrom
hi-ogawa:fix-don-t-resolve-from-parent-directory

Conversation

@hi-ogawa
Copy link
Collaborator

@hi-ogawa hi-ogawa commented Mar 24, 2026

Description

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link

netlify bot commented Mar 24, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 3f08647
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69c1ef3f3abea80008a5ce71
😎 Deploy Preview https://deploy-preview-9960--vitest-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.

@hi-ogawa hi-ogawa force-pushed the fix-don-t-resolve-from-parent-directory branch from 1e57d1d to bb6e5e8 Compare March 24, 2026 02:04
@hi-ogawa hi-ogawa marked this pull request as ready for review March 24, 2026 02:33
Comment on lines 31 to +42
function resolvePath(path: string, root: string) {
// local-pkg (mlly)'s resolveModule("./file", { paths: ["/some/root"] }) tries
// /some/file
// /some/file.js
// /some/root/file
// /some/root/file.js
// etc.
// but we don't want to resolve files from parent directories,
// so we ensure passing "/" suffix such as "/some/root/"
// https://github.com/unjs/mlly/blob/401d42983f6f3a9112658d67b0a92ba4fb1d7efa/src/resolve.ts#L104-L110
return normalize(
/* @__PURE__ */ resolveModule(path, { paths: [root] })
/* @__PURE__ */ resolveModule(path, { paths: [join(root, '/')] })
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a way more annoying than I thought. My first solution was merely doing:

if (path[0] === '.' || path[0] === '/') {
  return normalize(resolve(root, path))
}
return (...same as before...)

but this broke a following test since it was relying on resolveModule to resolve /(full)/file-setup.js:

export default defineConfig({
test: {
setupFiles: ['./file-setup'],
server: {
deps: {
// try to force setup file to be external
external: [/file-setup/]

So, I went back to still rely on resolveModule for relative path.

@sheremet-va sheremet-va merged commit 7aa9377 into vitest-dev:main Mar 24, 2026
15 of 16 checks passed
@hi-ogawa hi-ogawa deleted the fix-don-t-resolve-from-parent-directory branch March 24, 2026 08:49
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.

Fails to run with setupFile when inside git worktree

2 participants