wrangler test harness accesses Durable Object storage
Introduced 2026-07-17 · score 0.95
HOW TO USE IT
When a Worker test needs to seed or inspect SQLite-backed Durable Object state, use `worker.getDurableObjectStorage()` with the binding or exported class name and an instance name or ID, then run SQL with `storage.exec()`.
const server = createTestHarness({ workers: [{ configPath: "./wrangler.json" }] });
await server.listen();
const worker = server.getWorker();
const storage = await worker.getDurableObjectStorage("COUNTER", { name: "user-123" });
await worker.fetch("/counter/user-123");
const rows = await storage.exec("SELECT value FROM counters WHERE id = ?", "user-123");
expect(rows).toEqual([{ value: 1 }]);WHY THIS HELPS
Seed or assert SQLite-backed Durable Object storage state in a Worker test using `createTestHarness()`.
REQUIREMENTS AND LIMITATIONS
- Version: 4.112.0
- classNameOrBindingName (required): The Durable Object exported class name or namespace binding name.
- options (required): Select the Durable Object instance by `name` or `id`.
- storage.exec(sql, ...params) (required): Executes SQL inside the target Durable Object and returns all rows; SQL parameters follow the query string.
- Prerequisite: The Durable Object must be SQLite-backed; the method returns its storage handle.
- Prerequisite: Configure the test harness with a Worker via Wrangler config or inline config, then start it with `server.listen()`.
- The storage access shown is for a SQLite-backed Durable Object.
FIRST-PARTY EVIDENCE
- https://github.com/cloudflare/workers-sdk/releases/tag/wrangler%404.112.0
- https://developers.cloudflare.com/workers/testing/test-harness/prepare-test-state/
- https://github.com/cloudflare/workers-sdk/blob/cb6c3f9a5c6d67804cd0cb447cc0837a9f75848c/packages/wrangler/src/api/test-harness.ts
Check the installed version and the source before using it. Entry JSON