-
Notifications
You must be signed in to change notification settings - Fork 5
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
Compatibility with import.meta #14
Comments
I'll take a look into this and see what we can do |
After looking into this further, On the point of creating a svelte example, this is something we can most likely do. Thoughts? @fractalhq |
After even more investigation, here are a few points I've found:
|
Opened a related issue in |
I got import.meta working by using
There were a slew of other problems beyond that - such as mocking sveltekit's default context so things like Which were solved by mocks like these:
Mocking the sveltekit context was a bit tricky, so wanted to share for anyone else who comes down this path. This is set up and working in this example repo here: https://github.com/CloudNativeEntrepreneur/sveltekit-eventsourced-funnel |
Now using https://github.com/CloudNativeEntrepreneur/sveltekit-eventsourced-funnel/blob/master/.babelrc |
|
Raising a PR to implement the Vite specific transformations, beyond this will depend on the outcome of sveltejs/kit#1485 For now, the solution to using sveltekit runtime modules appears to be a mixture of:
|
jestjs/jest#9430 makes several references to |
Tried using On the point of Vite specific variables not being populated, this is also correct. The only property that I'm observing within |
I believe the latter when in tests - looks like I have jest.json as follows:
with the babel settings:
Which works, and from what I understand it replaces https://www.npmjs.com/package/babel-plugin-transform-vite-meta-env/v/1.0.1 When I remove babel from the equations, by deleting
repro: CloudNativeEntrepreneur/sveltekit-eventsourced-funnel#42 maybe I'm missing something - such as a way to make sure those env vars are set in tests. |
I wasn't able to get those mocks to work in the same way with ESM modules (though it did fix the build that broke with sk updates in another project that hasn't been updated to ESM/jest@27/svelte-jester@2 yet - and thus uses this mocking strategy), but to be fair that was like 48 hours ago, or something, before new ESM mocking features landed in jest (jestjs/jest#10025 (comment)), which I haven't tried yet. |
Yeah, from what I can gather, The problem we face is essentially setting up the environment around testing, i.e.: populating the vite specific variables based on some form of configuration when outside of Vite -- and also being able to mock sveltekit runtime modules without having to perform a build and subsequently point Jest to the output directory for module resolution. |
Yeah, I think there's a couple ways to do test setup:
I'm not sure what the tradeoffs are and which is the better approach. Also, if there's anything SvelteKit can do to make testing easier I'd be happy to support changes there. I'm glad you guys are paving the way on testing! |
I concur 😄 From a testing standpoint, being able to drive It'd be nice if Sveltekit had first-class support for testing, similar to Testing will definitely go a long way in increasing enterprise support and adoption. Having it as an integrated part of the sveltekit experience would be nice. I'm just happy to be of some use, I'll keep my eyes peeled for developments in the Jest ESM world in the meantime. |
To be clear, the I had provided some of the example mocks, and plan on trying out the |
A notion of a sveltekit testing adapter could be an interesting prospect, i.e.: a jest or jasmine adapter that is capable of transforming svelte projects into a format that jest or jasmine, respectively, can interpret and setup, all while hiding behind the facade of a command such as |
The primary discussion on Vite: vitejs/vite#1955.
Based on vitejs/vite#1955 (comment), the community seems to have settled around
vite-jest
, available on NPM npmjs.com/package/vite-jest.@rossyman - I'm thinking this might be the move, what do you think?
As an aside- it could be a good idea to submit a PR for a Svelte example if nobody has jumped on that yet.
The text was updated successfully, but these errors were encountered: