Skip to content

[Workers] integration testing guide with createTestHarness()#31377

Draft
edmundhung wants to merge 1 commit into
productionfrom
edmundhung/create-test-harness-docs
Draft

[Workers] integration testing guide with createTestHarness()#31377
edmundhung wants to merge 1 commit into
productionfrom
edmundhung/create-test-harness-docs

Conversation

@edmundhung

Copy link
Copy Markdown
Member

Summary

Adding some docs with regards to the new createTestHarness() API, which is now our recommendation for integration tests. While vitest-pool-workers remains recommended for unit tests.

Screenshots (optional)

Documentation checklist

  • Is there a changelog entry (guidelines)? If you don't add one for something awesome and new (however small) — how will our customers find out? Changelogs are automatically posted to RSS feeds, the Discord, and X.
  • The change adheres to the documentation style guide.
  • If a larger change - such as adding a new page- an issue has been opened in relation to any incorrect or out of date information that this PR fixes.
  • Files which have changed name or location have been allocated redirects.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/content/docs/workers/ @cloudflare/workers-docs, @GregBrimble, @irvinebroque, @mikenomitch, @korinne, @WalshyDev, @cloudflare/deploy-config, @cloudflare/product-owners, @cloudflare/wrangler, @MattieTK, @cloudflare/dev-plat-leads, @vy-ton
/src/content/docs/workers/wrangler/ @cloudflare/wrangler, @irvinebroque, @cloudflare/product-owners, @MattieTK, @vy-ton

@ask-bonk ask-bonk Bot added the documentation Documentation edits label Jun 10, 2026

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted 5 inline suggestions and flagged 1 issue requiring maintainer action.

HIGH — Style guide violations:

  • write-your-first-test.mdx line 26: Bare ts fence for a Workers example. Must use TypeScriptExample. (inline suggestion provided)
  • recipes.mdx lines 22–184: Multiple bare ts fences for Workers examples. Must use TypeScriptExample. (inline suggestions provided for representative blocks)
  • recipes.mdx lines 112–129: Bare jsonc fences for Wrangler config. Must use WranglerConfig with TOML input and $today for compatibility_date. (inline suggestions provided)

MEDIUM — Missing changelog:

  • This PR introduces a new major feature with 3 new docs pages. Consider adding a changelog entry in src/content/changelog/workers/.

Out of scopemigrate-from-unstable-dev.mdx has a pre-existing invalid pcx_content_type: migration (not in the allowed values list).

products:
- workers
---

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the required component import:

Suggested change
import { TypeScriptExample } from "~/components";

Comment on lines +26 to +50
```ts title="test/index.test.ts"
import { afterAll, afterEach, beforeAll, test } from "vitest";
import { createTestHarness } from "wrangler";

const server = createTestHarness({
workers: [{ configPath: "./wrangler.jsonc" }],
});

beforeAll(async () => {
await server.listen();
});

afterEach(async () => {
await server.reset();
});

afterAll(async () => {
await server.close();
});

test("responds", async ({ expect }) => {
const response = await server.fetch("/");
expect(await response.text()).toBe("Hello World");
});
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use TypeScriptExample for all Workers JS/TS examples:

Suggested change
```ts title="test/index.test.ts"
import { afterAll, afterEach, beforeAll, test } from "vitest";
import { createTestHarness } from "wrangler";
const server = createTestHarness({
workers: [{ configPath: "./wrangler.jsonc" }],
});
beforeAll(async () => {
await server.listen();
});
afterEach(async () => {
await server.reset();
});
afterAll(async () => {
await server.close();
});
test("responds", async ({ expect }) => {
const response = await server.fetch("/");
expect(await response.text()).toBe("Hello World");
});
```
<TypeScriptExample filename="test/index.test.ts">
```ts
import { afterAll, afterEach, beforeAll, test } from "vitest";
import { createTestHarness } from "wrangler";
const server = createTestHarness({
workers: [{ configPath: "./wrangler.jsonc" }],
});
beforeAll(async () => {
await server.listen();
});
afterEach(async () => {
await server.reset();
});
afterAll(async () => {
await server.close();
});
test("responds", async ({ expect }) => {
const response = await server.fetch("/");
expect(await response.text()).toBe("Hello World");
});
```

products:
- workers
---

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the required component imports:

Suggested change
import { TypeScriptExample, WranglerConfig } from "~/components";

Comment on lines +22 to +29
```ts
const server = createTestHarness({
workers: [
{ configPath: "./wrangler.api.jsonc" },
{ configPath: "./dist/web_worker/wrangler.json" },
],
});
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use TypeScriptExample instead of a bare ts fence:

Suggested change
```ts
const server = createTestHarness({
workers: [
{ configPath: "./wrangler.api.jsonc" },
{ configPath: "./dist/web_worker/wrangler.json" },
],
});
```
<TypeScriptExample>
```ts
const server = createTestHarness({
workers: [
{ configPath: "./wrangler.api.jsonc" },
{ configPath: "./dist/web_worker/wrangler.json" },
],
});
```

