Repository navigation
fix(vitest): load client solid-js in node-env files of DOM test runs - #535
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: d373e4f 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 |
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 #534.
Since 2.11.15, a test file with
// @vitest-environment nodeloads the server build of solid-js whentest.environmentisjsdomorhappy-dom. In that fileisServeristrueand effects never run.Root cause
The fix for #125 (765a406) removed the
browsercondition from the wholessrenvironment in DOM test runs, so that Node would not getbrowserin its--conditions. But Vitest runs per-filenodeenvironment files in thessrenvironment, and solid-js is inlined there, so Vite resolved it withoutbrowserand picked the server build.Vitest builds Node's
--conditionsfrom the resolvedconfig.ssr.resolve.conditions(Vitest 3 and 5 both read it). Vite 6, 7 and 8 fill that field from a separate copy of thessrenvironment's conditions, and Vite does not read it again after resolving.Change
configEnvironmentaddsbrowserto thessrenvironment in test mode again, as 2.11.14 did. It is no longer added a second time when the list already has it.configResolvedremovesbrowserfromconfig.ssr.resolve.conditionsonly, which is the list Vitest passes to Node. Thessrenvironment keeps it. Abrowsercondition the user set onssris left in place, and nothing changes if that field turns out to be the same object as the environment's.Node-env files then load the client build of solid-js, and
msw/nodestill loads in both node and DOM files.Verification
The reporter's setup (vite 8.3.6, vitest 5.1.0, happy-dom 21.0.4, solid-js 1.9.18), with node-env and DOM files plus
msw/nodeimports in each, run against the packed plugin:msw/nodefilesA mixed suite of 25 DOM files and 25 node-env files passes three runs out of three, with and without
--no-isolate. On 2.11.15 only the node-env files failed. I could not reproduce the intermittent DOM-file failures described in the issue.New tests, which fail without the fix:
examples/vite-6/tests/jsdom/node-environment.test.tsx, a// @vitest-environment nodefile in the jsdom suite (pnpm test:jsdom).src/test-config.test.ts(pnpm test:unit, 17/17 pass).examples/vite-6/tests/node-conditions.mjs, updated: thessrenvironment keepsbrowserand Node's conditions do not.The browser-mode example suite did not run locally because the Playwright browser was missing. It runs in the
clientenvironment, which this change does not touch.Open
The plugin keeps its test-mode flags on the plugin instance across
config,configEnvironmentandconfigResolved. If two config resolutions run at once on one instance they can read each other's flags. ThedomTestRuntimeInlinedflag from 2.11.15 already had this, and this PR does not change it.🤖 Generated with Claude Code