This article was originally published on Jo4 Blog.

I added 3,059 lines of tests to our Cloudflare Worker. Not a single line uses miniflare. No Workers runtime simulation. Just Vitest, vi.stubGlobal('fetch', mockFetch), and focused assertions on the things that actually break in production.

Here's why that's the right call and how to set it up.

TL;DR

Cloudflare Workers are just JavaScript functions that receive a Request and return a Response. You don't need the Workers runtime to test most of the logic. Stub fetch, write unit tests for routing, caching headers, and redirect handling. Save integration tests for deployment verification. This approach is faster, simpler, and catches the bugs that miniflare would miss anyway.