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

オープン
#4,749 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@pi0x がすでに取り組んでいます。

2026年10月8日 から。

評価

この issue はまだ評価されていません。

説明

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.

主要言語
TypeScript
スター
11.5k
フォーク
968
平均マージ
4日 9時間
マージ済み PR(30日)
64

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nitrojs/nitro のほかの issue

nitrojs/nitro の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。