Skip to content

Commit

Permalink
Add basic start worker docs
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa committed Jan 16, 2025
1 parent f67732d commit cc968b4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/content/docs/workers/testing/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar:

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

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/testing/wrangler) API provide options for testing your Worker in any testing framework.
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.


<LinkButton href="/workers/testing/vitest-integration/get-started/write-your-first-test/">
Expand All @@ -17,7 +17,7 @@ The Workers platform has a variety of ways to test your applications, depending

## Testing comparison matrix

| Feature | [Vitest integration](/workers/testing/vitest-integration) | [`unstable_startWorker()`](/workers/testing/wrangler) | [Miniflare's API](/workers/testing/miniflare) |
| Feature | [Vitest integration](/workers/testing/vitest-integration) | [`unstable_startWorker()`](/workers/wrangler/api/#unstable_startworker) | [Miniflare's API](/workers/testing/miniflare) |
| ----------------------------------------- | ----------- | ---------------- | --------------- |
| Unit testing ||||
| Integration testing ||||
Expand Down
32 changes: 32 additions & 0 deletions src/content/docs/workers/wrangler/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,41 @@ import { Render, TabItem, Tabs, Type, MetaInfo } from "~/components";

Wrangler offers APIs to programmatically interact with your Cloudflare Workers.

- [`unstable_startWorker`](#unstable_startworker) - Start a server for running integration tests against your Worker.
- [`unstable_dev`](#unstable_dev) - Start a server for running either end-to-end (e2e) or integration tests against your Worker.
- [`getPlatformProxy`](#getplatformproxy) - Get proxies and values for emulating the Cloudflare Workers platform in a Node.js process.

## `unstable_startWorker`

This API exposes the internals of Wrangler's dev server, and allows you to customise how it runs. For example, you could use `unstable_startWorker()` to run integration tests against your Worker (the below example is with `node:test`, but this should work in any testing framework):

```js
import assert from "node:assert";
import test, { after, before, describe } from "node:test";
import { unstable_startWorker } from "wrangler";

describe("worker", () => {
let worker;

before(async () => {
worker = await unstable_startWorker({ config: "wrangler.json" });
});

test("hello world", async () => {
assert.strictEqual(
await (await worker.fetch("http://example.com")).text(),
"Hello world"
);
});

after(async () => {
await worker.dispose();
});
});
```



## `unstable_dev`

Start an HTTP server for testing your Worker.
Expand Down

0 comments on commit cc968b4

Please sign in to comment.