Skip to content

Introduce vitest4 to vitest-pool-workers#28908

Open
MattieTK wants to merge 2 commits intoproductionfrom
mattietk/vitest-pool-workers-vitest4
Open

Introduce vitest4 to vitest-pool-workers#28908
MattieTK wants to merge 2 commits intoproductionfrom
mattietk/vitest-pool-workers-vitest4

Conversation

@MattieTK
Copy link
Member

Summary

This introduces a changelog and updates relevant documentation for vitest-pool-workers to reflect the changes made to update to vitest4. There are some features that are dependent on vitest 4.1 so we should wait for that release before merging this.

The changelog largely uses the documentation opencode persona, but has been manually reviewed and tweaked where it overstepped.

Documentation checklist

@github-actions github-actions bot added product:workers Related to Workers product product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ product:changelog size/xl labels Mar 11, 2026
@github-actions
Copy link
Contributor

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/content/changelog/ @cloudflare/pm-changelogs, @cloudflare/pcx-technical-writing
/src/content/docs/durable-objects/ @elithrar, @vy-ton, @joshthoward, @oxyjun, @lambrospetrou, @mikenomitch, @cloudflare/pcx-technical-writing
/src/content/docs/workers/ @cloudflare/workers-docs, @GregBrimble, @irvinebroque, @mikenomitch, @korinne, @WalshyDev, @cloudflare/deploy-config, @cloudflare/pcx-technical-writing, @cloudflare/wrangler, @mattietk, @cloudflare/dev-plat-leads

@github-actions
Copy link
Contributor

Preview URL: https://eb562266.preview.developers.cloudflare.com
Preview Branch URL: https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com

Files with changes (up to 15)

Original Link Updated Link
https://developers.cloudflare.com/workers/testing/vitest-integration/test-apis/ https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com/workers/testing/vitest-integration/test-apis/
https://developers.cloudflare.com/durable-objects/best-practices/rules-of-durable-objects/ https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com/durable-objects/best-practices/rules-of-durable-objects/
https://developers.cloudflare.com/durable-objects/examples/testing-with-durable-objects/ https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com/durable-objects/examples/testing-with-durable-objects/
https://developers.cloudflare.com/workers/testing/vitest-integration/configuration/ https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com/workers/testing/vitest-integration/configuration/
https://developers.cloudflare.com/workers/testing/vitest-integration/known-issues/ https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com/workers/testing/vitest-integration/known-issues/
https://developers.cloudflare.com/workers/testing/vitest-integration/write-your-first-test/ https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com/workers/testing/vitest-integration/write-your-first-test/
https://developers.cloudflare.com/workers/testing/vitest-integration/debugging/ https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com/workers/testing/vitest-integration/debugging/
https://developers.cloudflare.com/workers/testing/vitest-integration/migration-guides/migrate-from-miniflare-2/ https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com/workers/testing/vitest-integration/migration-guides/migrate-from-miniflare-2/
https://developers.cloudflare.com/changelog/2026-03-11-vitest-pool-workers-vitest-4/ https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com/changelog/2026-03-11-vitest-pool-workers-vitest-4/
https://developers.cloudflare.com/workers/testing/vitest-integration/isolation-and-concurrency/ https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com/workers/testing/vitest-integration/isolation-and-concurrency/
https://developers.cloudflare.com/workers/testing/vitest-integration/migration-guides/migrate-from-unstable-dev/ https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com/workers/testing/vitest-integration/migration-guides/migrate-from-unstable-dev/
https://developers.cloudflare.com/workers/testing/vitest-integration/ https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com/workers/testing/vitest-integration/
https://developers.cloudflare.com/workers/best-practices/workers-best-practices/ https://mattietk-vitest-pool-workers-vitest4.preview.developers.cloudflare.com/workers/best-practices/workers-best-practices/

@@ -0,0 +1,70 @@
---
title: "`@cloudflare/vitest-pool-workers` now requires Vitest 4"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we say "targets" rather than "requires" to make it sound a bit more positive?

Suggested change
title: "`@cloudflare/vitest-pool-workers` now requires Vitest 4"
title: "`@cloudflare/vitest-pool-workers` now targets Vitest 4"

Copy link
Member

Choose a reason for hiding this comment

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

How about this?

Suggested change
title: "`@cloudflare/vitest-pool-workers` now requires Vitest 4"
title: "`@cloudflare/vitest-pool-workers` now supports Vitest 4"

