msw 2.2.12 → 2.2.13

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.
@@ -8,7 +8,7 @@
8
8
  * - Please do NOT serve this file on production.
9
9
  */
10
10
 
11
- const PACKAGE_VERSION = '2.2.12'
11
+ const PACKAGE_VERSION = '2.2.13'
12
12
  const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
13
13
  const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
14
14
  const activeClientIds = new Set()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "msw",
3
- "version": "2.2.12",
3
+ "version": "2.2.13",
4
4
  "description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
5
5
  "main": "./lib/core/index.js",
6
6
  "module": "./lib/core/index.mjs",
@@ -105,7 +105,7 @@
105
105
  "@bundled-es-modules/statuses": "^1.0.1",
106
106
  "@inquirer/confirm": "^3.0.0",
107
107
  "@mswjs/cookies": "^1.1.0",
108
- "@mswjs/interceptors": "^0.26.12",
108
+ "@mswjs/interceptors": "^0.26.14",
109
109
  "@open-draft/until": "^2.1.0",
110
110
  "@types/cookie": "^0.6.0",
111
111
  "@types/statuses": "^2.0.4",
@@ -1,6 +1,6 @@
1
+ import { createRequestId } from '@mswjs/interceptors'
1
2
  import type { RequestHandler } from './handlers/RequestHandler'
2
3
  import { executeHandlers } from './utils/executeHandlers'
3
- import { randomId } from './utils/internal/randomId'
4
4
 
5
5
  /**
6
6
  * Finds a response for the given request instance
@@ -15,7 +15,7 @@ export const getResponse = async (
15
15
  ): Promise<Response | undefined> => {
16
16
  const result = await executeHandlers({
17
17
  request,
18
- requestId: randomId(),
18
+ requestId: createRequestId(),
19
19
  handlers,
20
20
  })
21
21
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @vitest-environment jsdom
3
3
  */
4
- import { encodeBuffer } from '@mswjs/interceptors'
4
+ import { createRequestId, encodeBuffer } from '@mswjs/interceptors'
5
5
  import { OperationTypeNode, parse } from 'graphql'
6
6
  import {
7
7
  GraphQLHandler,
@@ -9,7 +9,6 @@ import {
9
9
  GraphQLResolverExtras,
10
10
  isDocumentNode,
11
11
  } from './GraphQLHandler'
12
- import { randomId } from '../utils/internal/randomId'
13
12
  import { HttpResponse } from '../HttpResponse'
14
13
  import { ResponseResolver } from './RequestHandler'
15
14
 
@@ -737,7 +736,7 @@ describe('run', () => {
737
736
  userId: 'abc-123',
738
737
  },
739
738
  })
740
- const requestId = randomId()
739
+ const requestId = createRequestId()
741
740
  const result = await handler.run({ request, requestId })
742
741
 
743
742
  expect(result!.handler).toEqual(handler)
