sincecutoff.com
← all changes

wrangler createTestHarness exposes per-Worker resource accessors

Introduced 2026-06-16 · score 0.97

HOW TO USE IT

When testing a Worker with configured KV, R2, D1, or Durable Object bindings, call `server.getWorker(name)` and use that handle’s accessor for the binding.

import { createTestHarness } from "wrangler"; const server = createTestHarness({ workers: [{ configPath: "<wrangler-config-path>" }] }); const worker = server.getWorker("<worker-name>"); const kv = await worker.getKVNamespace("<KV-binding>"); const bucket = await worker.getR2Bucket("<R2-binding>"); const db = await worker.getD1Database("<D1-binding>"); const objects = await worker.getDurableObjectNamespace("<DO-binding>");

WHY THIS HELPS

Test a Worker that uses configured KV, R2, D1, or Durable Object resources.

REQUIREMENTS AND LIMITATIONS

  • Version: 4.101.0
  • server.getWorker(name): Returns a handle for the named Worker; without a name, returns the primary Worker.
  • bindingName (required): Binding name passed to `getKVNamespace`, `getR2Bucket`, `getD1Database`, or `getDurableObjectNamespace`; returns that configured resource on this Worker.
  • Prerequisite: Create the harness with at least one Worker; the resource must be configured on the selected Worker.
  • Accessors are for configured KV namespaces, R2 buckets, D1 databases, and Durable Object namespaces.
  • Resources are scoped to the specific Worker returned by `server.getWorker(name)`. The source does not name accessor methods for KV namespaces or Durable Object namespaces.

FIRST-PARTY EVIDENCE

Check the installed version and the source before using it. Entry JSON

Report a problem with this card