msw 0.43.1 → 0.44.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{glossary-58eca5a8.d.ts → glossary-297d38ba.d.ts} +48 -26
- package/lib/iife/index.js +4847 -2318
- package/lib/iife/index.js.map +1 -1
- package/lib/index.d.ts +11 -14
- package/lib/index.js +283 -329
- package/lib/index.js.map +1 -1
- package/lib/mockServiceWorker.js +5 -69
- package/lib/native/index.d.ts +1 -1
- package/lib/native/index.js +480 -458
- package/lib/native/index.mjs +470 -448
- package/lib/node/index.d.ts +2 -2
- package/lib/node/index.js +480 -458
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +470 -448
- package/lib/node/index.mjs.map +1 -1
- package/package.json +7 -4
package/lib/mockServiceWorker.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
/* tslint:disable */
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Mock Service Worker (0.
|
|
5
|
+
* Mock Service Worker (0.44.2).
|
|
6
6
|
* @see https://github.com/mswjs/msw
|
|
7
7
|
* - Please do NOT modify this file.
|
|
8
8
|
* - Please do NOT serve this file on production.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const INTEGRITY_CHECKSUM = '
|
|
11
|
+
const INTEGRITY_CHECKSUM = 'b3066ef78c2f9090b4ce87e874965995'
|
|
12
12
|
const activeClientIds = new Set()
|
|
13
13
|
|
|
14
14
|
self.addEventListener('install', function () {
|
|
@@ -231,13 +231,6 @@ async function getResponse(event, client, requestId) {
|
|
|
231
231
|
return passthrough()
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
// Create a communication channel scoped to the current request.
|
|
235
|
-
// This way events can be exchanged outside of the worker's global
|
|
236
|
-
// "message" event listener (i.e. abstracted into functions).
|
|
237
|
-
const operationChannel = new BroadcastChannel(
|
|
238
|
-
`msw-response-stream-${requestId}`,
|
|
239
|
-
)
|
|
240
|
-
|
|
241
234
|
// Notify the client that a request has been intercepted.
|
|
242
235
|
const clientMessage = await sendToClient(client, {
|
|
243
236
|
type: 'REQUEST',
|
|
@@ -262,11 +255,7 @@ async function getResponse(event, client, requestId) {
|
|
|
262
255
|
|
|
263
256
|
switch (clientMessage.type) {
|
|
264
257
|
case 'MOCK_RESPONSE': {
|
|
265
|
-
return respondWithMock(clientMessage.
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
case 'MOCK_RESPONSE_START': {
|
|
269
|
-
return respondWithMockStream(operationChannel, clientMessage.payload)
|
|
258
|
+
return respondWithMock(clientMessage.data)
|
|
270
259
|
}
|
|
271
260
|
|
|
272
261
|
case 'MOCK_NOT_FOUND': {
|
|
@@ -274,31 +263,13 @@ async function getResponse(event, client, requestId) {
|
|
|
274
263
|
}
|
|
275
264
|
|
|
276
265
|
case 'NETWORK_ERROR': {
|
|
277
|
-
const { name, message } = clientMessage.
|
|
266
|
+
const { name, message } = clientMessage.data
|
|
278
267
|
const networkError = new Error(message)
|
|
279
268
|
networkError.name = name
|
|
280
269
|
|
|
281
270
|
// Rejecting a "respondWith" promise emulates a network error.
|
|
282
271
|
throw networkError
|
|
283
272
|
}
|
|
284
|
-
|
|
285
|
-
case 'INTERNAL_ERROR': {
|
|
286
|
-
const parsedBody = JSON.parse(clientMessage.payload.body)
|
|
287
|
-
|
|
288
|
-
console.error(
|
|
289
|
-
`\
|
|
290
|
-
[MSW] Uncaught exception in the request handler for "%s %s":
|
|
291
|
-
|
|
292
|
-
${parsedBody.location}
|
|
293
|
-
|
|
294
|
-
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/recipes/mocking-error-responses\
|
|
295
|
-
`,
|
|
296
|
-
request.method,
|
|
297
|
-
request.url,
|
|
298
|
-
)
|
|
299
|
-
|
|
300
|
-
return respondWithMock(clientMessage.payload)
|
|
301
|
-
}
|
|
302
273
|
}
|
|
303
274
|
|
|
304
275
|
return passthrough()
|
|
@@ -316,7 +287,7 @@ function sendToClient(client, message) {
|
|
|
316
287
|
resolve(event.data)
|
|
317
288
|
}
|
|
318
289
|
|
|
319
|
-
client.postMessage(
|
|
290
|
+
client.postMessage(message, [channel.port2])
|
|
320
291
|
})
|
|
321
292
|
}
|
|
322
293
|
|
|
@@ -330,38 +301,3 @@ async function respondWithMock(response) {
|
|
|
330
301
|
await sleep(response.delay)
|
|
331
302
|
return new Response(response.body, response)
|
|
332
303
|
}
|
|
333
|
-
|
|
334
|
-
function respondWithMockStream(operationChannel, mockResponse) {
|
|
335
|
-
let streamCtrl
|
|
336
|
-
const stream = new ReadableStream({
|
|
337
|
-
start: (controller) => (streamCtrl = controller),
|
|
338
|
-
})
|
|
339
|
-
|
|
340
|
-
return new Promise(async (resolve, reject) => {
|
|
341
|
-
operationChannel.onmessageerror = (event) => {
|
|
342
|
-
operationChannel.close()
|
|
343
|
-
return reject(event.data.error)
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
operationChannel.onmessage = (event) => {
|
|
347
|
-
if (!event.data) {
|
|
348
|
-
return
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
switch (event.data.type) {
|
|
352
|
-
case 'MOCK_RESPONSE_CHUNK': {
|
|
353
|
-
streamCtrl.enqueue(event.data.payload)
|
|
354
|
-
break
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
case 'MOCK_RESPONSE_END': {
|
|
358
|
-
streamCtrl.close()
|
|
359
|
-
operationChannel.close()
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
await sleep(mockResponse.delay)
|
|
365
|
-
return resolve(new Response(stream, mockResponse))
|
|
366
|
-
})
|
|
367
|
-
}
|
package/lib/native/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as RequestHandler, i as RequestHandlerDefaultInfo, M as MockedRequest, c as DefaultBodyType,
|
|
1
|
+
import { b as RequestHandler, i as RequestHandlerDefaultInfo, M as MockedRequest, c as DefaultBodyType, I as SetupServerApi } from '../glossary-297d38ba.js';
|
|
2
2
|
import 'type-fest';
|
|
3
3
|
import '@mswjs/interceptors';
|
|
4
4
|
import 'headers-polyfill';
|