sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.22k stars 1.85k forks source link

`vitest` hangs when using `adapter-cloudflare` #12305

Open wooseopkim opened 1 month ago

wooseopkim commented 1 month ago

Describe the bug

Everything seems okay when using adapter-auto. However vitest hangs With adapter-cloudflare. I saw this issue and tried pool: 'forks' but it didn't fix the problem.

Reproduction

https://github.com/wooseopkim/sveltekit-vitest-repro

This repository contains source code generated with npm create svelte@latest just with the additional dependency of @sveltejs/adapter-cloudflare. Run npm run test -- --run to see the problem.

Logs

Below is the output with hanging-reporters in vite.config.js.

There are 8 handle(s) keeping the process running

# Tinypool
node:internal/async_hooks:202                                                                                
node:internal/async_hooks:505                                                                                
file:///home/<user>/Workspace/sveltekit-vitest-repro/node_modules/tinypool/dist/esm/index.js:37              
file:///home/<user>/Workspace/sveltekit-vitest-repro/node_modules/tinypool/dist/esm/index.js:58              
file:///home/<user>/Workspace/sveltekit-vitest-repro/node_modules/tinypool/dist/esm/index.js:952             
file:///home/<user>/Workspace/sveltekit-vitest-repro/node_modules/vitest/dist/vendor/cli-api.E07AF1Yq.js:8192
file:///home/<user>/Workspace/sveltekit-vitest-repro/node_modules/vitest/dist/vendor/cli-api.E07AF1Yq.js:8845
file:///home/<user>/Workspace/sveltekit-vitest-repro/node_modules/vitest/dist/vendor/cli-api.E07AF1Yq.js:8870

# FILEHANDLE
node:internal/async_hooks:202

# FILEHANDLE
node:internal/async_hooks:202

# FILEHANDLE
node:internal/async_hooks:202

# FILEHANDLE
node:internal/async_hooks:202

# FILEHANDLE
node:internal/async_hooks:202

# FILEHANDLE
node:internal/async_hooks:202

# FILEHANDLE
node:internal/async_hooks:202
close timed out after 10000ms
Tests closed successfully but something prevents Vite server from exiting
You can try to identify the cause by enabling "hanging-process" reporter. See https://vitest.dev/config/#reporters

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (12) x64 AMD Ryzen 5 7600 6-Core Processor
    Memory: 47.86 GB / 54.93 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.14.0 - ~/.volta/tools/image/node/20.14.0/bin/node
    Yarn: 4.2.2 - ~/.volta/tools/image/yarn/4.2.2/bin/yarn
    npm: 10.7.0 - ~/.volta/tools/image/node/20.14.0/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.2.1 
    @sveltejs/adapter-cloudflare: ^4.4.0 => 4.4.0 
    @sveltejs/kit: ^2.0.0 => 2.5.10 
    @sveltejs/package: ^2.0.0 => 2.3.1 
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.1.1 
    svelte: ^4.2.7 => 4.2.17 
    vite: ^5.0.11 => 5.2.12 

Severity

annoyance

Additional Information

No response

wooseopkim commented 1 month ago

Adding statement await proxy.dispose(); here seems to fix this problem, but leads to another (and more serious) problem - dev server loses connection to local Miniflare.

wooseopkim commented 1 month ago

I've found a better, potential fix: moving this line into the vite.middlewares.use block. I have no idea what the side effects are as of now, though.

Oreoezi commented 2 weeks ago

I know this is a ridiculous fix but

"test:unit": "sed -i '1s/.*/import adapter from \"@sveltejs\\/adapter-auto\";/' svelte.config.js && vitest run && sed -i '1s/.*/import adapter from \"@sveltejs\\/adapter-cloudflare\";/' svelte.config.js"