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

Svelte 4 support #121

Closed
rallets opened this issue Jun 26, 2023 · 7 comments · Fixed by #133
Closed

Svelte 4 support #121

rallets opened this issue Jun 26, 2023 · 7 comments · Fixed by #133
Labels
enhancement New feature or request

Comments

@rallets
Copy link

rallets commented Jun 26, 2023

Hi, I'm wondering if this library is still maintained.
Svelte 4 has been released few days ago, and I needed to change how the tests were written, to be able to get them to work.
Is this something it's planned on your side?
Thanks

@sebastianrothe
Copy link
Collaborator

Hey, yes it is. I saw the v4 release and plan to have a look at what must be changed.

If you just want to test and dont rely on jest, you should consider vitest, which proves to be very good with ESM format.

@sebastianrothe sebastianrothe added the enhancement New feature or request label Jun 26, 2023
@rallets
Copy link
Author

rallets commented Jun 26, 2023

Hi, glad to hear that. I just changed a bit here and there to make them work, nothing blocking on my side. So I don't see any value for me currently to switch to vitest, but thanks anyway on the tip, really appreciated.
FYI I had problems with

  • running tests that depend on svelte/store
  • running tests that import Svelte components.
    The problem looks like is raised from how the code is transpiled/compiled in the new Svelte.
    Basically I test just pure functions and it works well.

@tarun-khanna
Copy link

Hey @sebastianrothe, any update here on svelte v4 support ?
Facing similar issues mentioned by @rallets

@sebastianrothe
Copy link
Collaborator

Sorry, I was busy with other projects. If someone can jump in with a PR, please go ahead.

@sebastianrothe
Copy link
Collaborator

sebastianrothe commented Jul 11, 2023

Just reading through https://svelte.dev/docs/v4-migration-guide#removal-of-cjs-related-output means it will be more difficult to support CJS. It needs to use a bundler like esbuild to convert the output to CJS. It also means that the codebase could be converted to ESM entirely.

The old version will still support both formats if you use Svelte < 4.

@benmccann
Copy link
Collaborator

benmccann commented Jul 21, 2023

As of right now, you'll need to use ESM with Svelte 4. Though there's an issue about CJS support for Svelte 4: #166

To use ESM with Svelte 4:

  • If you're using svelte-jester, upgrade to 3.x+
  • Ensure your project has "type": "module" in its package.json
  • Set NODE_OPTIONS=--experimental-vm-modules and the "extensionsToTreatAsEsm": ['.svelte', '.ts'] Jest config option as described in Jest's docs as well as any other changes Jest requires such as updating your calls to jest.mock
  • If you're using ts-jest, set the useESM option referred to in their ESM docs
  • If you're using @testing/library-svelte, update it to 4.x+

I upgraded a random library I found, svelte-credit-card, as an example and there's also a sveltekit example in this repo.

You may also consider migrating to vitest, which generally works much better in my experience and is the officially recommended unit testing solution. There's a tool to automatically migrate though I've not tried it myself

@sebastianrothe
Copy link
Collaborator

Released as v3.0.0 https://www.npmjs.com/package/svelte-jester

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

Successfully merging a pull request may close this issue.

4 participants