Closed Acetyld closed 6 days ago
Hi, @Acetyld. Thanks for reporting this.
I looked at the repo briefly, your usage seems to be okay. This may be a bug in MSW. I will explore this in more detail once I have a moment.
The error suggests that the underlying socket instance starts receiving a response whose status code is a non-configurable range (200 - 599):
/Users/diongrendelman/Projects/verbleif/my-jest-project/node_modules/@mswjs/interceptors/src/interceptors/ClientRequest/MockHttpSocket.ts:547:22
You can log out that response header received on that line (just go to the build *.js
/*.mjs
file, not the *.ts
) and see what kind of response is that, and whether it gives you any hints why your test receives that response.
I'm quite curious what kind of response that may be.
Cool, i tried looking int he builded js/mjs files but couldt reference it my self.
Hi @kettanaito it all happens because of the websocket stuff
I get a 201. Can i just disable the websocket stuff or something?
Are you using WebSockets in tests? I wonder what triggers 101, to begin with. That has to be your tested code or your test environment.
Are you using WebSockets in tests? I wonder what triggers 101, to begin with. That has to be your tested code or your test environment.
Yhea i created a full reproduction see https://github.com/stichingsd-vitrion/msw_jest_undici_reproduction
I do nothing special in my opinion. Do you also get it with repro? Would love to hear =)
diff --git a/node_modules/@mswjs/interceptors/lib/node/chunk-FPLETXGA.js b/node_modules/@mswjs/interceptors/lib/node/chunk-FPLETXGA.js
index 648938e..85e8a13 100644
--- a/node_modules/@mswjs/interceptors/lib/node/chunk-FPLETXGA.js
+++ b/node_modules/@mswjs/interceptors/lib/node/chunk-FPLETXGA.js
@@ -348,6 +348,7 @@ var MockHttpSocket = class extends MockSocket {
this.responseStream = new (0, _stream.Readable)({ read() {
} });
}
+ let newStatus = status > 200 ? status : 200
const response = new Response(
/**
* @note The Fetch API response instance exposed to the consumer
@@ -358,7 +359,7 @@ var MockHttpSocket = class extends MockSocket {
*/
canHaveBody ? _stream.Readable.toWeb(this.responseStream) : null,
{
- status,
+ status:newStatus,
statusText,
headers
}
diff --git a/node_modules/@mswjs/interceptors/lib/node/chunk-MG3S53QP.mjs b/node_modules/@mswjs/interceptors/lib/node/chunk-MG3S53QP.mjs
index c6d2383..33a8411 100644
--- a/node_modules/@mswjs/interceptors/lib/node/chunk-MG3S53QP.mjs
+++ b/node_modules/@mswjs/interceptors/lib/node/chunk-MG3S53QP.mjs
@@ -348,6 +348,8 @@ var MockHttpSocket = class extends MockSocket {
this.responseStream = new Readable({ read() {
} });
}
+ let newStatus = status > 200 ? status : 200;
+
const response = new Response(
/**
* @note The Fetch API response instance exposed to the consumer
@@ -358,7 +360,7 @@ var MockHttpSocket = class extends MockSocket {
*/
canHaveBody ? Readable.toWeb(this.responseStream) : null,
{
- status,
+ status:newStatus,
statusText,
headers
}
For now ill use this as a patch-package
same issue problem = console-ninja extenstion vscode console ninja using socket
Yeah, or e.g. Effect Devtools using socket
@Acetyld, thanks for publishing a reproduction repo! That package patch though, I don't recommend doing that. You are disrupting the data transfer, and responses like 101
won't be received and handled properly by Node.js. Do that at your own risk.
I will take a look at your repo once I have a minute and track down the root cause for this.
From the looks of it, this brings us back to non-configurable response status codes. We do something around this already in Interceptors, perhaps just not in MockHttpSocket
.
@wslp12 @tsteckenborn thanks for confirming this happens during WebSocket usage!
Yup! I also have Console Ninja, so @wslp12 thanks for pointing that out ๐
The fix is written in https://github.com/mswjs/interceptors/pull/677.
This has been released in v2.6.5!
Make sure to always update to the latest version (npm i msw@latest
) to get the newest features and bug fixes.
Predictable release automation by @ossjs/release.
Prerequisites
Environment check
msw
versionNode.js version
v22.3.0
Reproduction repository
https://github.com/stichingsd-vitrion/msw_jest_undici_reproduction
Reproduction steps
Current behavior
Expected behavior
No errors recarding Undici