Skip to content

fix(vitest): add resolve.conditions to client test config #580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

AdrianGonz97
Copy link
Member

closes #579

It looks like our default config broke in [email protected]. Adding resolve.conditions to the client test config seemingly fixes it (as mentioned in the related issue), though I'm unsure if it's the right fix.

cc @dominikg @manuel3108

export default defineConfig({
	// ...
	test: {
		projects: [
			{
				extends: './vite.config.ts',
				plugins: [svelteTesting()],
+				resolve: { conditions: ['browser'] },
				test: {
					name: 'client',
					environment: 'jsdom',
					clearMocks: true,
					include: ['src/**/*.svelte.{test,spec}.{js,ts}'],
					exclude: ['src/lib/server/**'],
					setupFiles: ['./vitest-setup-client.ts']
				}
			},
			{
				extends: './vite.config.ts',
				test: {
					name: 'server',
					environment: 'node',
					include: ['src/**/*.{test,spec}.{js,ts}'],
					exclude: ['src/**/*.svelte.{test,spec}.{js,ts}']
				}
			}
		]
	}
});

Copy link

changeset-bot bot commented Jun 6, 2025

🦋 Changeset detected

Latest commit: 5b5d640

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

This PR includes changesets to release 1 package
Name Type
sv 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

Copy link

pkg-pr-new bot commented Jun 6, 2025

Open in StackBlitz

npx https://pkg.pr.new/sveltejs/cli/sv@580
npx https://pkg.pr.new/sveltejs/cli/svelte-migrate@580

commit: 5b5d640

@iain3000
Copy link

iain3000 commented Jun 6, 2025

Adding resolve.conditions to the client test config seemingly fixes it (as mentioned in the related issue), though I'm unsure if it's the right fix.

For clarity, the resolve fix was sourced from the svelte testing docs so hopefully it's at least partially correct :)

@dominikg
Copy link
Member

dominikg commented Jun 7, 2025

we want to rework the template based on https://scottspence.com/posts/migrating-from-testing-library-svelte-to-vitest-browser-svelte

also if the output we currently do works in vitest 3.1 and breaks in 3.2 thats potentially a bug/regression in vitest. we should not have to mess with conditions anymore

@dominikg
Copy link
Member

dominikg commented Jun 7, 2025

(the testing docs are due for an update as well, sveltejs/svelte#14243 (comment))

@manuel3108
Copy link
Member

Should we go ahead with this or wait on the upstream fix, where @dominikg created the issue? (vitest-dev/vitest#8120)

@manuel3108
Copy link
Member

BTW, also glad to see that vitest-ecosystem-ci failed for our run https://github.com/vitest-dev/vitest-ecosystem-ci/actions/runs/15483387187/job/43593197840

@dominikg
Copy link
Member

dominikg commented Jun 8, 2025

i'd rather see the jsdom setup replaced with browser-mode as mentioned above, also there is https://sveltest.dev now 🥳

can't tell what other effects these missing conditions have so maybe pinning vitest to 3.1 for the time being would be the better choice.

@AdrianGonz97
Copy link
Member Author

Closing in favor of #584

@manuel3108 manuel3108 deleted the fix/vitest-add-on branch June 8, 2025 21:33
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.

Bug: mount(...) is not available on the server error when running tests after a fresh install
4 participants