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

vitest hangs when using adapter-cloudflare #12305

Open
wooseopkim opened this issue Jun 6, 2024 · 7 comments · May be fixed by #12306 or #12830
Open

vitest hangs when using adapter-cloudflare #12305

wooseopkim opened this issue Jun 6, 2024 · 7 comments · May be fixed by #12306 or #12830

Comments

@wooseopkim
Copy link

wooseopkim commented Jun 6, 2024

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
Copy link
Author

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
Copy link
Author

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
Copy link

Oreoezi commented Jul 9, 2024

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"

@bdmackie
Copy link

bdmackie commented Oct 7, 2024

I have also hit the issue. It renders unit testing unusable with no obvious workaround except for downgrading to 4.1.0 which is getting a fair way behind the latest.

@eltigerchino
Copy link
Member

These are the logs when it hangs (after upgrading everything to the latest).

❯ npm run test -- --run

> [email protected] test
> vitest --run


 RUN  v2.1.3 /home/chewteeming/github/sveltekit-vitest-repro

 ✓ src/index.test.js (1)
   ✓ sum test (1)
     ✓ adds 1 + 2 to equal 3

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  13:44:29
   Duration  239ms (transform 11ms, setup 0ms, collect 9ms, tests 2ms, environment 0ms, prepare 61ms)

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/#reporter

@eltigerchino eltigerchino linked a pull request Oct 18, 2024 that will close this issue
6 tasks
@knicholson32
Copy link

My current temporary solution is to switch to adapter-auto when running vitest based on process.env.VITEST:

// svelte.config.js

import { default as auto} from '@sveltejs/adapter-auto';
import { default as cf } from '@sveltejs/adapter-cloudflare';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

const config = {
  preprocess: vitePreprocess(),

  kit: {
    adapter: process.env.VITEST ? auto() : cf()
  }
};

export default config;

@bdmackie
Copy link

Thanks @knicholson32. That works, however it does require a different approach to passing env vars. e.g. using .env.local with the .dev.vars subsets you need in tests, loading env from vite.config.ts, prepending with VITE_ and checking for VITE_ prefix in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants