Production and deployment

Test with the Workers runtime

Run integration tests inside the Workers execution environment with local bindings instead of mocking every platform API.

8 minute lesson

~~~

Ordinary unit tests still suit pure Link Vault logic. Runtime integration tests should exercise the actual Worker module and local D1, KV, R2, and Queue behavior.

Use Cloudflare’s Vitest integration and isolated storage for tests. Apply migrations, send requests through the Worker, and assert binding effects. Keep a small remote verification step for differences that local emulation cannot represent.

Split tests by evidence. Pure tests prove validation and state transitions. Runtime integration tests prove that the exported handler, generated environment, migrations, and binding APIs work together. A deployed smoke test proves that the published version is connected to the intended remote resources.

Reset storage between tests and never let test order create the fixture. For eventual-consistency behavior, test the application’s tolerance rather than expecting local emulation to reproduce global propagation timing. Exercise failure paths too: a missing migration, duplicate queue delivery, absent R2 object, and unavailable downstream service should produce controlled states and useful logs.

Test create/list in D1, a KV cache miss and hit, an R2 export, and duplicate queue processing.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →