Skip to content

Commit 5bf3e3b

Browse files
authored
fix: support non-configurable responses (#2360)
1 parent c40eac6 commit 5bf3e3b

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
"@bundled-es-modules/statuses": "^1.0.1",
144144
"@bundled-es-modules/tough-cookie": "^0.1.6",
145145
"@inquirer/confirm": "^5.0.0",
146-
"@mswjs/interceptors": "^0.36.5",
146+
"@mswjs/interceptors": "^0.37.0",
147147
"@open-draft/deferred-promise": "^2.2.0",
148148
"@open-draft/until": "^2.1.0",
149149
"@types/cookie": "^0.6.0",

pnpm-lock.yaml

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/browser/setupWorker/start/createResponseListener.ts

+14-19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { FetchResponse } from '@mswjs/interceptors'
12
import type {
23
ServiceWorkerIncomingEventsMap,
34
SetupWorkerInternalContext,
45
} from '../glossary'
56
import type { ServiceWorkerMessage } from './utils/createMessageChannel'
6-
import { isResponseWithoutBody } from '@mswjs/interceptors'
77

88
export function createResponseListener(context: SetupWorkerInternalContext) {
99
return (
@@ -35,32 +35,27 @@ export function createResponseListener(context: SetupWorkerInternalContext) {
3535
const response =
3636
responseJson.status === 0
3737
? Response.error()
38-
: new Response(
38+
: new FetchResponse(
3939
/**
4040
* Responses may be streams here, but when we create a response object
4141
* with null-body status codes, like 204, 205, 304 Response will
4242
* throw when passed a non-null body, so ensure it's null here
4343
* for those codes
4444
*/
45-
isResponseWithoutBody(responseJson.status)
46-
? null
47-
: responseJson.body,
48-
responseJson,
45+
FetchResponse.isResponseWithBody(responseJson.status)
46+
? responseJson.body
47+
: null,
48+
{
49+
...responseJson,
50+
/**
51+
* Set response URL if it's not set already.
52+
* @see https://github.com/mswjs/msw/issues/2030
53+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/url
54+
*/
55+
url: request.url,
56+
},
4957
)
5058

51-
/**
52-
* Set response URL if it's not set already.
53-
* @see https://github.com/mswjs/msw/issues/2030
54-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/url
55-
*/
56-
if (!response.url) {
57-
Object.defineProperty(response, 'url', {
58-
value: request.url,
59-
enumerable: true,
60-
writable: false,
61-
})
62-
}
63-
6459
context.emitter.emit(
6560
responseJson.isMockedResponse ? 'response:mocked' : 'response:bypass',
6661
{

0 commit comments

Comments
 (0)