Skip to content

fix: forward-port #364 (jest-dom root resolution) + #323 (respect vitest projects environments) - #367

Merged
ryansolid merged 4 commits into
nextfrom
fwdport-364-323
Sep 18, 2026
Merged

ryansolid merged 4 commits into
nextfrom
fwdport-364-323

Conversation

@ryansolid

Copy link
Copy Markdown
Member

Forward-ports two open main-line fixes onto the @solidjs/vite-plugin 3.0.0-next line. Two patch changesets, one per fix.

1. jest-dom setup file resolved from the project root — port of #364 (@brenelz), fixes #231

getJestDomExport probed @testing-library/jest-dom/vitest with the plugin's own require (from import.meta.url). Under pnpm's isolated node_modules that succeeds whenever any package in the tree depends on jest-dom transitively (Storybook in the issue), while Vitest resolves bare setupFiles from the project root, where it isn't installed → Failed to load url .../@testing-library/jest-dom/vitest. Reproduced on next with a packed tarball (see below).

The next-specific posture logic around the injection (server-posture skip, browser-mode skip) is unchanged; the probe now takes the Vite root (userConfig.root, falling back to process.cwd()), as in #364.

Divergence from #364: #364 uses createRequire(path.join(root, 'package.json')).resolve(...). That still gives a false positive on the most common command path: require.resolve also consults NODE_PATH, and pnpm's bin shims (pnpm vitest / pnpm test) export NODE_PATH=…/node_modules/.pnpm/node_modules — the hoisted virtual store where every transitive dep is reachable. Vite's resolver ignores NODE_PATH, so the injected setup file still failed to load under the shim (verified: the faithful port passed a plain node probe but pnpm vitest run still failed). The port therefore walks <dir>/node_modules/@testing-library/jest-dom up from the root (what Vite/Node do without NODE_PATH), then checks the subpath (/vitest, then v5's /extend-expect) against that exact copy. The bare specifier is still what gets injected, for the reason documented in #364. Worth back-porting to main as well.

2. No jsdom default when test.projects / test.workspace is set — port of #323 (@carloitaben), fixes #205

A root config that defines test.projects (or the pre-Vitest-4 test.workspace) runs no tests itself; each project controls its own environment. Injecting environment: 'jsdom' at the root made vitest probe for (and prompt to install) jsdom on startup even when every project runs under node or in browser mode. Same one-line guard as #323, folded into next's existing browser-mode guard.

Note (same on main with #323): an inline project with extends: true inherits the root file's test.projects, so such a project also opts out of the jsdom default unless it declares environment itself — matching vitest's projects guide, where projects declare their environment explicitly. Documented in the code comment.

Also checked

Tests

  • New regression assertions in examples/start-ssr/test/run.mjs (vitest mode), both at config-resolution level:
    • projects-env: root config with test.projects resolves with no test.environment.
    • jest-dom-root: an empty project outside the repo, resolved in a child process whose NODE_PATH points at the repo's node_modules (simulating both the plugin-local resolution and the pnpm shim), gets no setupFiles; the example root (whose ancestors hold the repo's jest-dom) still gets @testing-library/jest-dom/vitest.
    • Both fail against the pre-fix build (environment: jsdom / ["@testing-library/jest-dom/vitest"] for the empty root) and pass with it.
  • pnpm build, tsc --noEmit, examples/vite-8 vitest (browser mode) and the root pnpm test cypress run pass.
  • Scratch repros with the packed tarball (pnpm, before → after):
    • jest-dom only transitive via a local file: dep, default jsdom environment: pnpm vitest run failed with Cannot find module '.../@testing-library/jest-dom/vitest' → passes with no setup file injected. With jest-dom as a direct dep (v6 and v5) the setup file is still injected and toBeInTheDocument works (v6).
    • test.projects with a node project and a project with no environment: root test.environment jsdomundefined; the node project runs under node in both cases; the environment-less project now runs under node instead of failing on the missing jsdom package.

ryansolid and others added 2 commits September 18, 2026 02:44
…pace is set

Forward-port of #323 (@carloitaben, fixes #205) to the 3.0.0-next line.

A root vitest config that defines `test.projects` (or the pre-vitest-4
`test.workspace`) runs no tests itself; each project controls its own
environment. Injecting the jsdom default at the root made vitest probe
for (and prompt to install) jsdom on startup even when every project
runs under node or in browser mode.

Adds a config-resolution assertion to the start-ssr vitest suite.
Forward-port of #364 (@brenelz, fixes #231) to the 3.0.0-next line.

getJestDomExport probed `@testing-library/jest-dom/vitest` with the
plugin's own `require` (created from import.meta.url), so under pnpm's
isolated node_modules it reported the package available whenever ANY
package in the tree depended on jest-dom transitively (Storybook in the
issue). Vitest resolves bare `setupFiles` from the project root, where it
isn't installed, and failed with
`Failed to load url .../@testing-library/jest-dom/vitest`.

Divergence from #364: instead of a `createRequire` rooted at the project,
the probe walks `<dir>/node_modules/@testing-library/jest-dom` up from the
Vite root (the way Vite/Node resolve without NODE_PATH). `require.resolve`
also consults NODE_PATH, and pnpm's bin shims (`pnpm vitest`, `pnpm test`)
export NODE_PATH=node_modules/.pnpm/node_modules — the hoisted virtual
store where every transitive dependency is reachable — so the root-derived
require still found the transitive copy under the shim while vitest did
not. The subpath (`/vitest`, then v5's `/extend-expect`) is then checked
against that exact package copy. The bare specifier is still what gets
injected.

Adds a config-resolution assertion to the start-ssr vitest suite that
covers both false-positive paths (plugin-local resolution and NODE_PATH).

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Sep 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bdcc964

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/vite-plugin Patch

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

@pkg-pr-new

pkg-pr-new Bot commented Sep 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@solidjs/vite-plugin@367

commit: bdcc964

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	examples/start-ssr/test/run.mjs
@ryansolid
ryansolid merged commit 31e96dc into next Sep 18, 2026
6 checks passed
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.

1 participant