Comment on lines +112 to +120
```jsonc title="wrangler.web.jsonc"
{
"name": "web-worker",
"main": "src/web.ts",
"compatibility_date": "2026-06-01",
"routes": ["example.com/*"],
"services": [{ "binding": "API", "service": "api-worker" }]
}
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use WranglerConfig with TOML input and $today for Wrangler configuration examples:

Suggested change
```jsonc title="wrangler.web.jsonc"
{
"name": "web-worker",
"main": "src/web.ts",
"compatibility_date": "2026-06-01",
"routes": ["example.com/*"],
"services": [{ "binding": "API", "service": "api-worker" }]
}
```
<WranglerConfig>
```toml
name = "web-worker"
main = "src/web.ts"
compatibility_date = "$today"
routes = ["example.com/*"]
[[services]]
binding = "API"
service = "api-worker"
```

Comment on lines +122 to +129
```jsonc title="wrangler.api.jsonc"
{
"name": "api-worker",
"main": "src/api.ts",
"compatibility_date": "2026-06-01",
"routes": ["example.com/api/*"]
}
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use WranglerConfig with TOML input and $today for Wrangler configuration examples:

Suggested change
```jsonc title="wrangler.api.jsonc"
{
"name": "api-worker",
"main": "src/api.ts",
"compatibility_date": "2026-06-01",
"routes": ["example.com/api/*"]
}
```
<WranglerConfig>
```toml
name = "api-worker"
main = "src/api.ts"
compatibility_date = "$today"
routes = ["example.com/api/*"]
```

@ask-bonk

ask-bonk Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

I have completed the review of PR #31377.

Actions taken:

  • Added the documentation label.
  • Posted a review with 5 inline suggestions and a summary comment.

What the PR changes:
This PR introduces documentation for the new createTestHarness() API, adding 3 new pages under /workers/testing/test-harness/ (index, how-to, and recipes). It updates the Workers testing overview to position createTestHarness() as the recommended integration testing tool, while keeping the Vitest integration as the recommendation for unit tests. It also marks unstable_startWorker() and unstable_dev() as deprecated in the Wrangler API reference and updates related cross-references across 10 files.

Issues flagged:

  • HIGH — Style guide violations in new pages:

    • write-your-first-test.mdx and recipes.mdx use bare ts code blocks for Workers TypeScript examples. The style guide mandates TypeScriptExample for all Workers JS/TS examples.
    • recipes.mdx uses bare jsonc code blocks for Wrangler configuration examples. The style guide mandates WranglerConfig with TOML input and $today for compatibility_date.
  • MEDIUM — Missing changelog:

    • The PR introduces a major new feature with multiple new docs pages, but no changelog entry has been added yet. The documentation checklist item for changelog is unchecked.
  • Out of scopemigrate-from-unstable-dev.mdx has a pre-existing invalid pcx_content_type: migration (not in the allowed values list).

I posted inline suggestions for the most representative violations. The author should apply the TypeScriptExample and WranglerConfig patterns to all occurrences in the new files.

github run

@github-actions

Copy link
Copy Markdown
Contributor

Preview URL: https://52de8539.preview.developers.cloudflare.com
Preview Branch URL: https://edmundhung-create-test-harness-docs.preview.developers.cloudflare.com

Files with changes (up to 15)

Original Link Updated Link
https://developers.cloudflare.com/workers/testing/test-harness/recipes/ https://edmundhung-create-test-harness-docs.preview.developers.cloudflare.com/workers/testing/test-harness/recipes/
https://developers.cloudflare.com/workers/wrangler/api/ https://edmundhung-create-test-harness-docs.preview.developers.cloudflare.com/workers/wrangler/api/
https://developers.cloudflare.com/workers/testing/test-harness/write-your-first-test/ https://edmundhung-create-test-harness-docs.preview.developers.cloudflare.com/workers/testing/test-harness/write-your-first-test/
https://developers.cloudflare.com/workers/testing/ https://edmundhung-create-test-harness-docs.preview.developers.cloudflare.com/workers/testing/
https://developers.cloudflare.com/workers/testing/test-harness/ https://edmundhung-create-test-harness-docs.preview.developers.cloudflare.com/workers/testing/test-harness/
https://developers.cloudflare.com/workers/testing/unstable_startworker/ https://edmundhung-create-test-harness-docs.preview.developers.cloudflare.com/workers/testing/unstable_startworker/
https://developers.cloudflare.com/workers/testing/vitest-integration/migration-guides/migrate-from-unstable-dev/ https://edmundhung-create-test-harness-docs.preview.developers.cloudflare.com/workers/testing/vitest-integration/migration-guides/migrate-from-unstable-dev/
https://developers.cloudflare.com/workers/testing/miniflare/ https://edmundhung-create-test-harness-docs.preview.developers.cloudflare.com/workers/testing/miniflare/
https://developers.cloudflare.com/workers/testing/miniflare/writing-tests/ https://edmundhung-create-test-harness-docs.preview.developers.cloudflare.com/workers/testing/miniflare/writing-tests/
https://developers.cloudflare.com/workers/testing/vitest-integration/ https://edmundhung-create-test-harness-docs.preview.developers.cloudflare.com/workers/testing/vitest-integration/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation edits product:workers Related to Workers product size/l

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants