cloudflare / workers-sdk

โ›…๏ธ Home to Wrangler, the CLI for Cloudflare Workersยฎ
https://developers.cloudflare.com/workers/
Apache License 2.0
2.61k stars 684 forks source link

๐Ÿš€ Feature Request: ability to monkey patch cloudflare workers when running tests #4375

Open shivan-s opened 1 year ago

shivan-s commented 1 year ago

Describe the solution

I used the package, msw to mock some external URLs, but if you use the unstable_dev then external call are still made and they aren't interceptors.

Is there anyway this could in included into the wrangler framework, or am I mistaken?

penalosa commented 1 year ago

Unfortunately this isn't something that's possible today, but this is definitely something we could consider trying to support!

mrbbot commented 1 year ago

Hey! ๐Ÿ‘ As a quick update, this is something we're planning to expose as part of the work to stabilise unstable_dev. Miniflare provides outboundService and fetchMock options that we should be able to pass through to Wrangler. ๐Ÿ‘

mrbbot commented 11 months ago

Hey again! ๐Ÿ‘‹ Considering Miniflare now provides outboundService and fetchMock options, I'm going to transfer this back to cloudflare/workers-sdk. This is something we should be able to support as part of our work to rearchitect wrangler dev as a library. /cc @RamIdeas

m-shaka commented 2 months ago

Hi. It seems like outboundService and fetchMock can be passed here. https://github.com/cloudflare/workers-sdk/blob/51cc4f806e2fea826f10f4249df2ed0b792763a5/packages/wrangler/src/dev.tsx#L728-L768

Is there something bothering you? If I can help you, please let me know