vite: run vitest tests inside env-runner runtimes (miniflare, ...)
Maintainers usually reply within 2 days
@pi0x is already working on this.
Since Oct 8, 2026.
Assessment
This issue has not been assessed yet.
Description
Follow-up to #4748. Vitest tests in a project using the nitro() Vite plugin always run in Vitest's Node.js workers, and the devServer.runner option (and presets that set it, like miniflare for Cloudflare) is ignored. Code that needs the real platform, such as cloudflare:workers imports or bindings, can't be tested.
Proposal
Run test files inside the env-runner runtime (miniflare, Bun, Deno, ...), similar to how @cloudflare/vitest-pool-workers works for Cloudflare.
- Host side: a custom Vitest pool. Vitest 5's pool API (
createPoolWorker()returning a worker withstart/stop/send/on) would start an env-runner runner and forward Vitest's worker messages to it. - Runtime side: a worker entry that wires env-runner's message channel to the experimental
init({ post, on, runTests, collectTests })fromvitest/worker. - Main challenge: the Vitest worker runtime imports
node:vm,node:async_hooksand chai, writes snapshots, and evaluates modules withnew AsyncFunction, which workerd does not allow without miniflare's unsafe-eval binding. env-runner already has a workerd-safe evaluator for the dev worker, but the Vitest runner, mocker and snapshot code would need shims or replacements per runtime. A first spike should check whethervitest/workercan run in workerd at all.
Fallback
If this turns out to be very complex, a smaller alternative: keep test files in Node.js, but route serverFetch to the app running in the real env-runner dev worker (started from configureVitest via the existing initEnvRunner(), URL passed to tests with project.provide()). Requests then run in the real runtime with its bindings, while direct runtime calls in tests and vi.mock stay in Node.js, so it suits integration tests rather than unit tests.
Opened with AI assistance.
- Dominant language
- TypeScript
- Stars
- 11.5k
- Forks
- 968
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 64
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from nitrojs/nitro
-
pending triage
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 2 days
-
cloudflare: `nitro deploy` fails when a parent directory has a Wrangler configPossibly taken @draarivpatel-ui claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 2 days
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
pending triage
Difficulty 5/5 Over a week Newbie friendliness 30/100
nitrojs/nitro#5205 · 1 reaction ·
Maintainers usually reply within 2 days
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ranxianglei/billion-context#8319 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JimLiu/open-artifact#126 ·
-
bug repro-ready
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
mksglu/context-mode#1454 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
laststance/design-world#98 ·
Maintainers usually reply within 1 day
-
Add: KCM True crimeOpenapproved check:passed streams:add
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day