I was gonna use miniflare jest to test

I was gonna use miniflare-jest to test my worker by making fetch requests to it, as seen in https://miniflare.dev/testing/jest#writing-and-running-tests. I guess we could call theses "integration tests". Can you confirm this is the right way (I guess so, given the doc).
7 Replies
vvo
vvoOP2y ago
And then have a few more involved tests like: - deploy to cloudflare - make actual fetch requests to cloudflare (but this would not use miniflare)
DaniFoldi
DaniFoldi2y ago
There is no single right way to do tests - depends on what you want to make sure doesn't break. It is a possibility to test the external (http) interface of your worker, and if that fails then you know in advance your API would have breaking changes, for example
vvo
vvoOP2y ago
Yup that's the goal
DaniFoldi
DaniFoldi2y ago
I personally have 3 layers of tests (not every app needs that, this is an extreme case for an example here) - test the flow of REST API (e2e tests) - test the interface of HTTP endpoints (integration tests, sort of) - test components, utility functions (unit tests) in other cases, I'll only do the 2nd, for simple projects I don't really care about internals changing (esp if I'm the only one working on it)
vvo
vvoOP2y ago
- test the flow of REST API (e2e tests) Do you achieve this via wrangler publish --route or similar (to avoid conflicts with production/other PRs) and then run tests on that? - test the interface of HTTP endpoints (integration tests, sort of) => done via miniflare?
DaniFoldi
DaniFoldi2y ago
I run all of these locally with vitest, which is similar to jest, just integrates better with vite
vvo
vvoOP2y ago
You said "e2e tests" so I thought you 1. deploy to cloudflare 2. test the endpoint
Want results from more Discord servers?
Add your server