vitest-dev / vitest-dev/vitest
`@vitest/web-worker` error when using browser environment
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 94
Description
Describe the bug
I'm trying to get test coverage output with istanbul but I've found out vitest can't see codes executed in web workers (per #2911). So I figured I could wrap my worker with @vitest/web-worker and execute it in main thread. However, since that worker executes WebAssembly I want to keep using browser environment.
Now, in theory I don't see any problem with this approach but I'm getting a dynamic import error.
TypeError: Failed to fetch dynamically imported module: http://localhost:5173/home/foo/workspace/bar/node_modules/@vitest/web-worker/dist/index.js?v=1704701752071
This could be just a configuration error on my side, maybe there is a way to bundle this worker wrapper in browser environment but that didn't shine any ideas to my mind.
Reproduction
If the problem is not obvious I'll create a reproduction project
System Info
System:
OS: Linux 6.2 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
CPU: (32) x64 Intel(R) Core(TM) i9-14900K
Memory: 54.16 GB / 62.57 GB
Container: Yes
Shell: 5.8.1 - /usr/bin/zsh
Binaries:
Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
Browsers:
Chrome: 120.0.6099.129
npmPackages:
@vitejs/plugin-react: ^4.2.1 => 4.2.1
@vitest/browser: ^1.1.3 => 1.1.3
@vitest/coverage-istanbul: ^1.1.3 => 1.1.3
@vitest/coverage-v8: ~1.1.3 => 1.1.3
@vitest/ui: ~1.1.3 => 1.1.3
@vitest/web-worker: ^1.1.3 => 1.1.3
vite: ^5.0.11 => 5.0.11
vitest: ~1.1.3 => 1.1.3
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reducing the browser-environment setup to a minimal reproduction using @vitest/web-worker and a WebAssembly-executing worker. Then trace the dynamic import of @vitest/web-worker from the browser entry point; done means the worker wrapper loads and executes successfully while browser testing and coverage remain usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vite, wasm
- Domain
- testing-qa, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100