createTestHarness() Worker handles apply local D1 migrations
Introduced 2026-06-30 · score 0.97
HOW TO USE IT
When tests need a local D1 schema before requests, call `applyD1Migrations("DATABASE")` on the Worker handle returned by `server.getWorker()`; call it after storage is reset.
const worker = server.getWorker();
beforeEach(async () => {
await worker.applyD1Migrations("DATABASE");
});WHY THIS HELPS
Run tests that need a local D1 database schema initialized before sending requests to a test harness Worker.
REQUIREMENTS AND LIMITATIONS
- Version: wrangler@4.106.0
- bindingName (required): D1 binding to migrate; reads its Wrangler migration settings.
- Prerequisite: Use a test harness Worker with a configured D1 binding. Migrations use configured `migrations_dir` and `migrations_pattern`; without them, `.sql` files are read from the `migrations` directory relative to the config file.
- Applies local D1 migrations before running requests.
FIRST-PARTY EVIDENCE
- https://github.com/cloudflare/workers-sdk/releases/tag/wrangler%404.106.0
- https://developers.cloudflare.com/workers/testing/test-harness/prepare-test-state/
- https://developers.cloudflare.com/workers/wrangler/api/
Check the installed version and the source before using it. Entry JSON