@@ -779,7 +778,7 @@ describe('run', () => {
779
778
  const request = createPostGraphQLRequest({
780
779
  query: LOGIN,
781
780
  })
782
- const requestId = randomId()
781
+ const requestId = createRequestId()
783
782
  const result = await handler.run({ request, requestId })
784
783
 
785
784
  expect(result).toBeNull()
@@ -827,7 +826,7 @@ describe('request', () => {
827
826
  `,
828
827
  })
829
828
 
830
- const requestId = randomId()
829
+ const requestId = createRequestId()
831
830
  await handler.run({ request, requestId })
832
831
 
833
832
  expect(matchAllResolver).toHaveBeenCalledTimes(1)
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @vitest-environment jsdom
3
3
  */
4
- import { randomId } from '../utils/internal/randomId'
4
+ import { createRequestId } from '@mswjs/interceptors'
5
5
  import { HttpHandler, HttpRequestResolverExtras } from './HttpHandler'
6
6
  import { HttpResponse } from '..'
7
7
  import { ResponseResolver } from './RequestHandler'
@@ -152,7 +152,7 @@ describe('run', () => {
152
152
  test('returns a mocked response given a matching request', async () => {
153
153
  const handler = new HttpHandler('GET', '/user/:userId', resolver)
154
154
  const request = new Request(new URL('/user/abc-123', location.href))
155
- const requestId = randomId()
155
+ const requestId = createRequestId()
156
156
  const result = await handler.run({ request, requestId })
157
157
 
158
158
  expect(result!.handler).toEqual(handler)
@@ -176,7 +176,7 @@ describe('run', () => {
176
176
  const handler = new HttpHandler('POST', '/login', resolver)
177
177
  const result = await handler.run({
178
178
  request: new Request(new URL('/users', location.href)),
179
- requestId: randomId(),
179
+ requestId: createRequestId(),
180
180
  })
181
181
 
182
182
  expect(result).toBeNull()
@@ -186,7 +186,7 @@ describe('run', () => {
186
186
  const handler = new HttpHandler('GET', '/users', resolver)
187
187
  const result = await handler.run({
188
188
  request: new Request(new URL('/users', location.href)),
189
- requestId: randomId(),
189
+ requestId: createRequestId(),
190
190
  })
191
191
 
192
192
  expect(result?.parsedResult?.match?.params).toEqual({})
@@ -207,7 +207,7 @@ describe('run', () => {
207
207
  const run = async () => {
208
208
  const result = await handler.run({
209
209
  request: new Request(new URL('/users', location.href)),
210
- requestId: randomId(),
210
+ requestId: createRequestId(),
211
211
  })
212
212
  return result?.response?.text()
213
213
  }
@@ -2,12 +2,12 @@
2
2
  * @vitest-environment jsdom
3
3
  */
4
4
  import { Emitter } from 'strict-event-emitter'
5
+ import { createRequestId } from '@mswjs/interceptors'
5
6
  import { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'
6
7
  import { RequestHandler } from '../handlers/RequestHandler'
7
8
  import { http } from '../http'
8
9
  import { handleRequest, HandleRequestOptions } from './handleRequest'
9
10
  import { RequiredDeep } from '../typeUtils'
10
- import { randomId } from './internal/randomId'
11
11
  import { HttpResponse } from '../HttpResponse'
12
12
  import { passthrough } from '../passthrough'
13
13
 
@@ -51,7 +51,7 @@ afterEach(() => {
51
51
  test('returns undefined for a request with the "x-msw-intention" header equal to "bypass"', async () => {
52
52
  const { emitter, events } = setup()
53
53
 
54
- const requestId = randomId()
54
+ const requestId = createRequestId()
55
55
  const request = new Request(new URL('http://localhost/user'), {
56
56
  headers: new Headers({
57
57
  'x-msw-intention': 'bypass',
@@ -97,7 +97,7 @@ test('does not bypass a request with "x-msw-intention" header set to arbitrary v
97
97
 
98
98
  const result = await handleRequest(
99
99
  request,
100
- randomId(),
100
+ createRequestId(),
101
101
  handlers,
102
102
  options,
103
103
  emitter,
@@ -112,7 +112,7 @@ test('does not bypass a request with "x-msw-intention" header set to arbitrary v
112
112
  test('reports request as unhandled when it has no matching request handlers', async () => {
113
113
  const { emitter, events } = setup()
114
114
 
115
- const requestId = randomId()
115
+ const requestId = createRequestId()
116
116
  const request = new Request(new URL('http://localhost/user'))
117
117
  const handlers: Array<RequestHandler> = []
118
118
 
@@ -145,7 +145,7 @@ test('reports request as unhandled when it has no matching request handlers', as
145
145
  test('returns undefined on a request handler that returns no response', async () => {
146
146
  const { emitter, events } = setup()
147
147
 
148
- const requestId = randomId()
148
+ const requestId = createRequestId()
149
149
  const request = new Request(new URL('http://localhost/user'))
150
150
  const handlers: Array<RequestHandler> = [
151
151
  http.get('/user', () => {
@@ -184,7 +184,7 @@ test('returns undefined on a request handler that returns no response', async ()
184
184
  test('returns the mocked response for a request with a matching request handler', async () => {
185
185
  const { emitter, events } = setup()
186
186
 
187
- const requestId = randomId()
187
+ const requestId = createRequestId()
188
188
  const request = new Request(new URL('http://localhost/user'))
189
189
  const mockedResponse = HttpResponse.json({ firstName: 'John' })
190
190
  const handlers: Array<RequestHandler> = [
@@ -242,7 +242,7 @@ test('returns the mocked response for a request with a matching request handler'
242
242
  test('returns a transformed response if the "transformResponse" option is provided', async () => {
243
243
  const { emitter, events } = setup()
244
244
 
245
- const requestId = randomId()
245
+ const requestId = createRequestId()
246
246
  const request = new Request(new URL('http://localhost/user'))
247
247
  const mockedResponse = HttpResponse.json({ firstName: 'John' })
248
248
  const handlers: Array<RequestHandler> = [
@@ -325,7 +325,7 @@ test('returns a transformed response if the "transformResponse" option is provid
325
325
  it('returns undefined without warning on a passthrough request', async () => {
326
326
  const { emitter, events } = setup()
327
327
 
328
- const requestId = randomId()
328
+ const requestId = createRequestId()
329
329
  const request = new Request(new URL('http://localhost/user'))
330
330
  const handlers: Array<RequestHandler> = [
331
331
  http.get('/user', () => {
@@ -358,7 +358,7 @@ it('returns undefined without warning on a passthrough request', async () => {
358
358
  it('calls the handler with the requestId', async () => {
359
359
  const { emitter } = setup()
360
360
 
361
- const requestId = randomId()
361
+ const requestId = createRequestId()
362
362
  const request = new Request(new URL('http://localhost/user'))
363
363
  const handlerFn = vi.fn()
364
364
  const handlers: Array<RequestHandler> = [http.get('/user', handlerFn)]
@@ -390,7 +390,7 @@ it('marks the first matching one-time handler as used', async () => {
390
390
  })
391
391
  const handlers: Array<RequestHandler> = [oneTimeHandler, anotherHandler]
392
392
 
393
- const requestId = randomId()
393
+ const requestId = createRequestId()
394
394
  const request = new Request('http://localhost/resource')
395
395
  const firstResult = await handleRequest(
396
396
  request,
@@ -438,7 +438,7 @@ it('does not mark non-matching one-time handlers as used', async () => {
438
438
  )
439
439
  const handlers: Array<RequestHandler> = [oneTimeHandler, anotherHandler]
440
440
 
441
- const requestId = randomId()
441
+ const requestId = createRequestId()
442
442
  const firstResult = await handleRequest(
443
443
  new Request('http://localhost/another'),
444
444
  requestId,
@@ -481,7 +481,7 @@ it('handles parallel requests with one-time handlers', async () => {
481
481
  })
482
482
  const handlers: Array<RequestHandler> = [oneTimeHandler, anotherHandler]
483
483
 
484
- const requestId = randomId()
484
+ const requestId = createRequestId()
485
485
  const request = new Request('http://localhost/resource')
486
486
  const firstResultPromise = handleRequest(
487
487
  request,
@@ -526,7 +526,7 @@ describe('[Private] - resolutionContext - used for extensions', () => {
526
526
 
527
527
  const handlers: Array<RequestHandler> = [handler]
528
528
 
529
- const requestId = randomId()
529
+ const requestId = createRequestId()
530
530
  const request = new Request(new URL('/resource', baseUrl))
531
531
  const response = await handleRequest(
532
532
  request,
@@ -555,7 +555,7 @@ describe('[Private] - resolutionContext - used for extensions', () => {
555
555
 
556
556
  const handlers: Array<RequestHandler> = [handler]
557
557
 
558
- const requestId = randomId()
558
+ const requestId = createRequestId()
559
559
  const request = new Request(
560
560
  new URL('/resource', `http://not-the-base-url.com`),
561
561
  )
@@ -1,3 +0,0 @@
1
- declare function randomId(): string;
2
-
3
- export { randomId };
@@ -1,3 +0,0 @@
1
- declare function randomId(): string;
2
-
3
- export { randomId };
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var randomId_exports = {};
20
- __export(randomId_exports, {
21
- randomId: () => randomId
22
- });
23
- module.exports = __toCommonJS(randomId_exports);
24
- function randomId() {
25
- return Math.random().toString(16).slice(2);
26
- }
27
- //# sourceMappingURL=randomId.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/core/utils/internal/randomId.ts"],"sourcesContent":["export function randomId(): string {\n return Math.random().toString(16).slice(2)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,WAAmB;AACjC,SAAO,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC;AAC3C;","names":[]}
@@ -1,7 +0,0 @@
1
- function randomId() {
2
- return Math.random().toString(16).slice(2);
3
- }
4
- export {
5
- randomId
6
- };
7
- //# sourceMappingURL=randomId.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/core/utils/internal/randomId.ts"],"sourcesContent":["export function randomId(): string {\n return Math.random().toString(16).slice(2)\n}\n"],"mappings":"AAAO,SAAS,WAAmB;AACjC,SAAO,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC;AAC3C;","names":[]}
@@ -1,3 +0,0 @@
1
- export function randomId(): string {
2
- return Math.random().toString(16).slice(2)
3
- }