Closed sureshjoshi closed 1 year ago
I'm trying to figure out if it's related to vitest or something else, because creating a trivial reproduction case (e.g. Svelte skeleton app, upgraded to vitest 0.32) - everything works as expected.
Is there any sort of trace logs to flag where store creation occurs?
I started manually calling console.trace
in the lib, and there seems to be some weird race condition, or maybe just an async condition:
// Enable Svelte Store testing mode (adds a "reset" method to all stores)
import { enableStoreTestingMode } from "@square/svelte-store";
enableStoreTestingMode()
// Import the i18n module and set the locale to "en"
import "$lib/i18n"; // Import to initialize.
Somehow the import of that library is beating out the call to enableStoreTestingMode
...
I'm sure this comes down to how imports are handled, and how eager/lazily they're handled. Fortunately, the fix is easy (and more correct, to be honest) - which is to push my import of that i18n
module (which uses a persisted
store) into beforeAll
.
I've been trying to get
enableStoreTestingMode
running on my tests, however, I can't seem to figure out where it can be placed to not cause an exception.I've tried to place it in my setup file, in various unit test files, or anywhere else. I'm wondering if it's related to when vitest runs its setupFiles. Maybe my application is being launched before setupFiles runs?
Working on a small reproduction repo.
Using vitest, in
vite.config.ts
, I havesetup-dom-env.ts
in setupFiles, so it should run before any of my tests:In
setup-dom-test.ts
:Alternate approach, using the
beforeAll
hook.