I've been doing a Svelte project for work, and therefore experimenting with it in my free time. I noticed that after generating a brand new project, using the Svelte instructions, the unit test command does not work.

I got so frustrated with this I opened up a bug report.

The error I see is something like this:

12:55:39 PM [vite] (ssr) Error when evaluating SSR module /@fs/C:/Projects/blog/svelte-test-2/node_modules/@sveltejs/kit/src/runtime/server/index.js: transport was disconnected, cannot call "fetchModule"

It turns out the issue goes away if I tell the tests to use the headless browser. Change the vite.config.ts to make this happen. Find code like this:

view plain print about
1browser: {
2    enabled: true,
3    provider: 'playwright',
4    instances: [{ browser: 'chromium' }]
5},

And change the instances section, to add the headless option:

view plain print about
1browser: {
2    enabled: true,
3    provider: 'playwright',
4    instances: [{ browser: 'chromium', headless: true }]
5},

That solved the problem for me. Although, sometimes I like to use the headful browser to debug unit tests, so this is not quite perfect. But, at least I can keep moving forward with my own experiments.