Skip to content

Commit 8427f60

Browse files
committed
rearrange
1 parent 68d9ec7 commit 8427f60

File tree

16 files changed

+432
-519
lines changed

16 files changed

+432
-519
lines changed

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ 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 Cloudflare Workers [Vitest integration](/workers/testing/vitest-integration) is the recommended way to test your applications, and allows for unit testing individual functions within your Worker or Pages Function.
11+
12+
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.
1113

1214
<LinkButton href="/workers/testing/vitest-integration/get-started/write-your-first-test/">
13-
Write your first test
15+
Get started with Vitest
1416
</LinkButton>
1517

1618
## Testing comparison matrix
1719

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 ||||
31-
32-
<Render file="testing-pages-functions" product="workers" />
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 ||||

src/content/docs/workers/testing/integration-testing.mdx

Lines changed: 0 additions & 139 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Miniflare
33
pcx_content_type: navigation
44
sidebar:
5-
order: 15
5+
order: 16
66
head:
77
- tag: title
88
content: miniflare

src/content/docs/workers/testing/miniflare/writing-tests.mdx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ description: Write integration tests against Workers using Miniflare.
88
---
99

1010
:::note
11-
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.
11+
For most users, Cloudflare recommends using the Workers Vitest integration for testing Workers and [Pages Functions](/pages/functions/) projects.
12+
13+
If you have been using the test environments from Miniflare 2 for integration testing and want to migrate to Cloudflare's Vitest integration, refer to the [Migrate from Miniflare 2 migration guide](/workers/testing/vitest-integration/get-started/migrate-from-miniflare-2/) for more information.
14+
1215
:::
1316

1417
import { TabItem, Tabs, Details } from "~/components";
@@ -98,13 +101,13 @@ The highlighted lines of the test file above demonstrate how to set up Miniflare
98101
<Details header="What runtime are tests running in?">
99102
When using the [Vitest integration](/workers/testing/vitest-integration/),
100103
your entire test suite runs in
101-
[`workerd`](https://github.com/cloudflare/workerd), which is why it is possible
102-
to unit test individual functions. By contrast, when using a different testing
103-
framework to run tests via Miniflare, only your Worker itself is running in
104-
[`workerd`](https://github.com/cloudflare/workerd) — your test files run in
105-
Node.js. This means that importing functions from your Worker into your test
106-
files might exhibit different behaviour than you'd see at runtime if the
107-
functions rely on `workerd`-specific behaviour.
104+
[`workerd`](https://github.com/cloudflare/workerd), which is why it is
105+
possible to unit test individual functions. By contrast, when using a
106+
different testing framework to run tests via Miniflare, only your Worker
107+
itself is running in [`workerd`](https://github.com/cloudflare/workerd) — your
108+
test files run in Node.js. This means that importing functions from your
109+
Worker into your test files might exhibit different behaviour than you'd see
110+
at runtime if the functions rely on `workerd`-specific behaviour.
108111
</Details>
109112

110113
## Interacting with Bindings

src/content/docs/workers/testing/unit-testing.mdx

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: unstable_startWorker()
3+
pcx_content_type: concept
4+
sidebar:
5+
order: 17
6+
head: []
7+
description: Test multiple units of your Worker working together.
8+
---
9+
10+
import { Render } from "~/components";
11+
import { LinkButton } from "@astrojs/starlight/components";
12+
13+
note: we recommend using vitest
14+
15+
## [Wrangler's `unstable_startWorker()` API](/workers/wrangler/api/#unstable_startworker)
16+
17+
:::caution
18+
`unstable_startWorker()` is an experimental API subject to breaking changes.
19+
:::
20+
21+
If you do not want to use Vitest and would like to write integration tests for a single Worker, consider using [Wrangler's `unstable_startWorker()` API](/workers/wrangler/api/#unstable_startworker). This API exposes the internals of Wrangler's dev server, and allows you to customise how it runs.
22+
23+
```js
24+
import assert from "node:assert";
25+
import { unstable_startWorker } from "wrangler";
26+
27+
const worker = await unstable_startWorker({ config: "wrangler.json" });
28+
try {
29+
const response = await worker.fetch("/?a=1&b=2");
30+
assert.strictEqual(await response.text(), "3");
31+
} finally {
32+
await worker.dispose();
33+
}
34+
```
35+
36+
<Render file="testing-pages-functions" product="workers" />

0 commit comments

Comments
 (0)