Skip to content

Commit b42cc8f

Browse files
[Vitest Integration] Update guide to use Vitest 3 (#20369)
Co-authored-by: ToriLindsay <[email protected]>
1 parent df4e904 commit b42cc8f

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/content/docs/agents/getting-started/testing-your-agent.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The `agents-sdk-starter` template and new Cloudflare Workers projects already in
2323
Before you write your first test, install the necessary packages:
2424

2525
```sh
26-
npm install vitest@2.1.8 --save-dev --save-exact
26+
npm install vitest@~3.0.0 --save-dev --save-exact
2727
npm install @cloudflare/vitest-pool-workers --save-dev
2828
```
2929

src/content/docs/workers/testing/vitest-integration/get-started/migrate-from-miniflare-2.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ First, you will need to uninstall the old environment and install the new pool.
3030

3131
```sh
3232
npm uninstall vitest-environment-miniflare
33-
npm install --save-dev --save-exact vitest@2.1.8
33+
npm install --save-dev --save-exact vitest@~3.0.0
3434
npm install --save-dev @cloudflare/vitest-pool-workers
3535
```
3636

3737
## Update your Vitest configuration file
3838

39-
After installing the Workers Vitest configuration, update your Vitest configuration file to use the pool instead. Most Miniflare configuration previously specified `environmentOptions` can be moved to `poolOptions.workers.miniflare` instead. Refer to [Miniflare's `WorkerOptions` interface](https://github.com/cloudflare/workers-sdk/blob/main/packages/miniflare/README.md#interface-workeroptions) for supported options and the [Miniflare version 2 to 3 migration guide](https://miniflare.dev/get-started/migrating#api-changes) for more information. If you relied on configuration stored in a Wrangler file, set `wrangler.configPath` too.
39+
After installing the Workers Vitest configuration, update your Vitest configuration file to use the pool instead. Most Miniflare configuration previously specified `environmentOptions` can be moved to `poolOptions.workers.miniflare` instead. Refer to [Miniflare's `WorkerOptions` interface](https://github.com/cloudflare/workers-sdk/blob/main/packages/miniflare/README.md#interface-workeroptions) for supported options and the [Miniflare version 2 to 3 migration guide](/workers/testing/miniflare/migrations/from-v2/) for more information. If you relied on configuration stored in a Wrangler file, set `wrangler.configPath` too.
4040

4141
```diff
4242
+ import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";

src/content/docs/workers/testing/vitest-integration/get-started/write-your-first-test.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ This guide will instruct you through installing and setting up the `@cloudflare/
2424
Open a terminal window and make sure you are in your project's root directory. Once you have confirmed that, run:
2525

2626
```sh
27-
npm install vitest@2.1.8 --save-dev --save-exact
27+
npm install vitest@~3.0.0 --save-dev --save-exact
2828
npm install @cloudflare/vitest-pool-workers --save-dev
2929
```
3030

3131
The above commands will add the packages to your `package.json` file and install them as dev dependencies.
3232

3333
:::note
3434

35-
Currently, the `@cloudflare/vitest-pool-workers` package _only_ works with Vitest 2.0.x - 2.1.8.
35+
Currently, the `@cloudflare/vitest-pool-workers` package _only_ works with Vitest 2.0.x - 3.0.x.
3636

3737
:::
3838

src/content/docs/workers/testing/vitest-integration/known-issues.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Using WebSockets with Durable Objects with the [`isolatedStorage`](/workers/test
3434

3535
When the `isolatedStorage` flag is enabled (the default), the test runner will undo any writes to the storage at the end of the test as detailed in the [isolation and concurrency documentation](/workers/testing/vitest-integration/isolation-and-concurrency/). However, Cloudflare recommends that you consider the following actions to avoid any common issues:
3636

37-
## Await all storage operations
37+
#### Await all storage operations
3838

3939
Always `await` all `Promise`s that read or write to storage services.
4040

@@ -46,15 +46,15 @@ beforeAll(async () => {
4646
});
4747
```
4848

49-
## Explicitly signal resource disposal
49+
#### Explicitly signal resource disposal
5050

5151
When calling RPC methods of a Service Worker or Durable Object that return non-primitive values (such as objects or classes extending `RpcTarget`), use the `using` keyword to explicitly signal when resources can be disposed of. See [this example test](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/rpc/test/unit.test.ts#L155) and refer to [explicit-resource-management](/workers/runtime-apis/rpc/lifecycle#explicit-resource-management) for more details.
5252

5353
```ts
5454
using result = await stub.getCounter();
5555
```
5656

57-
## Consume response bodies
57+
#### Consume response bodies
5858

5959
When making requests via `fetch` or `R2.get()`, consume the entire response body, even if you are not asserting its content. For example:
6060

0 commit comments

Comments
 (0)