msw 2.1.6 → 2.1.7
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/browser/index.js +17 -16
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +17 -16
- package/lib/browser/index.mjs.map +1 -1
- package/lib/iife/index.js +17 -16
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.js +5 -1
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +5 -1
- package/lib/native/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/native/index.ts +5 -1
package/lib/mockServiceWorker.js
CHANGED
package/lib/native/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(native_exports, {
|
|
|
23
23
|
setupServer: () => setupServer
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(native_exports);
|
|
26
|
+
var import_fetch = require("@mswjs/interceptors/fetch");
|
|
26
27
|
var import_XMLHttpRequest = require("@mswjs/interceptors/XMLHttpRequest");
|
|
27
28
|
|
|
28
29
|
// src/node/SetupServerApi.ts
|
|
@@ -104,7 +105,10 @@ var SetupServerApi = class extends import_SetupApi.SetupApi {
|
|
|
104
105
|
|
|
105
106
|
// src/native/index.ts
|
|
106
107
|
function setupServer(...handlers) {
|
|
107
|
-
return new SetupServerApi(
|
|
108
|
+
return new SetupServerApi(
|
|
109
|
+
[import_fetch.FetchInterceptor, import_XMLHttpRequest.XMLHttpRequestInterceptor],
|
|
110
|
+
...handlers
|
|
111
|
+
);
|
|
108
112
|
}
|
|
109
113
|
// Annotate the CommonJS export names for ESM import in node:
|
|
110
114
|
0 && (module.exports = {
|
package/lib/native/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerApi.ts"],"sourcesContent":["import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerApi } from '../node/SetupServerApi'\n\n/**\n * Sets up a requests interception in React Native with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport function setupServer(\n ...handlers: Array<RequestHandler>\n): SetupServerApi {\n // Provision request interception via patching the `XMLHttpRequest` class only\n // in React Native. There is no `http`/`https` modules in that environment.\n return new SetupServerApi([XMLHttpRequestInterceptor]
|
|
1
|
+
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerApi.ts"],"sourcesContent":["import { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerApi } from '../node/SetupServerApi'\n\n/**\n * Sets up a requests interception in React Native with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport function setupServer(\n ...handlers: Array<RequestHandler>\n): SetupServerApi {\n // Provision request interception via patching the `XMLHttpRequest` class only\n // in React Native. There is no `http`/`https` modules in that environment.\n return new SetupServerApi(\n [FetchInterceptor, XMLHttpRequestInterceptor],\n ...handlers,\n )\n}\n","import {\n BatchInterceptor,\n HttpRequestEventMap,\n Interceptor,\n InterceptorReadyState,\n} from '@mswjs/interceptors'\nimport { invariant } from 'outvariant'\nimport { SetupApi } from '~/core/SetupApi'\nimport { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { RequiredDeep } from '~/core/typeUtils'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport { devUtils } from '~/core/utils/internal/devUtils'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { SetupServer } from './glossary'\n\nconst DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServer\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{\n new (): Interceptor<HttpRequestEventMap>\n }>,\n ...handlers: Array<RequestHandler>\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\n this.resolvedOptions = {} as RequiredDeep<SharedOptions>\n\n this.init()\n }\n\n /**\n * Subscribe to all requests that are using the interceptor object\n */\n private init(): void {\n this.interceptor.on('request', async ({ request, requestId }) => {\n const response = await handleRequest(\n request,\n requestId,\n this.currentHandlers,\n this.resolvedOptions,\n this.emitter,\n )\n\n if (response) {\n request.respondWith(response)\n }\n\n return\n })\n\n this.interceptor.on(\n 'response',\n ({ response, isMockedResponse, request, requestId }) => {\n this.emitter.emit(\n isMockedResponse ? 'response:mocked' : 'response:bypass',\n {\n response,\n request,\n requestId,\n },\n )\n },\n )\n }\n\n public listen(options: Partial<SharedOptions> = {}): void {\n this.resolvedOptions = mergeRight(\n DEFAULT_LISTEN_OPTIONS,\n options,\n ) as RequiredDeep<SharedOptions>\n\n // Apply the interceptor when starting the server.\n this.interceptor.apply()\n\n this.subscriptions.push(() => {\n this.interceptor.dispose()\n })\n\n // Assert that the interceptor has been applied successfully.\n // Also guards us from forgetting to call \"interceptor.apply()\"\n // as a part of the \"listen\" method.\n invariant(\n [InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(\n this.interceptor.readyState,\n ),\n devUtils.formatMessage(\n 'Failed to start \"setupServer\": the interceptor failed to apply. This is likely an issue with the library and you should report it at \"%s\".',\n ),\n 'https://github.com/mswjs/msw/issues/new/choose',\n )\n }\n\n public close(): void {\n this.dispose()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;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C,0CAAsB,UAAU,0CAAsB,OAAO,EAAE;AAAA,QAC9D,KAAK,YAAY;AAAA,MACnB;AAAA,MACA,yBAAS;AAAA,QACP;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEO,QAAc;AACnB,SAAK,QAAQ;AAAA,EACf;AACF;;;ADrGO,SAAS,eACX,UACa;AAGhB,SAAO,IAAI;AAAA,IACT,CAAC,+BAAkB,+CAAyB;AAAA,IAC5C,GAAG;AAAA,EACL;AACF;","names":["Interceptor"]}
|
package/lib/native/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/native/index.ts
|
|
2
|
+
import { FetchInterceptor } from "@mswjs/interceptors/fetch";
|
|
2
3
|
import { XMLHttpRequestInterceptor } from "@mswjs/interceptors/XMLHttpRequest";
|
|
3
4
|
|
|
4
5
|
// src/node/SetupServerApi.ts
|
|
@@ -83,7 +84,10 @@ var SetupServerApi = class extends SetupApi {
|
|
|
83
84
|
|
|
84
85
|
// src/native/index.ts
|
|
85
86
|
function setupServer(...handlers) {
|
|
86
|
-
return new SetupServerApi(
|
|
87
|
+
return new SetupServerApi(
|
|
88
|
+
[FetchInterceptor, XMLHttpRequestInterceptor],
|
|
89
|
+
...handlers
|
|
90
|
+
);
|
|
87
91
|
}
|
|
88
92
|
export {
|
|
89
93
|
setupServer
|
package/lib/native/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerApi.ts"],"sourcesContent":["import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerApi } from '../node/SetupServerApi'\n\n/**\n * Sets up a requests interception in React Native with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport function setupServer(\n ...handlers: Array<RequestHandler>\n): SetupServerApi {\n // Provision request interception via patching the `XMLHttpRequest` class only\n // in React Native. There is no `http`/`https` modules in that environment.\n return new SetupServerApi([XMLHttpRequestInterceptor]
|
|
1
|
+
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerApi.ts"],"sourcesContent":["import { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerApi } from '../node/SetupServerApi'\n\n/**\n * Sets up a requests interception in React Native with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport function setupServer(\n ...handlers: Array<RequestHandler>\n): SetupServerApi {\n // Provision request interception via patching the `XMLHttpRequest` class only\n // in React Native. There is no `http`/`https` modules in that environment.\n return new SetupServerApi(\n [FetchInterceptor, XMLHttpRequestInterceptor],\n ...handlers,\n )\n}\n","import {\n BatchInterceptor,\n HttpRequestEventMap,\n Interceptor,\n InterceptorReadyState,\n} from '@mswjs/interceptors'\nimport { invariant } from 'outvariant'\nimport { SetupApi } from '~/core/SetupApi'\nimport { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { RequiredDeep } from '~/core/typeUtils'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport { devUtils } from '~/core/utils/internal/devUtils'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { SetupServer } from './glossary'\n\nconst DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServer\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{\n new (): Interceptor<HttpRequestEventMap>\n }>,\n ...handlers: Array<RequestHandler>\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\n this.resolvedOptions = {} as RequiredDeep<SharedOptions>\n\n this.init()\n }\n\n /**\n * Subscribe to all requests that are using the interceptor object\n */\n private init(): void {\n this.interceptor.on('request', async ({ request, requestId }) => {\n const response = await handleRequest(\n request,\n requestId,\n this.currentHandlers,\n this.resolvedOptions,\n this.emitter,\n )\n\n if (response) {\n request.respondWith(response)\n }\n\n return\n })\n\n this.interceptor.on(\n 'response',\n ({ response, isMockedResponse, request, requestId }) => {\n this.emitter.emit(\n isMockedResponse ? 'response:mocked' : 'response:bypass',\n {\n response,\n request,\n requestId,\n },\n )\n },\n )\n }\n\n public listen(options: Partial<SharedOptions> = {}): void {\n this.resolvedOptions = mergeRight(\n DEFAULT_LISTEN_OPTIONS,\n options,\n ) as RequiredDeep<SharedOptions>\n\n // Apply the interceptor when starting the server.\n this.interceptor.apply()\n\n this.subscriptions.push(() => {\n this.interceptor.dispose()\n })\n\n // Assert that the interceptor has been applied successfully.\n // Also guards us from forgetting to call \"interceptor.apply()\"\n // as a part of the \"listen\" method.\n invariant(\n [InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(\n this.interceptor.readyState,\n ),\n devUtils.formatMessage(\n 'Failed to start \"setupServer\": the interceptor failed to apply. This is likely an issue with the library and you should report it at \"%s\".',\n ),\n 'https://github.com/mswjs/msw/issues/new/choose',\n )\n }\n\n public close(): void {\n this.dispose()\n }\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAAS,iCAAiC;;;ACD1C;AAAA,EACE;AAAA,EAGA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AAIzB,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAG3B,IAAM,yBAAsD;AAAA,EAC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ACf;AACF;;;ADrGO,SAAS,eACX,UACa;AAGhB,SAAO,IAAI;AAAA,IACT,CAAC,kBAAkB,yBAAyB;AAAA,IAC5C,GAAG;AAAA,EACL;AACF;","names":["Interceptor"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.7",
|
|
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",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"@bundled-es-modules/cookie": "^2.0.0",
|
|
96
96
|
"@bundled-es-modules/statuses": "^1.0.1",
|
|
97
97
|
"@mswjs/cookies": "^1.1.0",
|
|
98
|
-
"@mswjs/interceptors": "^0.25.
|
|
98
|
+
"@mswjs/interceptors": "^0.25.16",
|
|
99
99
|
"@open-draft/until": "^2.1.0",
|
|
100
100
|
"@types/cookie": "^0.6.0",
|
|
101
101
|
"@types/statuses": "^2.0.4",
|
package/src/native/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FetchInterceptor } from '@mswjs/interceptors/fetch'
|
|
1
2
|
import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'
|
|
2
3
|
import { RequestHandler } from '~/core/handlers/RequestHandler'
|
|
3
4
|
import { SetupServerApi } from '../node/SetupServerApi'
|
|
@@ -13,5 +14,8 @@ export function setupServer(
|
|
|
13
14
|
): SetupServerApi {
|
|
14
15
|
// Provision request interception via patching the `XMLHttpRequest` class only
|
|
15
16
|
// in React Native. There is no `http`/`https` modules in that environment.
|
|
16
|
-
return new SetupServerApi(
|
|
17
|
+
return new SetupServerApi(
|
|
18
|
+
[FetchInterceptor, XMLHttpRequestInterceptor],
|
|
19
|
+
...handlers,
|
|
20
|
+
)
|
|
17
21
|
}
|