vite: run vitest tests inside env-runner runtimes (miniflare, ...)

Open
#4,749 0 comments 0 reactions 1 assignee View on GitHub

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

vite

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 with start/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 }) from vitest/worker.
  • Main challenge: the Vitest worker runtime imports node:vm, node:async_hooks and chai, writes snapshots, and evaluates modules with new 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 whether vitest/worker can 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

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nitrojs/nitro

All issues in nitrojs/nitro

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.