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

Abierto
#4,749 0 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 2 días

@pi0x ya está trabajando en esto.

Desde el 8/10/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
11.5k
Forks
968
Merge medio
4 d 9 h
PR fusionados (30 d)
64

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de nitrojs/nitro

Todos los issues de nitrojs/nitro

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.