Skip to content
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

Merged
merged 19 commits into from
May 25, 2021
Merged

Support SvelteKit #46

merged 19 commits into from
May 25, 2021

Conversation

sebastianrothe
Copy link
Collaborator

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:

  • added vscode extension recommendations and settings
  • renamed js files to cjs
  • duplicated tests for svelte and sveltekit (moved test suite into a base file)
  • removed cosmiconf (node can import them dynamically)
  • extract compiler from transformer to be able to reuse more code for the async transfomer Use jest async transformers when available #25

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

@mihar-22
Copy link
Collaborator

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.

@sebastianrothe
Copy link
Collaborator Author

sebastianrothe commented May 25, 2021

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 preprocess.js had to be converted to ESM.
The other problem was with Cosmiconfig, which I removed and used the capabilities from node.

@mihar-22
Copy link
Collaborator

LGTM!

@mihar-22 mihar-22 merged commit 0c008d7 into svelteness:master May 25, 2021
@mihar-22
Copy link
Collaborator

Thanks again for the PR @sebastianrothe. I've released everything in 1.6.0 👍

@sebastianrothe
Copy link
Collaborator Author

Thanks again for the PR @sebastianrothe. I've released everything in 1.6.0 👍

Thanks! If there are any issues, I will gladly provide some support.

@jacob-8
Copy link

jacob-8 commented May 25, 2021

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 preprocess: true option both throw the same error.

@sebastianrothe
Copy link
Collaborator Author

sebastianrothe commented May 25, 2021

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 preprocess: true option both throw the same error.

I see. Will have a look tonight.

@sebastianrothe
Copy link
Collaborator Author

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 preprocess: true option both throw the same error.

I see. Will have a look tonight.

@jwrunner If i run your repo with preprocess: true, it works for me (node 16). Btw, I think you don't need your https://github.com/HVSBible/hvsb/blob/main/tests/jest-config-hack/svelte.config.js anymore. 1.6.0 supports EMS config files.

@sebastianrothe
Copy link
Collaborator Author

Discussion continues in #47

@sebastianrothe sebastianrothe deleted the sveltekit branch May 29, 2021 21:34
@sebastianrothe
Copy link
Collaborator Author

@jwrunner Can you try again with version 1.7.0, please ?

@jacob-8
Copy link

jacob-8 commented Jun 9, 2021

@jwrunner Can you try again with version 1.7.0, please ?

That fixed things. Thanks! I was traveling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Svelte-kit support
3 participants