-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Unable to test files with $app/stores import after migrating to new vite.config.js format #5525
Comments
I know Storybook has to do some stuff to disable HMR. I'd hope the Vitest setup wouldn't have to be as complicated though |
That doesn't really help me figure out how to disable hot module reloading. I looked at the So what would I pass to Or is vitest not meant to be used w/ sveltekit anymore? I don't care either way, I was just trying to "stay within the ecosystem" and trying vitest out. |
I see this in the link you provided: sveltejs/vite-plugin-svelte#321 (comment) I was under the assumption that vite-plugin-svelte isn't being used anymore because create-svelte doesn't put it in the generated vite.config.js file. |
I'm guessing that this was caused by the new version of |
That didn't change the output at all. And I looked at the type info for Option and vitePlugin isn't mentioned. Though this implies that it does exist: https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#config-file-resolving Do i need to install vite-plugin-svelte manually? |
Oh, you're using outdated dependencies. I sent you a PR to update: illogic-al/store-test#1 I'm not seeing anything related to HMR, so I think that was a red herring and the real issue is related to I haven't used Vitest myself, so don't have much experience with this. @Davidpon do you have any experience using stuff from |
So, I went back and looked at my branch. I also was using the vitest-svelte-kit package (kit 357 -> 372, see package-lock file for other versions. Given that I wasn't using stock packages I can't actually claim this was working with sveltekit + vitest before, and given the code I see in the vitest-svelte-kit src, it probably wasn't working. I don't knoe if this becomes a feature request for svelte or vitest, but if it is a svelte thing, I could try my hand at making the changes (w/ some guidance) :-) |
Ah, yeah, that's why it was working for you. That package provides some mocks: nickbreaton/vitest-svelte-kit#16 (comment) I'm going to close this as a duplicate of #1485, which was asking for the mocking ability |
I haven't tested with runtime modules like // setupTest.js for Vitest
vi.mock('$app/stores', async () => {
const { readable, writable } = await import('svelte/store');
/**
* @type {import('$app/stores').getStores}
*/
const getStores = () => ({
navigating: readable(null),
page: readable({ url: new URL('http://localhost'), params: {} }),
session: writable(null),
updated: readable(false)
});
/** @type {typeof import('$app/stores').page} */
const page = {
subscribe(fn) {
return getStores().page.subscribe(fn);
}
};
/** @type {typeof import('$app/stores').navigating} */
const navigating = {
subscribe(fn) {
return getStores().navigating.subscribe(fn);
}
};
/** @type {typeof import('$app/stores').session} */
const session = {
subscribe(fn) {
return getStores().session.subscribe(fn);
}
};
/** @type {typeof import('$app/stores').updated} */
const updated = {
subscribe(fn) {
return getStores().updated.subscribe(fn);
}
};
return {
getStores,
navigating,
page,
session,
updated
};
}); BTW, the person you tagged wasn't me 😅. |
@davipon That did indeed work, thanks for that! And now that I know these have to be mocked I can do so next time. Thanks again! |
What's the current state here? Wondering if there's now a solution without mocking? |
This works for me, thanks! |
Describe the bug
I had previously set up a project with vitest and, after migrating this project to the new vite.config.js I kept getting the error:
[HMR][Svelte] Unrecoverable HMR error in <Header>: next update will trigger a full reload
with the following backtrace:I assume this has something to do with HMR not working the same now as it did with the old
svelte.config.js
method but I am not certain.I tried adding the following to disable HMR in vite but it didn't change the outcome.
I'm pretty new to sveltekit and svelte so it's entirely possible I'm donig something wrong, but given that this worked before the config format change, and doesn't now, that's the likely culprit in my mind. Minimal repo that allows you to reproduce the issue is given below
Reproduction
pnpm i
to install dependencies.vite test
The error I showed above will be present in the terminal. Again, this was not occurring pre @sveltejs/[email protected]
Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
No response
The text was updated successfully, but these errors were encountered: