Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .changeset/msw-cloudflare-integration.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
"@cloudflare/vitest-pool-workers": minor
"@cloudflare/vitest-plugin": minor
---

Mocking requests with MSW in Worker tests now requires MSW >= 2.14

`@cloudflare/vitest-pool-workers` previously shipped internal shims to make MSW work inside the workerd runtime. MSW 2.14 added that support natively, so those shims have been removed.
`@cloudflare/vitest-plugin` previously shipped internal shims to make MSW work inside the workerd runtime. MSW 2.14 added that support natively, so those shims have been removed.

If you mock requests with MSW in your Worker tests, make sure you're on MSW `>= 2.14`; older versions will no longer intercept requests. You can keep using `setupServer()` from `msw/node`, or adopt the official [`@msw/cloudflare`](https://github.com/mswjs/cloudflare) integration via `setupNetwork()`. See the updated [`request-mocking` example fixture](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/request-mocking) for the recommended pattern.
If you mock requests with MSW in your Worker tests, make sure you're on MSW `>= 2.14`; older versions will no longer intercept requests. You can keep using `setupServer()` from `msw/node`, or adopt the official [`@msw/cloudflare`](https://github.com/mswjs/cloudflare) integration via `setupNetwork()`. See the updated [`request-mocking` example fixture](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-plugin-examples/request-mocking) for the recommended pattern.
31 changes: 31 additions & 0 deletions .changeset/rename-vitest-plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
"@cloudflare/vitest-plugin": major
---

Rename `@cloudflare/vitest-pool-workers` to `@cloudflare/vitest-plugin` for the v1 release

The package has been renamed from `@cloudflare/vitest-pool-workers` to `@cloudflare/vitest-plugin` to better reflect that it is a Vite/Vitest plugin rather than a custom Vitest pool.

To migrate:

1. Replace the dependency in your `package.json`:

```diff
- "@cloudflare/vitest-pool-workers": "^0.16.0"
+ "@cloudflare/vitest-plugin": "^1.0.0"
```

2. Update your imports (a codemod is provided):

```sh
npx jscodeshift -t node_modules/@cloudflare/vitest-plugin/dist/codemods/vitest-pool-workers-to-vitest-plugin.mjs vitest.config.ts
```

This rewrites imports such as `import { cloudflareTest } from "@cloudflare/vitest-pool-workers"` to `import { cloudflareTest } from "@cloudflare/vitest-plugin"`, preserving any subpaths.

3. Update the `types` entry in your test `tsconfig.json`:

```diff
- "types": ["@cloudflare/vitest-pool-workers/types"]
+ "types": ["@cloudflare/vitest-plugin/types"]
```
2 changes: 1 addition & 1 deletion .github/skills/issue-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Map the issue to a package based on labels, title, and body content:
| `package:wrangler` label, wrangler CLI commands, `wrangler.toml`/`wrangler.json` | `packages/wrangler` |
| `package:miniflare` label, local dev simulation | `packages/miniflare` |
| `product:d1` label, D1 database, `d1 execute`, migrations | `packages/wrangler` (D1 code is in wrangler) |
| `package:vitest` label, worker tests, `vitest-pool-workers` | `packages/vitest-pool-workers` |
| `package:vitest` label, worker tests, `vitest-plugin` | `packages/vitest-plugin` |
| `package:vite-plugin` label, vite dev, `@cloudflare/vite-plugin` | `packages/vite-plugin-cloudflare` |
| `package:c3` label, `create-cloudflare`, project scaffolding | `packages/create-cloudflare` |
| `product:pages` label, Pages deployment, `_routes.json`, `_headers` | `packages/wrangler` (Pages code is in wrangler) |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test-and-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ jobs:

- name: Run tests (packages)
if: steps.changes.outputs.everything_but_markdown == 'true' && matrix.suite == 'packages-and-tools'
# We skip @cloudflare/vitest-pool-workers tests in CI on Windows because they're very flaky. We still run the vitest-pool-workers-examples fixture, which is a comprehensive set of example tests and gives us a lot of confidence.
# The @cloudflare/vitest-pool-workers tests skipped are things like watch mode, which constantly times out probably due to the github runners in use.
# We skip @cloudflare/vitest-plugin tests in CI on Windows because they're very flaky. We still run the vitest-plugin-examples fixture, which is a comprehensive set of example tests and gives us a lot of confidence.
# The @cloudflare/vitest-plugin tests skipped are things like watch mode, which constantly times out probably due to the github runners in use.
# Package tests are well-isolated (separate processes, temp dirs, random ports, MSW mocks) and can safely run in parallel.
# Concurrency is capped at 3 to avoid CPU starvation on 4-vCPU CI runners when heavyweight suites
# (wrangler/forks, miniflare/workerd, vitest-pool-workers/Verdaccio) overlap.
run: pnpm run test:ci --log-order=stream --concurrency=3 --filter="./packages/*" ${{ matrix.os == 'windows-latest' && '--filter="!./packages/vitest-pool-workers"' || '' }}
# (wrangler/forks, miniflare/workerd, vitest-plugin/Verdaccio) overlap.
run: pnpm run test:ci --log-order=stream --concurrency=3 --filter="./packages/*" ${{ matrix.os == 'windows-latest' && '--filter="!./packages/vitest-plugin"' || '' }}
env:
NODE_OPTIONS: "--max_old_space_size=8192"
WRANGLER_LOG_PATH: ${{ runner.temp }}/wrangler-debug-logs/
Expand Down
2 changes: 1 addition & 1 deletion .opencode/agents/bonk.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Use triage mode when you are asked to investigate rather than change code.
- Add regression tests for bug fixes.
- Run `pnpm test:ci --filter <package>` for the touched area.
- Do not leave `.only()` in tests.
- Use `vitest-pool-workers` when you need actual Workers runtime behavior.
- Use `vitest-plugin` when you need actual Workers runtime behavior.

**Git:**

Expand Down
2 changes: 1 addition & 1 deletion .oxfmtrc.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"!packages/create-cloudflare/templates*/hello-world/**/*.*",
"packages/create-cloudflare/templates*/hello-world/**/worker-configuration.d.ts",

"packages/vitest-pool-workers/scripts/rtti/rtti.js",
"packages/vitest-plugin/scripts/rtti/rtti.js",
"packages/vite-plugin-cloudflare/playground/prisma/src/generated",
"dist-functions",
"vscode.d.ts",
Expand Down
10 changes: 5 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This is the **Cloudflare Workers SDK** monorepo containing tools and libraries f

**Development & Testing:**

- `packages/vitest-pool-workers/` - Vitest integration for testing Workers in actual runtime
- `packages/vitest-plugin/` - Vitest integration for testing Workers in actual runtime
- `packages/chrome-devtools-patches/` - Modified Chrome DevTools for Workers debugging

**Shared Libraries:**
Expand Down Expand Up @@ -124,7 +124,7 @@ This is the **Cloudflare Workers SDK** monorepo containing tools and libraries f
- Unit tests with Vitest for all packages
- Fixture tests in `/fixtures` directory for filesystem/Worker scenarios
- E2E tests require real Cloudflare account credentials
- Use `vitest-pool-workers` for testing actual Workers runtime behavior
- Use `vitest-plugin` for testing actual Workers runtime behavior
- Shared vitest config (`vitest.shared.ts`): 50s timeouts, `retry: 1`, `restoreMocks: true`
- Vitest 4 pool config: use `maxWorkers: 1` instead of the removed `poolOptions.forks.singleFork: true` when tests must run sequentially
- **`expect` must come from test context** — never `import { expect } from "vitest"`:
Expand All @@ -134,7 +134,7 @@ This is the **Cloudflare Workers SDK** monorepo containing tools and libraries f
- When test context is unavailable (e.g. setup files), use `node:assert` instead
- E2E vitest configs do NOT set `globals: true` — this rule is critical there; forgetting `{ expect }` in the callback causes `ReferenceError` at runtime
- When changing user-facing strings or output messages, update corresponding test snapshots
- New test fixtures in `vitest-pool-workers-examples/` must include a `tsconfig.json`
- New test fixtures in `vitest-plugin-examples/` must include a `tsconfig.json`
- Test fixtures serve as user-facing recipes — use clean patterns, avoid type casting where possible
- Use the `runInTmpDir()` utility instead of mocking filesystem operations. Real filesystem operations are preferred over mocking. The utility creates isolated temporary directories, handles cleanup automatically in `afterEach` hooks, and allows tests to write actual files and assert against them
- Use the `mockConsoleMethods()` helper to capture stdout/stderr. Use the pattern `const std = mockConsoleMethods()` in test setup, then access captured output via `std.out`, `std.err`, `std.warn` properties. Assert against captured output using `expect(std.out).toMatchInlineSnapshot()`
Expand Down Expand Up @@ -179,7 +179,7 @@ This is the **Cloudflare Workers SDK** monorepo containing tools and libraries f
**Package-specific tests:** Most packages have their own test suites
**Integration tests:** Use fixtures to test real-world scenarios
**E2E tests:** Test against actual Cloudflare services (requires auth)
**Workers runtime tests:** Use vitest-pool-workers for workerd-specific behavior
**Workers runtime tests:** Use vitest-plugin for workerd-specific behavior

Run `pnpm check` before submitting changes to ensure all quality gates pass.

Expand Down Expand Up @@ -227,7 +227,7 @@ Packages with their own AGENTS.md for deeper context:
- `packages/miniflare/AGENTS.md` - Worker simulation, embedded workers, build system
- `packages/vite-plugin-cloudflare/AGENTS.md` - Plugin architecture, playground setup
- `packages/create-cloudflare/AGENTS.md` - Scaffolding, template system
- `packages/vitest-pool-workers/AGENTS.md` - 3-context architecture, cloudflare:test module
- `packages/vitest-plugin/AGENTS.md` - 3-context architecture, cloudflare:test module
- `packages/workers-utils/AGENTS.md` - Shared config validation, test helpers

When making architectural changes to a package (renaming files, adding entry points, changing build output), update the relevant AGENTS.md to reflect the new structure.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ npm i https://pkg.pr.new/@cloudflare/vite-plugin@main

</p></details>

<details><summary><b>@cloudflare/vitest-pool-workers</b></summary><p>
<details><summary><b>@cloudflare/vitest-plugin</b></summary><p>

```
npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@main
npm i https://pkg.pr.new/@cloudflare/vitest-plugin@main
```

</p></details>
Expand Down
2 changes: 1 addition & 1 deletion fixtures/browser-run/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"devDependencies": {
"@cloudflare/playwright": "^1.0.0",
"@cloudflare/puppeteer": "^1.0.4",
"@cloudflare/vitest-pool-workers": "workspace:*",
"@cloudflare/vitest-plugin": "workspace:*",
"@types/node": "catalog:default",
"typescript": "catalog:default",
"vitest": "catalog:default",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `@cloudflare/vitest-pool-workers` Examples
# `@cloudflare/vitest-plugin` Examples

This directory contains example projects tested with `@cloudflare/vitest-pool-workers`. It aims to provide the building blocks for you to write tests for your own Workers.
This directory contains example projects tested with `@cloudflare/vitest-plugin`. It aims to provide the building blocks for you to write tests for your own Workers.

| Directory | Overview |
| --------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🤖 AI and Vectorize

This Worker uses the AI and Vectorize bindings. @cloudflare/vitest-pool-workers@^0.8.1 is required to use AI and Vectorize bindings in the Vitest integration.
This Worker uses the AI and Vectorize bindings. `@cloudflare/vitest-plugin` is required to use AI and Vectorize bindings in the Vitest integration.

[!WARNING]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down
3 changes: 3 additions & 0 deletions fixtures/vitest-plugin-examples/container-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Apps with no-op containers

Currently, `vitest-plugin` does not support testing containers yet. It should still let you test your application as long as you do not test with any code paths that interact with containers.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"compilerOptions": {
"paths": {
// This path is used to simulate a virtual module that Vitest and TypeScript can understand,
// but esbuild (used by the vitest-pool-workers to guess exports) cannot.
// but esbuild (used by the vitest-plugin to guess exports) cannot.
"@virtual-module": ["./virtual.ts"]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ConfiguredVirtualDurableObject extends DurableObject<Env> {
}
}

// Although this export cannot be inferred by esbuild, it is explicitly configured in vitest-pool-workers config via `additionalExports`.
// Although this export cannot be inferred by esbuild, it is explicitly configured in vitest-plugin config via `additionalExports`.
export class ConfiguredVirtualEntryPoint extends WorkerEntrypoint<Env> {
greet() {
return `Hello ${this.env.NAME} from ConfiguredVirtualEntryPoint!`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ it("will warn on missing context exports on the main worker", async ({
expect(warnSpy).toHaveBeenCalledWith(
"Attempted to access 'ctx.exports.InvalidExport', which was not defined for the main Worker.\n" +
"Check that 'InvalidExport' is exported as an entry-point from the Worker.\n" +
"The '@cloudflare/vitest-pool-workers' integration tries to infer these exports by analyzing the source code of the main Worker.\n"
"The '@cloudflare/vitest-plugin' integration tries to infer these exports by analyzing the source code of the main Worker.\n"
);
});

Expand All @@ -45,7 +45,7 @@ it("will warn on implicit re-exports that will exist in production but cannot no
expect(warnSpy).toHaveBeenCalledWith(
"Attempted to access 'ctx.exports.ReexportedVirtualEntryPoint', which was not defined for the main Worker.\n" +
"Check that 'ReexportedVirtualEntryPoint' is exported as an entry-point from the Worker.\n" +
"The '@cloudflare/vitest-pool-workers' integration tries to infer these exports by analyzing the source code of the main Worker.\n"
"The '@cloudflare/vitest-plugin' integration tries to infer these exports by analyzing the source code of the main Worker.\n"
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"compilerOptions": {
"paths": {
// This path is used to simulate a virtual module that Vitest and TypeScript can understand,
// but esbuild (used by the vitest-pool-workers to guess exports) cannot.
// but esbuild (used by the vitest-plugin to guess exports) cannot.
"@virtual-module": ["../src/virtual.ts"]
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down Expand Up @@ -36,7 +36,7 @@ export default mergeConfig(
globalSetup: ["./global-setup.ts"],
alias: {
// This alias is used to simulate a virtual module that Vitest and TypeScript can understand,
// but esbuild (used by the vitest-pool-workers to guess exports) cannot.
// but esbuild (used by the vitest-plugin to guess exports) cannot.
"@virtual-module": "./virtual.ts",
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import path from "node:path";
import {
cloudflareTest,
readD1Migrations,
} from "@cloudflare/vitest-pool-workers";
import { cloudflareTest, readD1Migrations } from "@cloudflare/vitest-plugin";
import { defineConfig, defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
_ctx: ExecutionContext
): Promise<Response> {
// Dynamic import inside a fetch handler — this is the pattern that
// triggers the cross-DO I/O violation in vitest-pool-workers 0.13.x
// triggers the cross-DO I/O violation in vitest-plugin 0.13.x
// when called via `exports.default.fetch()` in tests.
// See: https://github.com/cloudflare/workers-sdk/issues/12924
const { greet } = await import("./greeting");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down
3 changes: 3 additions & 0 deletions fixtures/vitest-plugin-examples/misc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 🤷 misc

We run all the tests in `vitest-plugin-examples` on every change to `workers-sdk`. This directory contains a bunch of tests to validate assorted Vitest features that aren't tested elsewhere.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { Response } from "miniflare";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineProject, mergeConfig } from "vitest/config";
import configShared from "../../../vitest.shared";

Expand Down
Loading
Loading