Repository navigation
fix: ignore NODE_PATH when checking for jest-dom - #542
Open
schiller-manuel wants to merge 1 commit into
Open
schiller-manuel wants to merge 1 commit into
schiller-manuel wants to merge 1 commit into
Conversation
getJestDomExport checked for `@testing-library/jest-dom/vitest` with a `createRequire` rooted at the project (solidjs#364). `require.resolve` also searches NODE_PATH, which pnpm's bin shims (`pnpm vitest`) point at the hoisted virtual store (`node_modules/.pnpm/node_modules`). In a workspace where any package depends on jest-dom, the check found that copy for projects without it, and Vitest, which resolves `setupFiles` without NODE_PATH, failed to load the injected setup file. Backport the lookup from the `next` branch (d30f051): walk `node_modules` up from the root, then check the subpath against that copy of the package. Fixes solidjs#541 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: ee21af4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
3 of 5 tasks
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #541
Problem
Since #364,
getJestDomExportchecks for jest-dom withcreateRequire(<root>/package.json).resolve().require.resolvealso searchesNODE_PATH, and pnpm's bin shims (pnpm vitest) point it at the hoisted virtual store,node_modules/.pnpm/node_modules. In a pnpm workspace where any package depends on jest-dom, the check finds that copy for a project that doesn't have it. The plugin then injects@testing-library/jest-dom/vitest, and Vitest, which resolvessetupFileswithoutNODE_PATH, fails before any test runs:That is Vitest 3.0.7; Vitest 5 reports
Cannot find module '<project>/@testing-library/jest-dom/vitest'.Fix
A backport of the lookup the
nextbranch already has (d30f051, its forward-port of #364).findPackageDirwalks<dir>/node_modules/@testing-library/jest-domup from the root, as Vite does, and the subpath is then checked against the realpath of that copy. Both functions are copied unchanged fromnext. The injected specifier is still the bare one.Verification
src/jest-dom.test.ts: a project without jest-dom, withNODE_PATHset to this repo'snode_modules. Node readsNODE_PATHat startup, so the test recomputes the global paths withModule._initPaths()and restores them afterwards. It fails onmain(['@testing-library/jest-dom/vitest']is injected) and passes with the fix.pnpm run build,pnpm run test:unitandpnpm run test:jsdominexamples/vite-6pass (Node 24.8, pnpm 9.15.5).adepends on jest-dom,bis a Solid app without it, andcis a Solid app with it whose test callstoBeInTheDocument()without a setup file of its own. With 2.11.16,pnpm vitest runinbfails with the error above. With this branch linked in,bpasses, andcstill gets the setup file and passes.Not run: the browser-mode suite of
examples/vite-6(the plugin doesn't inject jest-dom in browser mode) and the Cypress example tests. In one of 23 fulltest:unitruns, right after the first build,src/transform-ids.test.tsfailed to load. I didn't capture the error; the 22 runs since passed, and that file doesn't involve jest-dom.🤖 Generated with Claude Code