Skip to main content
Cloudflare Workers SDK provides several testing utilities to help you write comprehensive tests for your Workers.

D1 Testing Utilities

applyD1Migrations()

Apply D1 migrations from a directory.
D1Database
required
D1 database binding
string
required
Path to migrations directory containing SQL files
Promise<void>
Resolves when migrations are complete

listD1Databases()

List all D1 databases in local development.
string
required
Path to D1 persistence directory
Promise<string[]>
Array of database names

getD1DatabasePath()

Get the SQLite file path for a D1 database.
string
required
Path to D1 persistence directory
string
required
Database name
string
Full path to the SQLite database file

Pages Testing Utilities

getPagesAssetFetcher()

Get a fetcher for Pages assets.
PagesAssetOptions
required
Fetcher
Fetcher for serving static assets

readPagesConfig()

Read and parse a Pages configuration file.
string
required
Path to Pages config file
Promise<PagesConfig>
Parsed Pages configuration

Durable Object Testing

createDurableObjectId()

Create a Durable Object ID for testing.

resetDurableObjectStorage()

Reset a Durable Object’s storage.

Queue Testing

sendQueueMessage()

Manually send messages to a queue consumer.

Mock Utilities

Custom Request Mocking


Request Helpers


Time Utilities

advanceTime()

Advance time for testing scheduled events and timers.

Environment Utilities

setupTestEnvironment()

Set up a test environment with common bindings.

Assertion Helpers

Response Assertions


Complete Testing Example