Skip to content

Commit c2a5bb0

Browse files
committed
A few fixes for latest updates
1 parent 7498889 commit c2a5bb0

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

src/Frontend/public/mockServiceWorker.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* - Please do NOT serve this file on production.
99
*/
1010

11-
const PACKAGE_VERSION = '2.4.7'
12-
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
11+
const PACKAGE_VERSION = '2.6.6'
12+
const INTEGRITY_CHECKSUM = 'ca7800994cc8bfb5eb961e037c877074'
1313
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
1414
const activeClientIds = new Set()
1515

@@ -62,7 +62,12 @@ self.addEventListener('message', async function (event) {
6262

6363
sendToClient(client, {
6464
type: 'MOCKING_ENABLED',
65-
payload: true,
65+
payload: {
66+
client: {
67+
id: client.id,
68+
frameType: client.frameType,
69+
},
70+
},
6671
})
6772
break
6873
}
@@ -155,6 +160,10 @@ async function handleRequest(event, requestId) {
155160
async function resolveMainClient(event) {
156161
const client = await self.clients.get(event.clientId)
157162

163+
if (activeClientIds.has(event.clientId)) {
164+
return client
165+
}
166+
158167
if (client?.frameType === 'top-level') {
159168
return client
160169
}
@@ -183,12 +192,14 @@ async function getResponse(event, client, requestId) {
183192
const requestClone = request.clone()
184193

185194
function passthrough() {
186-
const headers = Object.fromEntries(requestClone.headers.entries())
187-
188-
// Remove internal MSW request header so the passthrough request
189-
// complies with any potential CORS preflight checks on the server.
190-
// Some servers forbid unknown request headers.
191-
delete headers['x-msw-intention']
195+
// Cast the request headers to a new Headers instance
196+
// so the headers can be manipulated with.
197+
const headers = new Headers(requestClone.headers)
198+
199+
// Remove the "accept" header value that marked this request as passthrough.
200+
// This prevents request alteration and also keeps it compliant with the
201+
// user-defined CORS policies.
202+
headers.delete('accept', 'msw/passthrough')
192203

193204
return fetch(requestClone, { headers })
194205
}

src/Frontend/test/driver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { type PathParams } from "msw";
2+
13
type GoTo = (path: string) => Promise<void>;
24
type DisposeApp = () => void;
35
export type MockEndpointOptions = {
@@ -16,7 +18,7 @@ export type MockEndpointDynamicOptions = {
1618
};
1719

1820
type MockEndpoint = (path: string, options: MockEndpointOptions) => void;
19-
type MockEndpointDynamic = (endpoint: string, callBack: (url: URL, params: { [key: string]: string | readonly string[] }) => MockEndpointDynamicOptions) => void;
21+
type MockEndpointDynamic = (endpoint: string, callBack: (url: URL, params: PathParams) => MockEndpointDynamicOptions) => void;
2022

2123
export type SetupFactoryOptions = {
2224
driver: Driver;

src/Frontend/test/mock-endpoint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { http, HttpResponse } from "msw";
1+
import { http, HttpResponse, type PathParams } from "msw";
22
import type { SetupWorker } from "msw/browser";
33
import { SetupServer } from "msw/node";
44
import { MockEndpointDynamicOptions, MockEndpointOptions } from "./driver";
@@ -11,7 +11,7 @@ export const makeMockEndpoint =
1111

1212
export const makeMockEndpointDynamic =
1313
({ mockServer }: { mockServer: SetupServer | SetupWorker }) =>
14-
(endpoint: string, callBack: (url: URL, params: { [key: string]: string | readonly string[] }) => MockEndpointDynamicOptions) => {
14+
(endpoint: string, callBack: (url: URL, params: PathParams) => MockEndpointDynamicOptions) => {
1515
mockServer.use(
1616
http.get(endpoint, ({ request, params }) => {
1717
const url = new URL(request.url.toString());

0 commit comments

Comments
 (0)