Skip to content

Vitest 5, with a workaround for its browser-mode define bug - #45

Merged
dillonroller merged 1 commit into
mainfrom
deps-vitest-5
Sep 14, 2026
Merged

dillonroller merged 1 commit into
mainfrom
deps-vitest-5

Conversation

@dillonroller

Copy link
Copy Markdown
Contributor

Supersedes #17, dependabot's bump of the svelte group: vitest and @vitest/browser-playwright to 5.0.0, vitest-browser-svelte to 3.1.0.

Why #17 couldn't just merge: Vitest 5.0.0 has a bug (vitest-dev/vitest#11164) where a browser test project's define values are injected at runtime a second time, taken literally. SvelteKit's defines are already JSON strings, so its base path arrives as the text "" and resolve('/') returns ""#/, which failed the three Nav component tests. The fix (vitest-dev/vitest#11198) merged on 2026-09-08, but 5.0.0 is still the latest release.

The workaround: the upstream fix gives browser projects no runtime defines, since in the browser Vite already provides them correctly. vite.config.ts gets a small plugin on the client test project that does the same thing after Vitest resolves the config. No dependency is patched. I traced the exact code path in 5.0.0 before choosing this; an earlier idea, moving SvelteKit's plugin off the root config, didn't help because the browser project takes a different branch.

Verified: all 60 unit tests pass with the plugin, and without it exactly the three Nav tests fail. The Nav tests are the regression check. The gotcha is noted in the svelte-ui skill with the instruction to delete the plugin once Vitest is past 5.0.0.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GoPfSTf4CwmHMTKzLxLfQR

Bumps vitest and @vitest/browser-playwright to 5.0.0 and
vitest-browser-svelte to 3.1.0 (dependabot #17).

Vitest 5.0.0 injects a browser project's own `define` values at runtime as
literal strings (vitest-dev/vitest#11164). SvelteKit's are already
stringified, so `__SVELTEKIT_PATHS_BASE__` arrived as '""' and
`resolve('/')` as '""#/', failing the Nav component tests. In the browser
Vite already provides the defines, and the upstream fix
(vitest-dev/vitest#11198, merged after 5.0.0) gives browser projects no
runtime defines. A tiny plugin on the client test project does the same
in `configResolved`, so no dependency is patched. Without it the three
Nav tests fail; with it all 60 unit tests pass. Delete it once Vitest is
past 5.0.0 (noted in the svelte-ui skill).

Supersedes #17.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GoPfSTf4CwmHMTKzLxLfQR
@dillonroller
dillonroller merged commit 4f6225f into main Sep 14, 2026
2 checks passed
@dillonroller
dillonroller deleted the deps-vitest-5 branch September 14, 2026 21:21
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