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

Call compileModule for .svelte.js files in Svelte 5 #282

Closed
mcous opened this issue May 15, 2024 · 8 comments
Closed

Call compileModule for .svelte.js files in Svelte 5 #282

mcous opened this issue May 15, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@mcous
Copy link
Contributor

mcous commented May 15, 2024

Howdy! I'm working on full Svelte 5 support over in @testing-library/svelte and I discovered that our suite fails with Svelte 5 + Jest + svelte-jester.

In Svelte 5, we rely on the $state rune to be able to re-render the component under test. This logic is placed in a .svelte.js file. However, if I try to send .svelte.js files through svelte-jester...

transform: {
  '^.+\\.svelte(?:\\.js)?$': ['svelte-jester'],
},

...Svelte becomes quite unhappy.

I gave vite-plugin-svelte a quick read, and discovered a new (to me) part of the transformation pipeline. It looks like there's a new compiler function - compileModule - used to compile .svelte.js files.

TL;DR: svelte-jester should probably know how to call compileModule for Svelte 5 support.

I've got a very rough proof-of-concept locally that adds enough support to get our test suite passing. Is this something you'd accept a PR for?

@mcous
Copy link
Contributor Author

mcous commented Jun 10, 2024

Hi @sebastianrothe, I hope you had a good weekend! Do you think you'll have time this week for these Svelte 5 PRs? I'm getting eager to ship proper Svelte 5 support in @testing-library/svelte, and I would prefer not to break Jest support while doing so

@sebastianrothe
Copy link
Collaborator

Hi @sebastianrothe, I hope you had a good weekend! Do you think you'll have time this week for these Svelte 5 PRs? I'm getting eager to ship proper Svelte 5 support in @testing-library/svelte, and I would prefer not to break Jest support while doing so

Yes, I am finally on it this evening.

@sebastianrothe
Copy link
Collaborator

I need to figure out tomorrow, how to release a next-Release for you to test.

@mcous
Copy link
Contributor Author

mcous commented Jun 10, 2024

Great! Let me know if I can help. For the time being, I'll try out a local build + tarball and report back

@sebastianrothe
Copy link
Collaborator

I think you can also use the git repo and main branch as a version number.

@mcous
Copy link
Contributor Author

mcous commented Jun 11, 2024

I think you can also use the git repo and main branch as a version number.

Unfortunately, due to the build step, this doesn't work. The GitHub repo has no dist directory, where the main export is output by rollup

I'll try out a local build + tarball and report back

Everything is checking out locally on my end! In Svelte 5, I am now able to specify...

{
  transform: {
    '^.+\\.svelte(?:\\.js)?$': 'svelte-jester',
  },
}

...in Svelte 5 and the v5 syntax (runes) works outside Svelte components as expected

@sebastianrothe
Copy link
Collaborator

Great, I will create a release with version number 5.

@sebastianrothe
Copy link
Collaborator

Published as 5.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

No branches or pull requests

2 participants