{
  "slug": "wrangler-createtestharness-supports-integration-testing-workers-b393214940be",
  "title": "wrangler createTestHarness() supports integration testing Workers",
  "tools": [
    "wrangler"
  ],
  "tags": [
    "agent"
  ],
  "introduced_at": "2026-06-09T12:48:28.000Z",
  "announced_at": "2026-06-09T12:48:28.000Z",
  "effective_at": null,
  "date_basis": "source-publication",
  "status": "unknown",
  "how": {
    "incantation": "When writing Worker integration tests with a Node.js test runner, use `createTestHarness()` with Wrangler config paths for the Workers. Start it before tests, then send requests or scheduled events through its handles; reset between tests and close after the suite.",
    "examples": [
      "import { after, afterEach, before, test } from \"node:test\";\nimport { createTestHarness } from \"wrangler\";\n\nconst server = createTestHarness({\n  workers: [\n    { configPath: \"<path-to-web-worker-wrangler-config>\" },\n    { configPath: \"<path-to-api-worker-wrangler-config>\" },\n  ],\n});\nconst apiWorker = server.getWorker(\"<api-worker-name>\");\n\nbefore(async () => { await server.listen(); });\nafterEach(async () => { await server.reset(); });\nafter(async () => { await server.close(); });\n\ntest(\"dispatches a request\", async () => {\n  const response = await server.fetch(\"<url-matching-configured-route>\");\n});\n\ntest(\"dispatches directly and triggers a scheduled event\", async () => {\n  await apiWorker.fetch(\"<request-url>\");\n  await apiWorker.scheduled({ cron: \"<cron-expression>\", scheduledTime: new Date() });\n});\n\nserver.getLogs();\n// On test failure:\nserver.debug();",
      "const server = createTestHarness({\n  workers: [{ configPath: \"<generated-vite-worker-wrangler-config>\" }],\n});"
    ],
    "gotchas": [
      "Version: 4.99.0",
      "workers (required): Worker inputs for the test server; the first Worker is primary.",
      "configPath (required): Wrangler configuration file path or URL; relative paths resolve from `root`.",
      "root: Base directory for resolving relative Worker config paths; defaults to `process.cwd()`.",
      "env: Wrangler environment to load from the config file.",
      "scheduled({ cron, scheduledTime }) (required): Dispatches a scheduled event directly to the selected Worker; documented example supplies a cron expression and `new Date()`.",
      "listen() (required): Starts the test server.",
      "reset(): Restores the options used when the current session started and recreates storage; the URL may change.",
      "close() (required): Stops the server and releases runtime resources.",
      "getLogs(): Returns captured Workers runtime logs for the current server session.",
      "debug(): Prints a diagnostic timeline including server events and captured Workers runtime logs.",
      "Prerequisite: Use a Node.js test runner and install `wrangler` as a development dependency.",
      "Prerequisite: For Cloudflare Vite plugin Workers, run `npx vite build` first so tests use production build output.",
      "Runs Workers in a local preview environment using production build output.",
      "Works with Wrangler projects and Workers built by the Cloudflare Vite plugin.",
      "Use from a Node.js test runner."
    ]
  },
  "why_it_matters": "When writing integration tests for Workers built by Wrangler or the Cloudflare Vite plugin, run them in a local preview environment using production build output.",
  "sources": [
    "https://github.com/cloudflare/workers-sdk/releases/tag/wrangler%404.99.0",
    "https://developers.cloudflare.com/workers/wrangler/api/",
    "https://developers.cloudflare.com/workers/testing/test-harness/configure/",
    "https://developers.cloudflare.com/workers/testing/test-harness/get-started/"
  ],
  "rank": 0.98068,
  "judge": {
    "publish": true,
    "judge_model": "codex-cli/gpt-6-luna+typesafe/jev-1.13.0",
    "prompt_version": "extract-v7+enrich-v1+judge-v2x3+jev-publish-v1"
  },
  "review_state": "approved",
  "provenance": {
    "run_id": "backfill-20261007",
    "verdict_id": "backfill-20261007:backfill-20261007-412ae260f94e092e-0:gate",
    "evidence_hash": "3ae058449663e4a41e368e6a31a0862679c6371306476b68201bdf7af384922d"
  },
  "review": {
    "draft_hash": "052bbc61e6883577bbcc35e8d453f23876b485f0e550e7d13334163bc593b3b8",
    "reviewer": "publication-gate",
    "reviewed_at": "2026-10-07T00:00:00.000Z",
    "decision": "backfill-20261007:gate",
    "reason": "3 of 3 judge runs approved with p_yes >= 0.9 (mean 0.98 >= 0.9; 2 needed) and Jev gave 0.78 (>= 0.6 needed)."
  }
}
