tests, scripts: cleanup tests and dev environment things
Alternative title: making the tests & local dev environment not annoying and messy
This is an attempt to make the tests and local dev environment a lot nicer to work with.
Some of the main problems with them right now are:
- No Sentry = no error visibility, nothing is logged to console
- You can't run the worker in development unless it's in wrangler's remote mode. This requires a Cloudflare account & a R2 bucket to be setup on that account which is annoying
- Tests are rather messy and haven't really been updated like the rest of the codebase has been. This was good when we were changing a lot so we could ensure we didn't break anything, but, it's time now to clean these up imo
This pr:
- Rewrites tests to be a lot cleaner & conform with the style of the rest of the codebase
- Adds an example of the structure of the
dist-prodbucket (calleddev-bucket)- Replaces the bucket data at
tests/e2e/test-data/R2_BUCKETfor e2e tests - Can be used in a dev script to populate a bucket for local testing (see 3)
- Replaces the bucket data at
- ~~
npm run dev- starts a locally running version of the worker with a populated R2 bucket~~- ~~Populated from the
dev-bucketdirectory~~
- ~~Populated from the
What's TODO:
- [x] Finish implementing e2e tests
- [ ] Go through code to see if there's anything that should be tested that isn't
- [ ] Make the local dev script nicer
Some current annoyances:
- The local dev script uses Miniflare since there isn't actually a way to populate an R2 bucket locally with Wrangler, so any niceness that that has we need to reimplement or go without. Hot reloading might not be possible either since Miniflare works off of the compiled
worker.jsfile. I do have some ideas, but not entirely sure if they're gonna work. - ~~Ideally we would be able to use Workers' vitest integration, but it's not really possible since we're doing things like mocking an S3 api in our e2e tests. Vitest patches a lot of modules and globals making things like
node:httpunavailable.~~ Workaround for this was found, so we can use the Vitest integration now
@flakey5 -- do you need a review now or is this still WIP?
Still a wip
Gonna go ahead and mark this for review now.
This unfortunately doesn't resolve the annoyances with running the worker locally though, there's still some things that I need to play around with to see if I can get it working in an ideal way.
cc @flakey5 thanks for bearing with me 🙇
@flakey5 OOC are you switching from Wrangler to the Vite Plugin?
Ah sorry, nvm, you just added Vitest. Forgot of that.