-
Notifications
You must be signed in to change notification settings - Fork 18
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
Support SvelteKit #46
Conversation
- add cjs file support - add esbuild for esm and ts files - use new jest runner - exclude fixtures - use v8 for coverage to support esm
This is awesome, thanks @sebastianrothe! I'm out of the loop on all of this so if I understand correctly this will only work with Jest 27+? I'm considering releasing it as a breaking change so major bump. |
No, this has been tested with Jest v26. For v27 we need to make more changes, but in #25. This PR brings the compatibility for SvelteKit, which requires ESM for some parts. The thing is Jest 26 does not understand ESM, thats why only the async call to |
LGTM! |
Thanks again for the PR @sebastianrothe. I've released everything in |
Thanks! If there are any issues, I will gladly provide some support. |
I upgraded from 1.5.0 to 1.6.0 and am having my very simple Hello component test failing now. Here is the error and my jest config is seen at https://github.com/HVSBible/hvsb/blob/main/tests/jest.svelte.cjs#L20 - note that I'm using a workaround dummy svelte config. Using that with 1.6.0 or also the |
I see. Will have a look tonight. |
@JWRunner If i run your repo with |
Discussion continues in #47 |
@JWRunner Can you try again with version |
That fixed things. Thanks! I was traveling. |
The main problem was, that cosmiconf could not import ESmodules within the
svelte.config.js
from SvelteKit. SvelteKit requires these imports (e.g. adapter) to be in ESM format. That's why the preprocess file has to be in ESM format as well. All other files still have to be commonJS, because otherwise jest won't be able to call them from the transformer (this might change in jest next).To support ESmodules I had to bump the node version to 14+. It might be possible to call node with some experimental flags, if someone needs to use and old version of node. I thought v10 is deprecated and v14 is the current LTS version, so it is okay to require v14.
Jest won't understand ESM natively and so we need to transform ESmodules files with esbuild/babel. For this to work, I had to introduce a jest config file. I used jest-circus as the new runner and added v8 as a provider which understands ESM as well.
Since the config files from Svelte and SvelteKit differ so much, I had to duplicate all tests to cover both scenarios.
notable changes:
I hope it still works for all people and settings out there. The tests run and our project with SvelteKit does as well.
This is also a preparation for #25 where we can try to convert all files to ESM and then use the async transformer from the next jest version.
Fixes #44 and #6