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

Browser mode fails with SyntaxError: Failed to construct 'WebSocket' #5382

Closed
6 tasks done
kossnocorp opened this issue Mar 14, 2024 · 4 comments · Fixed by #5595
Closed
6 tasks done

Browser mode fails with SyntaxError: Failed to construct 'WebSocket' #5382

kossnocorp opened this issue Mar 14, 2024 · 4 comments · Fixed by #5595
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@kossnocorp
Copy link

Describe the bug

After upgrading Vitest in the date-fns codebase (vitest@0.34.6 -> vitest@1.3.1 & @vitest/browser@0.34.6 -> @vitest/browser@1.3.1) I started getting many of these errors:

SyntaxError: Failed to construct 'WebSocket': The URL 'ws://localhost:undefined/' is invalid.
❯ setupWebSocket /@vite/client:505:20
❯ fallback /@vite/client:484:22
❯ WebSocket.<anonymous> /@vite/client:520:13

As the result npx vitest run --browser hangs forever, even though the tests pass when I open it with --ui.

Reproduction

git clone git@github.com:date-fns/date-fns.git
cd date-fns
npm install
npm install -D @vitest/ui
npx vitest --browser --ui

It will open the browser where you can see the errors:

image

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.1 LTS (Focal Fossa)
    CPU: (12) x64 AMD Ryzen 5 5600X 6-Core Processor
    Memory: 15.01 GB / 31.31 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.asdf/installs/nodejs/20.10.0/bin/node
    Yarn: 1.22.21 - ~/.asdf/installs/nodejs/20.10.0/bin/yarn
    npm: 10.2.3 - ~/.asdf/plugins/nodejs/shims/npm
    bun: 1.0.25 - ~/src/date-fns/date-fns/node_modules/.bin/bun
  Browsers:
    Chrome: 103.0.5060.114
  npmPackages:
    @vitest/browser: ^1.3.1 => 1.3.1 
    @vitest/coverage-v8: ^1.3.1 => 1.3.1 
    vitest: ^1.3.1 => 1.3.1

Used Package Manager

npm

Validations

@hi-ogawa hi-ogawa added feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Mar 14, 2024
@hi-ogawa
Copy link
Contributor

hi-ogawa commented Mar 14, 2024

I tested locally and I can reproduce. I'm not really sure yet but maybe spwaning too many iframes is causing some problems.

I tweaked some config and isolate: false seems to work, but fileParallelims: false doesn't seem to help even though the tests look proceeding slower.
If no isolation is acceptable, then you may use npx vitest --browser --no-isolate instead for now.

@kossnocorp
Copy link
Author

@hi-ogawa thank you! Yeah, isolate: false works for date-fns. Appreciate the tip!

@kunokareal
Copy link

kunokareal commented Mar 18, 2024

a similar issue seems to be happening on a smaller number of tests (~1k) when running in firefox, but works fine in chrome. isolate: false does help

image

@underoot
Copy link

Also reproduced issue, noticed that it's begins only when number of files larger than 127
https://github.com/underoot/vitest-large-file-list-issue

@github-actions github-actions bot locked and limited conversation to collaborators May 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants