Skip to content

Support Vitest 4 in @cloudflare/vitest-pool-workers#11632

Merged
penalosa merged 74 commits intomainfrom
penalosa/vitest-v4-support
Mar 10, 2026
Merged

Support Vitest 4 in @cloudflare/vitest-pool-workers#11632
penalosa merged 74 commits intomainfrom
penalosa/vitest-v4-support

Conversation

@penalosa
Copy link
Contributor

@penalosa penalosa commented Dec 12, 2025

Fixes #11064
Fixes #10260 (tests added to verify the mentioned libraries can be imported)
Fixes #9957 (provide data moved from HTTP headers to WebSocket messages, removing the ~8 KB size limit)
Fixes #8369 (defineWorkersConfig is removed)
Fixes #7795 (everything is now encapsulated in a plugin, and so this type of configuration problem is impossible)
Fixes #7717 (leaked FSWatcher from Pages ASSETS binding is now closed via AbortSignal on pool worker stop)
Fixes #7339 (we no longer recommend importing env from cloudflare:test. Instead, import env from cloudflare:workers and use withEnv to override the value: https://developers.cloudflare.com/workers/runtime-apis/bindings/#overriding-env-values)
Fixes #7324 (nodejs_compat_v2 and Node module flags are now forcibly enabled during tests)
Fixes #7288 (new WorkersSnapshotEnvironment proxies snapshot file operations over a service binding)
Fixes #6465 (workerd resolve condition is explicitly included, node condition is removed)
Fixes #6214 (bare Node.js specifiers like "url" are resolved by prepending node: in the module fallback)
Fixes #5592 (SSR optimizer replaced with server.deps.inline = true, so Stripe resolves to its worker build)
Fixes #5396 (module graph is now populated via standard Vitest PoolWorker RPC — the UI should work)
Fixes #11690, fixes #11031, fixes #7707, fixes #5524 (Per-test isolated storage is completely removed, and so the entire mechanism that caused this is gone)
Fixes #6391 (fetch mock is now removed entirely)

This a breaking change to the @cloudflare/vitest-pool-workers integration in order to support Vitest v4. Along with supporting Vitest v4 (and dropping support for Vitest v2 and v3), we've made a number of changes that may require changes to your tests. Our aim has been to improve stability & the foundations of @cloudflare/vitest-pool-workers as we move towards a v1 release of the package.

We've made a codemod to make the migration easier: wrangler codemod vitest-pool-v3-to-v4, which will make the required changes to your config file.

  • isolatedStorage & singleWorker: These have been removed in favour of a simpler isolation model that more closely matches Vitest. Storage isolation is now on a per test file basis, and you can make your test files share the same storage by using the Vitest flags --max-workers=1 --no-isolate
  • import { env, SELF } from "cloudflare:test": These have been deprecated in favour of import { env, exports } from "cloudflare:workers". exports.default.fetch() has the same behaviour as SELF.fetch(), except that it doesn't expose Assets. To test your assets, use the env.ASSETS bindings or write an integration test using startDevWorker() (recommended)
  • import { fetchMock } from "cloudflare:test": This has been removed. Instead, mock globalThis.fetch or use ecosystem libraries like MSW (recommended).

A picture of a cute animal (not mandatory, but encouraged)
IMG_20170827_223510_169 2

@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2025

🦋 Changeset detected

Latest commit: 405a192

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Dec 12, 2025
@penalosa penalosa force-pushed the penalosa/vitest-v4-support branch 4 times, most recently from 107ac9f to e018115 Compare December 17, 2025 22:22
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 17, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@11632

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@11632

miniflare

npm i https://pkg.pr.new/miniflare@11632

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@11632

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@11632

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@11632

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@11632

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@11632

wrangler

npm i https://pkg.pr.new/wrangler@11632

commit: e8bf541

@penalosa penalosa force-pushed the penalosa/vitest-v4-support branch from e28ec0a to d45260d Compare December 18, 2025 15:10
@claude
Copy link
Contributor

claude bot commented Dec 18, 2025

Claude encountered an error —— View job


Reviewing Changesets

  • Read changeset guidelines
  • Review .changeset/many-fishes-raise.md
  • Review .changeset/wrangler-codemod-command.md
  • Check attached image for cute animals

@penalosa penalosa force-pushed the penalosa/vitest-v4-support branch from d45260d to 60332b7 Compare December 18, 2025 17:58
@penalosa penalosa force-pushed the penalosa/vitest-v4-support branch from b4ce401 to 964012e Compare December 18, 2025 19:24
@penalosa penalosa marked this pull request as ready for review December 18, 2025 21:47
@penalosa penalosa requested review from a team as code owners December 18, 2025 21:47
Copy link
Contributor

@ascorbic ascorbic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly some questions. Otherwise, looking great!

@workers-devprod
Copy link
Contributor

workers-devprod commented Mar 5, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/deploy-config
  • ✅ @cloudflare/workflows
  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

✅ All changesets look good

@penalosa penalosa force-pushed the penalosa/vitest-v4-support branch from f44feba to 343ffb9 Compare March 5, 2026 23:55
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

penalosa added 5 commits March 9, 2026 17:56
…tsconfig

Use the dynamic env from cloudflare:workers (live ESM binding) instead of
the static this.env captured at WorkerEntrypoint construction. This allows
withEnv() overrides to propagate through exports.default.fetch() and RPC
calls to user handler invocations.

Also fix workers-assets root tsconfig to only include ./*.ts, matching the
pattern used by all other fixtures. The src/ and test/ subdirectories have
their own tsconfigs with the correct workers types.
singleWorker was removed from the pool options schema but was still
being passed in console.test.ts and inspector.test.ts — silently
stripped by Zod validation. Also expand the inline comment for
no_handle_cross_request_promise_resolution to explain what it does
and why it's needed.
Call worker.fetch() directly inside withEnv() so the overridden env
is visible to the handler. exports.default.fetch() goes through service
binding dispatch which creates a new request context — needs runtime
team input on whether withEnv() should propagate across that boundary.
devin-ai-integration[bot]

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done