vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
13.19k stars 1.2k forks source link

workspace + browser mode + watch leave server behind when root config changes #6738

Closed unional closed 3 weeks ago

unional commented 1 month ago

Describe the bug

Running vitest worspace (in watch mode) with a project is using browser mode.

When a root config is changed vitest detects the change and try to restart. But it doesn't first kill the previous browser runner, causing eventual failure:


Restarting due to config changes...

 DEV  v2.1.3 /home/unional/code/repobuddy/storybook
      [sb] Browser runner started by playwright at http://localhost:5173/

Port 5173 is in use, trying another one...

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: [vitest-api]: Timeout calling "createTesters"
 ❯ Object.onTimeoutError node_modules/.pnpm/@vitest+browser@2.1.3_@vitest+spy@2.1.3_playwright@1.48.1_typescript@5.6.3_vite@5.4.9_@types+node@22.7.5__vitest@2.1.3/node_modules/@vitest/browser/dist/index.js:577:17
 ❯ Timeout._onTimeout node_modules/.pnpm/@vitest+browser@2.1.3_@vitest+spy@2.1.3_playwright@1.48.1_typescript@5.6.3_vite@5.4.9_@types+node@22.7.5__vitest@2.1.3/node_modules/@vitest/browser/dist/index.js:240:41
 ❯ listOnTimeout node:internal/timers:573:17
 ❯ process.processTimers node:internal/timers:514:7

 ELIFECYCLE  Command failed with exit code 1.

Reproduction

TBD, I have a repro but need to clean it up.

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
    Memory: 28.36 GB / 31.31 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 20.10.0 - /run/user/1000/fnm_multishells/621_1729231040440/bin/node
    npm: 10.2.3 - /run/user/1000/fnm_multishells/621_1729231040440/bin/npm
    pnpm: 9.12.1 - /run/user/1000/fnm_multishells/621_1729231040440/bin/pnpm
    bun: 1.0.22 - ~/.bun/bin/bun
  npmPackages:
    @vitejs/plugin-react: ^4.3.2 => 4.3.2 
    @vitest/browser: ^2.1.3 => 2.1.3 
    vite: ^5.4.9 => 5.4.9 
    vitest: ^2.1.3 => 2.1.3

Used Package Manager

pnpm

Validations

sheremet-va commented 1 month ago

The problem is not that it doesn't kill the runner, because it does kill it. The problem is with the RPC - we don't stop it. Until recently, there was no way to do it, but with https://github.com/antfu/birpc/pull/21 we might be able to fix this. This would require an additional try/catch in the pool though.

xenobytezero commented 1 month ago

I have just hit something similar, where when running Vitest in watch mode and Browser Mode, I can re-run tests multiple times with no issue, but as soon as I attach a debugger and re-run the tests I get the above Timeout calling "createTesters" error.

Is this a similar issue? Has something changed recently, as I have been successfully doing this with 2.1.2 for a while now, and suddenly it has stopped working. Updating to 2.1.4 makes no difference