MrBBot 4470 I m writing tests `vitest

@mrbbot I'm writing tests (vitest-environment-miniflare) for a worker that binds another worker. The other worker has a DO, and I've bound that DO to the original worker as well. I want to seed an instance of the DO for tests, but I'm running into trouble because constructing that DO requires the other worker's env (to fetch another bound worker). Is there a way to get the other env, or a different pattern I should be using to seed the DO?
3 Replies
MrBBot
MrBBot•2y ago
Hey! 👋 Could you add a Durable Object namespace binding to the other DO in your test worker, then use the standard (await env.NAMESPACE.get(id)).fetch("/seed"), where /seed is some special URL defined in your DO's fetch handler that seeds the required data?
TravisFrank
TravisFrank•2y ago
Just tried this. Unfortunately the error persists, it looks like the service binding to the third worker isn’t showing up on the env of the DO constructor call The env of worker #2 (the one with the DO) has a service binding to worker #3 that I'm fetching in the constructor of the DO. I'm getting TypeError: Cannot read properties of undefined (reading 'fetch') when getting the DO, and after inspecting the env in the DO, I'm noting it's receiving the env of worker #1 (which does not have a service binding to worker #3). Ahhhh, is this expected behavior? If I fetch a DO declared in another worker, will the DO receive the env of the calling worker?
MrBBot
MrBBot•2y ago
That shouldn't be the case, it should be receiving the env of the Worker it's defined in
Want results from more Discord servers?
Add your server