msw 0.44.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.
@@ -2,13 +2,13 @@
2
2
  /* tslint:disable */
3
3
 
4
4
  /**
5
- * Mock Service Worker (0.44.1).
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 = 'df0d85222361310ecbe1792c606e08f2'
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.payload)
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.payload
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()
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "msw",
3
- "version": "0.44.1",
3
+ "version": "0.44.2",
4
4
  "description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",