-
Notifications
You must be signed in to change notification settings - Fork 33
Svelte 5 rendering in Nx #403
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
Comments
@DannyvanHolten I see that you're not using the Svelte testing plugin, as mentioned in the README. This plugin is required to ensure the browser version of Svelte is loaded into Vitest rather than its server-side-rendering bundle. The clue that you're loading the wrong Svelte bundle is in this log:
Try adding in the Svelte testing plugin and let me know how that works: // ...
import { svelteTesting } from '@testing-library/svelte/vite'
// ...
export default defineConfig({
// ...
plugins: [
// ...
svelteTesting(),
],
// ...
}); |
Ah sorry, I had implemented this, and thought I was very careful :D. But after some tinkering I removed it in my example. In the actual code it was still present, and unfortunately is not the fix :( I edited my example to be correct |
Shoot, well that was the obvious idea. Are you able to provide a minimal reproduction repository (or stackblitz or whatever) demonstrating the issue? With that I could try to help diagnose |
I will try so tomorrow :). We will first try to get a complete install of everything to see if we can find the problem. |
Hey @mcous, Hereby a minimal reproduction repository: https://github.com/playerfine/svelte5unittestingexample/ If there are any questions lemme know 😄 |
@playerfine there's a bit too much going on in that repo for me to figure out the issue. Could you pare it back to be a lot more minimal? e.g. ditch all the build stuff, the TypeScript stuff, so that all that remains is the problematic workspace and test setup itself FWIW, I pulled |
Sorry for the delay, @mcous. I removed as much of the Nx configuration as possible and completely removed TypeScript. if you encounter anymore issues a simple If not feel free to reach out! Thanks for your help so far 😄 |
@playerfine @DannyvanHolten looks like a potential bug in See playerfine/svelte5unittestingexample#1 for more details:
|
Ok, traced it down specifically to the heuristics that the Svelte Vite plugin uses to add dependencies to export default defineConfig({
// ...
test: {
server: {
deps: {
inline: ['@testing-library/svelte'],
}
}
}
}) Since we have our own Vite plugin, I'm adding this same workaround in #404 just in case it can't be fixed in the Svelte-plugin proper |
This also seems to work fine thanks again! |
🎉 This issue has been resolved in version 5.2.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@DannyvanHolten @playerfine thanks for y'all's feedback on this issue! I was able to track down and learn about a few relevant Vite and Svelte behaviors and improve this library a little bit as a result! Recap of issues you were experiencing:
Resolutions:
|
Uh oh!
There was an error while loading. Please reload this page.
Hey Team,
I have been spending some time already in trying to get svelte-testing-library to work in my monorepo.
However I am failing to do so. I will try to outline the details as best as I can below.
The error message.
When I run my test
nx test ui-component
(which is just a nx command for running the vitest command). I get the following error.When I remove this $state part from the render function inside modern.svelte.js (line 26( I get the following error:
To me this sounds like something is wrong with getting svelte to load correctly. I am in the myst about what I should do, and how to fix it. I have tried looking thoroughly at my vite configs, tsconfigs, etc. But I cannot copy the tutorials one on one as we're using Nx.
Below I will share some code / config
The test (nothing wrong with this, it works in other setups):
The component itself (cannot be wrong I guess, works in Storybook)
My vite.config.ts
My tsconfig:
My packages:
Do you have any idea why this error is popping up? And how I can fix it.
The text was updated successfully, but these errors were encountered: