fix(deps): update dependency msw to ^2.10.2 (#1888)

* fix(deps): update dependency msw to ^2.10.2

* Update

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Nathan Bierema <nbierema@gmail.com>
This commit is contained in:
renovate[bot] 2025-06-17 23:32:57 +00:00 committed by GitHub
parent 54c40135e5
commit da5e9f0c1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 101 additions and 64 deletions

View File

@ -19,7 +19,7 @@
"@redux-devtools/dock-monitor": "workspace:^", "@redux-devtools/dock-monitor": "workspace:^",
"@redux-devtools/rtk-query-monitor": "workspace:^", "@redux-devtools/rtk-query-monitor": "workspace:^",
"@reduxjs/toolkit": "^2.8.2", "@reduxjs/toolkit": "^2.8.2",
"msw": "^2.8.7", "msw": "^2.10.2",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0", "react-dom": "^19.1.0",
"react-icons": "^5.5.0", "react-icons": "^5.5.0",

View File

@ -5,24 +5,23 @@
* Mock Service Worker. * Mock Service Worker.
* @see https://github.com/mswjs/msw * @see https://github.com/mswjs/msw
* - Please do NOT modify this file. * - Please do NOT modify this file.
* - Please do NOT serve this file on production.
*/ */
const PACKAGE_VERSION = '2.8.7' const PACKAGE_VERSION = '2.10.2'
const INTEGRITY_CHECKSUM = '00729d72e3b82faf54ca8b9621dbb96f' const INTEGRITY_CHECKSUM = 'f5825c521429caf22a4dd13b66e243af'
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse') const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
const activeClientIds = new Set() const activeClientIds = new Set()
self.addEventListener('install', function () { addEventListener('install', function () {
self.skipWaiting() self.skipWaiting()
}) })
self.addEventListener('activate', function (event) { addEventListener('activate', function (event) {
event.waitUntil(self.clients.claim()) event.waitUntil(self.clients.claim())
}) })
self.addEventListener('message', async function (event) { addEventListener('message', async function (event) {
const clientId = event.source.id const clientId = Reflect.get(event.source || {}, 'id')
if (!clientId || !self.clients) { if (!clientId || !self.clients) {
return return
@ -94,17 +93,18 @@ self.addEventListener('message', async function (event) {
} }
}) })
self.addEventListener('fetch', function (event) { addEventListener('fetch', function (event) {
const { request } = event
// Bypass navigation requests. // Bypass navigation requests.
if (request.mode === 'navigate') { if (event.request.mode === 'navigate') {
return return
} }
// Opening the DevTools triggers the "only-if-cached" request // Opening the DevTools triggers the "only-if-cached" request
// that cannot be handled by the worker. Bypass such requests. // that cannot be handled by the worker. Bypass such requests.
if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') { if (
event.request.cache === 'only-if-cached' &&
event.request.mode !== 'same-origin'
) {
return return
} }
@ -115,20 +115,26 @@ self.addEventListener('fetch', function (event) {
return return
} }
// Generate unique request ID.
const requestId = crypto.randomUUID() const requestId = crypto.randomUUID()
event.respondWith(handleRequest(event, requestId)) event.respondWith(handleRequest(event, requestId))
}) })
/**
* @param {FetchEvent} event
* @param {string} requestId
*/
async function handleRequest(event, requestId) { async function handleRequest(event, requestId) {
const client = await resolveMainClient(event) const client = await resolveMainClient(event)
const requestCloneForEvents = event.request.clone()
const response = await getResponse(event, client, requestId) const response = await getResponse(event, client, requestId)
// Send back the response clone for the "response:*" life-cycle events. // Send back the response clone for the "response:*" life-cycle events.
// Ensure MSW is active and ready to handle the message, otherwise // Ensure MSW is active and ready to handle the message, otherwise
// this message will pend indefinitely. // this message will pend indefinitely.
if (client && activeClientIds.has(client.id)) { if (client && activeClientIds.has(client.id)) {
;(async function () { const serializedRequest = await serializeRequest(requestCloneForEvents)
// Clone the response so both the client and the library could consume it.
const responseClone = response.clone() const responseClone = response.clone()
sendToClient( sendToClient(
@ -136,27 +142,35 @@ async function handleRequest(event, requestId) {
{ {
type: 'RESPONSE', type: 'RESPONSE',
payload: { payload: {
requestId,
isMockedResponse: IS_MOCKED_RESPONSE in response, isMockedResponse: IS_MOCKED_RESPONSE in response,
request: {
id: requestId,
...serializedRequest,
},
response: {
type: responseClone.type, type: responseClone.type,
status: responseClone.status, status: responseClone.status,
statusText: responseClone.statusText, statusText: responseClone.statusText,
body: responseClone.body,
headers: Object.fromEntries(responseClone.headers.entries()), headers: Object.fromEntries(responseClone.headers.entries()),
body: responseClone.body,
}, },
}, },
[responseClone.body], },
responseClone.body ? [serializedRequest.body, responseClone.body] : [],
) )
})()
} }
return response return response
} }
// Resolve the main client for the given event. /**
// Client that issues a request doesn't necessarily equal the client * Resolve the main client for the given event.
// that registered the worker. It's with the latter the worker should * Client that issues a request doesn't necessarily equal the client
// communicate with during the response resolving phase. * that registered the worker. It's with the latter the worker should
* communicate with during the response resolving phase.
* @param {FetchEvent} event
* @returns {Promise<Client | undefined>}
*/
async function resolveMainClient(event) { async function resolveMainClient(event) {
const client = await self.clients.get(event.clientId) const client = await self.clients.get(event.clientId)
@ -184,12 +198,16 @@ async function resolveMainClient(event) {
}) })
} }
/**
* @param {FetchEvent} event
* @param {Client | undefined} client
* @param {string} requestId
* @returns {Promise<Response>}
*/
async function getResponse(event, client, requestId) { async function getResponse(event, client, requestId) {
const { request } = event
// Clone the request because it might've been already used // Clone the request because it might've been already used
// (i.e. its body has been read and sent to the client). // (i.e. its body has been read and sent to the client).
const requestClone = request.clone() const requestClone = event.request.clone()
function passthrough() { function passthrough() {
// Cast the request headers to a new Headers instance // Cast the request headers to a new Headers instance
@ -230,29 +248,17 @@ async function getResponse(event, client, requestId) {
} }
// Notify the client that a request has been intercepted. // Notify the client that a request has been intercepted.
const requestBuffer = await request.arrayBuffer() const serializedRequest = await serializeRequest(event.request)
const clientMessage = await sendToClient( const clientMessage = await sendToClient(
client, client,
{ {
type: 'REQUEST', type: 'REQUEST',
payload: { payload: {
id: requestId, id: requestId,
url: request.url, ...serializedRequest,
mode: request.mode,
method: request.method,
headers: Object.fromEntries(request.headers.entries()),
cache: request.cache,
credentials: request.credentials,
destination: request.destination,
integrity: request.integrity,
redirect: request.redirect,
referrer: request.referrer,
referrerPolicy: request.referrerPolicy,
body: requestBuffer,
keepalive: request.keepalive,
}, },
}, },
[requestBuffer], [serializedRequest.body],
) )
switch (clientMessage.type) { switch (clientMessage.type) {
@ -268,6 +274,12 @@ async function getResponse(event, client, requestId) {
return passthrough() return passthrough()
} }
/**
* @param {Client} client
* @param {any} message
* @param {Array<Transferable>} transferrables
* @returns {Promise<any>}
*/
function sendToClient(client, message, transferrables = []) { function sendToClient(client, message, transferrables = []) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const channel = new MessageChannel() const channel = new MessageChannel()
@ -280,14 +292,18 @@ function sendToClient(client, message, transferrables = []) {
resolve(event.data) resolve(event.data)
} }
client.postMessage( client.postMessage(message, [
message, channel.port2,
[channel.port2].concat(transferrables.filter(Boolean)), ...transferrables.filter(Boolean),
) ])
}) })
} }
async function respondWithMock(response) { /**
* @param {Response} response
* @returns {Response}
*/
function respondWithMock(response) {
// Setting response status code to 0 is a no-op. // Setting response status code to 0 is a no-op.
// However, when responding with a "Response.error()", the produced Response // However, when responding with a "Response.error()", the produced Response
// instance will have status code set to 0. Since it's not possible to create // instance will have status code set to 0. Since it's not possible to create
@ -305,3 +321,24 @@ async function respondWithMock(response) {
return mockedResponse return mockedResponse
} }
/**
* @param {Request} request
*/
async function serializeRequest(request) {
return {
url: request.url,
mode: request.mode,
method: request.method,
headers: Object.fromEntries(request.headers.entries()),
cache: request.cache,
credentials: request.credentials,
destination: request.destination,
integrity: request.integrity,
redirect: request.redirect,
referrer: request.referrer,
referrerPolicy: request.referrerPolicy,
body: await request.arrayBuffer(),
keepalive: request.keepalive,
}
}

View File

@ -2063,8 +2063,8 @@ importers:
specifier: ^2.8.2 specifier: ^2.8.2
version: 2.8.2(react-redux@9.2.0(@types/react@19.1.6)(react@19.1.0)(redux@5.0.1))(react@19.1.0) version: 2.8.2(react-redux@9.2.0(@types/react@19.1.6)(react@19.1.0)(redux@5.0.1))(react@19.1.0)
msw: msw:
specifier: ^2.8.7 specifier: ^2.10.2
version: 2.8.7(@types/node@22.15.21)(typescript@5.8.3) version: 2.10.2(@types/node@22.15.21)(typescript@5.8.3)
react: react:
specifier: ^19.1.0 specifier: ^19.1.0
version: 19.1.0 version: 19.1.0
@ -4074,8 +4074,8 @@ packages:
'@mswjs/data@0.16.2': '@mswjs/data@0.16.2':
resolution: {integrity: sha512-/C0d/PBcJyQJokUhcjO4HiZPc67hzllKlRtD1XELygl2t991/ATAAQJVcStn4YtVALsNodruzOHT0JIvgr0hnA==} resolution: {integrity: sha512-/C0d/PBcJyQJokUhcjO4HiZPc67hzllKlRtD1XELygl2t991/ATAAQJVcStn4YtVALsNodruzOHT0JIvgr0hnA==}
'@mswjs/interceptors@0.38.7': '@mswjs/interceptors@0.39.2':
resolution: {integrity: sha512-Jkb27iSn7JPdkqlTqKfhncFfnEZsIJVYxsFbUSWEkxdIPdsyngrhoDBk0/BGD2FQcRH99vlRrkHpNTyKqI+0/w==} resolution: {integrity: sha512-RuzCup9Ct91Y7V79xwCb146RaBRHZ7NBbrIUySumd1rpKqHL5OonaqrGIbug5hNwP/fRyxFMA6ISgw4FTtYFYg==}
engines: {node: '>=18'} engines: {node: '>=18'}
'@nicolo-ribaudo/chokidar-2@2.1.8-no-fsevents.3': '@nicolo-ribaudo/chokidar-2@2.1.8-no-fsevents.3':
@ -8157,8 +8157,8 @@ packages:
ms@2.1.3: ms@2.1.3:
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
msw@2.8.7: msw@2.10.2:
resolution: {integrity: sha512-0TGfV4oQiKpa3pDsQBDf0xvFP+sRrqEOnh2n1JWpHVKHJHLv6ZmY1HCZpCi7uDiJTeIHJMBpmBiRmBJN+ETPSQ==} resolution: {integrity: sha512-RCKM6IZseZQCWcSWlutdf590M8nVfRHG1ImwzOtwz8IYxgT4zhUO0rfTcTvDGiaFE0Rhcc+h43lcF3Jc9gFtwQ==}
engines: {node: '>=18'} engines: {node: '>=18'}
hasBin: true hasBin: true
peerDependencies: peerDependencies:
@ -11876,13 +11876,13 @@ snapshots:
strict-event-emitter: 0.5.1 strict-event-emitter: 0.5.1
uuid: 8.3.2 uuid: 8.3.2
optionalDependencies: optionalDependencies:
msw: 2.8.7(@types/node@22.15.21)(typescript@5.8.3) msw: 2.10.2(@types/node@22.15.21)(typescript@5.8.3)
transitivePeerDependencies: transitivePeerDependencies:
- '@types/node' - '@types/node'
- supports-color - supports-color
- typescript - typescript
'@mswjs/interceptors@0.38.7': '@mswjs/interceptors@0.39.2':
dependencies: dependencies:
'@open-draft/deferred-promise': 2.2.0 '@open-draft/deferred-promise': 2.2.0
'@open-draft/logger': 0.3.0 '@open-draft/logger': 0.3.0
@ -16826,13 +16826,13 @@ snapshots:
ms@2.1.3: {} ms@2.1.3: {}
msw@2.8.7(@types/node@22.15.21)(typescript@5.8.3): msw@2.10.2(@types/node@22.15.21)(typescript@5.8.3):
dependencies: dependencies:
'@bundled-es-modules/cookie': 2.0.1 '@bundled-es-modules/cookie': 2.0.1
'@bundled-es-modules/statuses': 1.0.1 '@bundled-es-modules/statuses': 1.0.1
'@bundled-es-modules/tough-cookie': 0.1.6 '@bundled-es-modules/tough-cookie': 0.1.6
'@inquirer/confirm': 5.1.10(@types/node@22.15.21) '@inquirer/confirm': 5.1.10(@types/node@22.15.21)
'@mswjs/interceptors': 0.38.7 '@mswjs/interceptors': 0.39.2
'@open-draft/deferred-promise': 2.2.0 '@open-draft/deferred-promise': 2.2.0
'@open-draft/until': 2.1.0 '@open-draft/until': 2.1.0
'@types/cookie': 0.6.0 '@types/cookie': 0.6.0