Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 BUG: fetchMock does not intercept fetch in a service binding worker #5789

Open
thiskevinwang opened this issue May 9, 2024 · 2 comments
Labels
bug Something that isn't working

Comments

@thiskevinwang
Copy link

thiskevinwang commented May 9, 2024

Which Cloudflare product(s) does this pertain to?

Workers Vitest Integration

What version(s) of the tool(s) are you using?

3.53.1 [wrangler], 0.2.6 [@cloudflare/vitest-pool-workers], 1.3.0 [vitest]

What version of Node are you using?

20.11.0

What operating system and version are you using?

Mac Ventura 13.5

Describe the Bug

Observed behavior

fetchMock does not appear to intercept fetch calls that are internal to another worker that is built and bound as a service binding.

Expected behavior

I'd expect fetchMock to intercept fetch calls in a service binding worker.

Steps to reproduce

  1. Create worker A
  2. Create worker B with entrypoint "Foo"
  3. In worker B, call fetch(SOMETHING)
  4. Create a test for worker A
  5. Build worker B and set as service binding on worker A
  6. From test for worker A, call fetchMock and intercept the previous SOMETHING
  7. activate(), disableNetConnect(). Assert no pending mocks
  8. Call code to test Worker A-to-B integration
  9. Observe 1 outstanding interceptor
  10. Observe a "Network connection lost" error from the fetch call.

See: https://github.com/thiskevinwang/workers-sdk-5789

Please provide a link to a minimal reproduction

https://github.com/thiskevinwang/workers-sdk-5789

Please provide any relevant error logs

No response

@thiskevinwang thiskevinwang added the bug Something that isn't working label May 9, 2024
@thiskevinwang
Copy link
Author

It looks like outboundService is one means to mock this class of fetches, but you're slightly bound to a static implementation, so it's not flexible.

I also see a mutually exclusive fetchMock option, but it's unclear how you satisfy this field (assuming a vitest.config.ts file)

@thiskevinwang
Copy link
Author

Update: added repro-repo https://github.com/thiskevinwang/workers-sdk-5789

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
Status: Untriaged
Development

No branches or pull requests

1 participant