sincecutoff.com
← all changes

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

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

Report a problem with this card