mswjs / msw

Industry standard API mocking for JavaScript.
https://mswjs.io
MIT License
15.94k stars 518 forks source link

MSW seems not to work with kafka testcontainers #1600

Open ofekdeitch-oligo opened 1 year ago

ofekdeitch-oligo commented 1 year ago

Prerequisites

Environment check

Node.js version

18.16.0

Reproduction repository

https://github.com/ofekdeitch-oligo/msw-testcontainers-bug

Reproduction steps

run:

  1. nvm use
  2. npm install
  3. npm run test

Notice that there are 2 tests running:

  1. Without MSW
  2. With MSW

Test (1) passes, but test (2) fails.

I've also added the method bypassRoutes that creates routes using req.passthrough(), but test (2) continues to fail.

Current behavior

When setting up an MSW server, the testcontainers library fails to create a Kafka container.

Expected behavior

MSW would bypass the requests that testcontainers relies on, so that a Kafka container would be created successfully.

kettanaito commented 1 year ago

Hi, @ofekdeitch-oligo. Thanks for reporting this.

From my experience, issues like these are often related to how the third-party agent (in your case the testcontainers package) constructs and performs the request. I can't count the number of times libraries go into strange tropes, sometimes even against the Node.js API, and then issues surface through libraries like MSW, which let you execute more of the request code.

I don't have the time capacity to look into this, so anybody is welcome to debug the issue and share their findings. Thank you for understanding.