Skip to content

Commit 8e9e86b

Browse files
emily-shenRebeccaTamachiro
authored andcommitted
[workers] Update vitest getting started guide (#21454)
* update write your first test * tidy up various overviews * pr feedback
1 parent ee6737b commit 8e9e86b

File tree

4 files changed

+160
-240
lines changed

4 files changed

+160
-240
lines changed

src/content/docs/workers/testing/index.mdx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,28 @@ sidebar:
77

88
import { Render, LinkButton } from "~/components";
99

10-
The Workers platform has a variety of ways to test your applications, depending on your requirements. We recommend using the [Vitest integration](/workers/testing/vitest-integration), which allows for unit testing individual functions within your Worker. However, if you don't use Vitest, both [Miniflare's API](/workers/testing/miniflare/writing-tests) and the [`unstable_startWorker()`](/workers/wrangler/api/#unstable_startworker) API provide options for testing your Worker in any testing framework.
10+
The Workers platform has a variety of ways to test your applications, depending on your requirements. We recommend using the [Vitest integration](/workers/testing/vitest-integration), which allows you to run tests to _inside_ the Workers runtime, and unit test individual functions within your Worker.
1111

1212
<LinkButton href="/workers/testing/vitest-integration/get-started/write-your-first-test/">
13-
Write your first test
13+
Get started with Vitest
1414
</LinkButton>
1515

1616
## Testing comparison matrix
1717

18-
| Feature | [Vitest integration](/workers/testing/vitest-integration) | [`unstable_startWorker()`](/workers/wrangler/api/#unstable_startworker) | [Miniflare's API](/workers/testing/miniflare) |
19-
| ------------------------------------- | --------------------------------------------------------- | ----------------------------------------------------------------------- | --------------------------------------------- |
20-
| Unit testing ||||
21-
| Integration testing ||||
22-
| Loading [Wrangler configuration files](/workers/wrangler/configuration/) ||||
23-
| Use bindings directly in tests ||||
24-
| Isolated per-test storage ||||
25-
| Outbound request mocking ||||
26-
| Multiple Worker support ||||
27-
| Direct access to Durable Objects ||||
28-
| Run Durable Object alarms immediately ||||
29-
| List Durable Objects ||||
30-
| Testing service Workers ||||
18+
However, if you don't use Vitest, both [Miniflare's API](/workers/testing/miniflare/writing-tests) and the [`unstable_startWorker()`](/workers/wrangler/api/#unstable_startworker) API provide options for testing your Worker in any testing framework.
19+
20+
| Feature | [Vitest integration](/workers/testing/vitest-integration) | [`unstable_startWorker()`](/workers/wrangler/api/#unstable_startworker) | [Miniflare's API](/workers/testing/miniflare) |
21+
| ------------------------------------------------------------------------ | --------------------------------------------------------- | ----------------------------------------------------------------------- | --------------------------------------------- |
22+
| Unit testing ||||
23+
| Integration testing ||||
24+
| Loading [Wrangler configuration files](/workers/wrangler/configuration/) ||||
25+
| Use bindings directly in tests ||||
26+
| Isolated per-test storage ||||
27+
| Outbound request mocking ||||
28+
| Multiple Worker support ||||
29+
| Direct access to Durable Objects ||||
30+
| Run Durable Object alarms immediately ||||
31+
| List Durable Objects ||||
32+
| Testing service Workers ||||
3133

3234
<Render file="testing-pages-functions" product="workers" />

src/content/docs/workers/testing/vitest-integration/get-started/index.mdx

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,12 @@ pcx_content_type: navigation
33
title: Get started
44
sidebar:
55
order: 1
6+
group:
7+
hideIndex: true
68
head: []
79
description: Install and set up the Workers Vitest integration.
8-
910
---
1011

11-
import { DirectoryListing } from "~/components"
12-
13-
For most users, Cloudflare recommends using the Workers Vitest integration for testing Workers and [Pages Functions](/pages/functions/) projects. [Vitest](https://vitest.dev/) is a popular JavaScript testing framework featuring a very fast watch mode, Jest compatibility, and out-of-the-box support for TypeScript. In this integration, Cloudflare provides a custom pool that allows your Vitest tests to run *inside* the Workers runtime.
14-
15-
The Workers Vitest integration:
16-
17-
* Supports both **unit tests** and **integration tests**.
18-
* Provides direct access to Workers runtime APIs and bindings.
19-
* Implements isolated per-test storage.
20-
* Runs tests fully-locally using [Miniflare](https://miniflare.dev/).
21-
* Leverages Vitest's hot-module reloading for near instant reruns.
22-
* Provides a declarative interface for mocking outbound requests.
23-
* Supports projects with multiple Workers.
24-
25-
Get started with one of the available guides:
12+
import { DirectoryListing } from "~/components";
2613

2714
<DirectoryListing />
28-
29-
:::caution
30-
31-
32-
The Workers Vitest integration does not support testing Workers using the service worker format. [Migrate to the ES modules format](/workers/reference/migrate-to-module-workers/) to use the Workers Vitest integration.
33-
34-
35-
:::

0 commit comments

Comments
 (0)