Skip to content

Commit ccba31a

Browse files
committed
change integration-testing.mdx to unstable startworker
1 parent b6393fd commit ccba31a

File tree

11 files changed

+166
-270
lines changed

11 files changed

+166
-270
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ The Workers platform has a variety of ways to test your applications, depending
1717

1818
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.
1919

20-
| Feature | [Vitest integration](/workers/testing/vitest-integration) | [`unstable_startWorker()`](/workers/wrangler/api/#unstable_startworker) | [Miniflare's API](/workers/testing/miniflare) |
2120
| ------------------------------------------------------------------------ | --------------------------------------------------------- | ----------------------------------------------------------------------- | --------------------------------------------- |
2221
| Unit testing ||||
2322
| Integration testing ||||
@@ -30,5 +29,6 @@ However, if you don't use Vitest, both [Miniflare's API](/workers/testing/minif
3029
| Run Durable Object alarms immediately ||||
3130
| List Durable Objects ||||
3231
| Testing service Workers ||||
32+
| Feature | [Vitest integration](/workers/testing/vitest-integration) | [`unstable_startWorker()`](/workers/testing/unstable_startworker/) | [Miniflare's API](/workers/testing/miniflare/writing-tests/) |
3333

3434
<Render file="testing-pages-functions" product="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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ head: []
77
description: Write integration tests against Workers using Miniflare.
88
---
99

10-
:::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.
12-
:::
13-
1410
import { TabItem, Tabs, Details } from "~/components";
1511

1612
import { FileTree } from "@astrojs/starlight/components";
1713

14+
:::note
15+
For most users, Cloudflare recommends using the Workers Vitest integration. If you have been using test environments from Miniflare, refer to the [Migrate from Miniflare 2 guide](/workers/testing/vitest-integration/migration-guides/migrate-from-miniflare-2/).
16+
:::
17+
1818
This guide will show you how to set up [Miniflare](/workers/testing/miniflare) to test your Workers. Miniflare is a low-level API that allows you to fully control how your Workers are run and tested.
1919

2020
To use Miniflare, make sure you've installed the latest version of Miniflare v3:
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Wrangler's unstable_startWorker()
3+
pcx_content_type: concept
4+
sidebar:
5+
order: 17
6+
head: []
7+
description: Write integration tests using Wrangler's `unstable_startWorker()` API
8+
---
9+
10+
import { Render } from "~/components";
11+
import { LinkButton } from "@astrojs/starlight/components";
12+
13+
:::note
14+
For most users, Cloudflare recommends using the Workers Vitest integration. If you have been using `unstable_dev()`, refer to the [Migrate from `unstable_dev()` guide](/workers/testing/vitest-integration/migration-guides/migrate-from-unstable-dev/).
15+
:::
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, 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. Compared to using [Miniflare directly](/workers/testing/miniflare/writing-tests/) for testing, you can pass in a Wrangler configuration file, and it will automatically load the configuration for you.
22+
23+
This example uses `node:test`, but should apply to any testing framework:
24+
25+
```ts
26+
import assert from "node:assert";
27+
import test, { after, before, describe } from "node:test";
28+
import { unstable_startWorker } from "wrangler";
29+
30+
describe("worker", () => {
31+
let worker;
32+
33+
before(async () => {
34+
worker = await unstable_startWorker({ config: "wrangler.json" });
35+
});
36+
37+
test("hello world", async () => {
38+
assert.strictEqual(
39+
await (await worker.fetch("http://example.com")).text(),
40+
"Hello world",
41+
);
42+
});
43+
44+
after(async () => {
45+
await worker.dispose();
46+
});
47+
});
48+
49+
```

0 commit comments

Comments
 (0)