Then mention this requires Vitest v4.1.0 with the new version in the content?

date: 2026-03-11
---

`@cloudflare/vitest-pool-workers` now requires Vitest 4.1 or later. Support for Vitest 2.x and 3.x has been dropped. This release rearchitects the integration to use a Vite plugin model and simplifies the configuration and isolation APIs as the package moves toward v1.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we focus on the benefits of us moving to Vitest 4? How this has enabled us to fix a bunch of long term bugs and issues?

Copy link
Contributor

Choose a reason for hiding this comment

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

And perhaps we could say that we took the opportunity of this breaking change to simplify the integration and usage and to clarify how best to use vitest when testing workers?

(e.g. the isolated storage removal is more inline with how people conventionally manage resources in vitest tests rather than the magical approach that often caused diifficult to debug breakages)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I don't think dropped is right language here.

Existing stuff keeps working with Vitest 3.x

It's just that there is a new version of @cloudflare/vitest-pool-workers

But where I am confused is — right now the version is 0.x? https://www.npmjs.com/package/@cloudflare/vitest-pool-workers?activeTab=code

So not to be semver guy about it — but I don't totally follow the relationship here between, "I need to use version of vitest pool workers in order to use vitest 4, etc."

Copy link
Contributor

@irvinebroque irvinebroque left a comment

Choose a reason for hiding this comment

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

See questions about codemod

Also — opportunity for agent skill?

date: 2026-03-11
---

`@cloudflare/vitest-pool-workers` now requires Vitest 4.1 or later. Support for Vitest 2.x and 3.x has been dropped. This release rearchitects the integration to use a Vite plugin model and simplifies the configuration and isolation APIs as the package moves toward v1.
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I don't think dropped is right language here.

Existing stuff keeps working with Vitest 3.x

It's just that there is a new version of @cloudflare/vitest-pool-workers

But where I am confused is — right now the version is 0.x? https://www.npmjs.com/package/@cloudflare/vitest-pool-workers?activeTab=code

So not to be semver guy about it — but I don't totally follow the relationship here between, "I need to use version of vitest pool workers in order to use vitest 4, etc."


## Other breaking changes

- **`isolatedStorage` and `singleWorker` removed.** Storage isolation is now per test file, matching Vitest's own isolation model. To make test files share the same storage, use the Vitest flags `--max-workers=1 --no-isolate`.
Copy link
Contributor

Choose a reason for hiding this comment

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

so is the guidance here — remove your uses of these — and just use vitest flags?

is this / should it be part of the codemod?


- **`isolatedStorage` and `singleWorker` removed.** Storage isolation is now per test file, matching Vitest's own isolation model. To make test files share the same storage, use the Vitest flags `--max-workers=1 --no-isolate`.

- **`import { env, SELF } from "cloudflare:test"` removed.** Use `import { env, exports } from "cloudflare:workers"` instead. `exports.default.fetch()` behaves the same as `SELF.fetch()`, except that it does not expose Assets. To test your assets, write an integration test using [`startDevWorker()`](/workers/testing/unstable_startworker/).
Copy link
Contributor

Choose a reason for hiding this comment

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

covered by codemod?

Copy link
Contributor

Choose a reason for hiding this comment

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

it would have been great if the codemod covered test files too tbh, but it's shipped now without it for just the config file. The config file is the easiest thing to update 🙃


- **`import { env, SELF } from "cloudflare:test"` removed.** Use `import { env, exports } from "cloudflare:workers"` instead. `exports.default.fetch()` behaves the same as `SELF.fetch()`, except that it does not expose Assets. To test your assets, write an integration test using [`startDevWorker()`](/workers/testing/unstable_startworker/).

- **`import { fetchMock } from "cloudflare:test"` removed.** Mock `globalThis.fetch` directly or use ecosystem libraries such as [MSW](https://mswjs.io/). Refer to the [request mocking example](https://github.com/cloudflare/workers-sdk/blob/main/fixtures/vitest-pool-workers-examples/request-mocking/test/imperative.test.ts) for an example.
Copy link
Contributor

Choose a reason for hiding this comment

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

codemod?

Comment on lines +95 to 98
declare module "cloudflare:workers" {
interface ProvidedEnv {
NAMESPACE: KVNamespace;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is no longer correct, and we should probably just link to the Workers Typescript docs here instead of re-stating the config.

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

Labels

product:changelog product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ product:workers Related to Workers product size/xl

Projects

None yet

Development

Successfully merging this pull request may close these issues.