Skip to content

Conversation

@RobinBertilsson
Copy link

As mentioned in ISSUE-103.

an error is happening when same API endpoint is triggered multiple times during test execution. Seems like error comes from onMockedResponse method, comparing it with same method from msw we can see that response is cloned before usage. When I've added response.clone() problem is gone.

@RobinBertilsson
Copy link
Author

@valendres could you please have a look? 🙏

headers: rawHeaders,
body: rawBody,
}) => {
onMockedResponse: async (response) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's much better to use a higher-level getResponse() instead of handleRequest(). Any history as to why handleRequest is used instead? Is it to tap into resolutionContext.baseUrl?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure i'm following... Where do you mean i would use handleRequest?
The only difference in this PR is that i accept the request parameter provided by onMockedResponse, which i then use to clone the response, before mutating it. The reason for the clone is because the stream is "locked" as per this error message.

ReadableStream is locked

Copy link

@kettanaito kettanaito Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment isn't related to your changes. If you scroll a few lines above your change, you see the usage of handleRequest. Funneling the mocked response from onMockedResponse to Playwright isn't the best place so I'm suggesting using getResponse() instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants