For each Vitest project, depending on its configured isolation and concurrency, start one or more workerd ↗ processes, each running one or more Workers.
Run setupFiles ↗ and test files in workerd using the appropriate Workers.
Watch for changes and re-run test files using the same Workers if the configuration has not changed.
Isolation model
Storage isolation is per test file. Each test file gets its own storage environment, and any writes to storage during a test file are not visible to other test files. The Workers Vitest integration reuses Workers and their module caches between test runs where possible. A copy of all auxiliary workers exists in each workerd process.
By default, test files run concurrently. To make test files share the same storage (for example, for integration tests that depend on shared state), use the Vitest flags --max-workers=1 --no-isolate.
Modules
Each Worker has its own module cache. As Workers are reused between test runs, their module caches are also reused. Vitest invalidates parts of the module cache at the start of each test run based on changed files.
The Workers Vitest plugin runs code inside a Cloudflare Worker that Vitest would usually run inside a Node.js Worker thread ↗. To make this possible, the plugin automatically injects the nodejs_compat, [no_nodejs_compat_v2] and export_commonjs_default compatibility flags. This is the minimal compatibility setup that still allows Vitest to run correctly, but without pulling in polyfills and globals that are not required. If you already have a Node.js compatibility flag defined in your configuration, the Vitest plugin does not add those flags.