Skip to content

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

@mcous

Description

@mcous

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?

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions