msw 2.2.3 → 2.3.0-ws.rc-1
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/cli/init.js +0 -0
- package/config/scripts/postinstall.js +0 -0
- package/lib/browser/index.d.mts +7 -6
- package/lib/browser/index.d.ts +7 -6
- package/lib/browser/index.js +32 -15
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +32 -15
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-jOzqbxSK.d.ts → GraphQLHandler-Cbu12sb0.d.ts} +1 -1
- package/lib/core/{GraphQLHandler-AenIUdwE.d.mts → GraphQLHandler-QGQY_9Rc.d.mts} +1 -1
- package/lib/core/{HttpResponse-wcp03c7-.d.mts → HttpResponse-BWB1yDNM.d.mts} +2 -2
- package/lib/core/{HttpResponse-_514VQ9z.d.ts → HttpResponse-DeJBWGN5.d.ts} +2 -2
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +15 -12
- package/lib/core/SetupApi.d.ts +15 -12
- package/lib/core/SetupApi.js +3 -1
- package/lib/core/SetupApi.js.map +1 -1
- package/lib/core/SetupApi.mjs +3 -1
- package/lib/core/SetupApi.mjs.map +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +2 -2
- package/lib/core/graphql.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +38 -0
- package/lib/core/handlers/WebSocketHandler.d.ts +38 -0
- package/lib/core/handlers/WebSocketHandler.js +65 -0
- package/lib/core/handlers/WebSocketHandler.js.map +1 -0
- package/lib/core/handlers/WebSocketHandler.mjs +47 -0
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -0
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +5 -2
- package/lib/core/index.d.ts +5 -2
- package/lib/core/index.js +3 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +3 -1
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/executeHandlers.js +4 -0
- package/lib/core/utils/executeHandlers.js.map +1 -1
- package/lib/core/utils/executeHandlers.mjs +6 -0
- package/lib/core/utils/executeHandlers.mjs.map +1 -1
- package/lib/core/utils/handleRequest.d.mts +2 -2
- package/lib/core/utils/handleRequest.d.ts +2 -2
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/handleWebSocketEvent.d.mts +10 -0
- package/lib/core/utils/handleWebSocketEvent.d.ts +10 -0
- package/lib/core/utils/handleWebSocketEvent.js +56 -0
- package/lib/core/utils/handleWebSocketEvent.js.map +1 -0
- package/lib/core/utils/handleWebSocketEvent.mjs +40 -0
- package/lib/core/utils/handleWebSocketEvent.mjs.map +1 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/utils/matching/matchRequestUrl.d.mts +2 -1
- package/lib/core/utils/matching/matchRequestUrl.d.ts +2 -1
- package/lib/core/utils/matching/matchRequestUrl.js +4 -0
- package/lib/core/utils/matching/matchRequestUrl.js.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs +4 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -1
- package/lib/core/ws/WebSocketClientManager.d.mts +64 -0
- package/lib/core/ws/WebSocketClientManager.d.ts +64 -0
- package/lib/core/ws/WebSocketClientManager.js +123 -0
- package/lib/core/ws/WebSocketClientManager.js.map +1 -0
- package/lib/core/ws/WebSocketClientManager.mjs +103 -0
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -0
- package/lib/core/ws/webSocketInterceptor.d.mts +5 -0
- package/lib/core/ws/webSocketInterceptor.d.ts +5 -0
- package/lib/core/ws/webSocketInterceptor.js +26 -0
- package/lib/core/ws/webSocketInterceptor.js.map +1 -0
- package/lib/core/ws/webSocketInterceptor.mjs +6 -0
- package/lib/core/ws/webSocketInterceptor.mjs.map +1 -0
- package/lib/core/ws/ws.d.mts +44 -0
- package/lib/core/ws/ws.d.ts +44 -0
- package/lib/core/ws/ws.js +82 -0
- package/lib/core/ws/ws.js.map +1 -0
- package/lib/core/ws/ws.mjs +65 -0
- package/lib/core/ws/ws.mjs.map +1 -0
- package/lib/iife/index.js +703 -17
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.mts +6 -5
- package/lib/native/index.d.ts +6 -5
- package/lib/native/index.js +7 -0
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +7 -0
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.d.mts +8 -7
- package/lib/node/index.d.ts +8 -7
- package/lib/node/index.js +7 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +7 -0
- package/lib/node/index.mjs.map +1 -1
- package/package.json +27 -22
- package/src/browser/setupWorker/glossary.ts +10 -10
- package/src/browser/setupWorker/setupWorker.ts +17 -3
- package/src/core/SetupApi.ts +28 -20
- package/src/core/handlers/WebSocketHandler.ts +89 -0
- package/src/core/index.ts +3 -0
- package/src/core/utils/executeHandlers.ts +6 -2
- package/src/core/utils/handleRequest.ts +1 -2
- package/src/core/utils/handleWebSocketEvent.ts +49 -0
- package/src/core/utils/matching/matchRequestUrl.test.ts +44 -0
- package/src/core/utils/matching/matchRequestUrl.ts +4 -0
- package/src/core/ws/WebSocketClientManager.test.ts +159 -0
- package/src/core/ws/WebSocketClientManager.ts +170 -0
- package/src/core/ws/webSocketInterceptor.ts +3 -0
- package/src/core/ws/ws.test.ts +23 -0
- package/src/core/ws/ws.ts +108 -0
- package/src/node/SetupServerApi.ts +8 -7
- package/src/node/SetupServerCommonApi.ts +10 -1
- package/src/node/glossary.ts +5 -7
- package/src/node/setupServer.ts +2 -1
package/lib/mockServiceWorker.js
CHANGED
package/lib/native/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { RequestHandler
|
|
1
|
+
import { RequestHandler } from '~/core/handlers/RequestHandler';
|
|
2
2
|
import { BatchInterceptor, Interceptor, HttpRequestEventMap } from '@mswjs/interceptors';
|
|
3
3
|
import { SharedOptions, LifeCycleEventEmitter, LifeCycleEventsMap } from '~/core/sharedOptions';
|
|
4
4
|
import { SetupApi } from '~/core/SetupApi';
|
|
5
|
+
import { WebSocketHandler } from '~/core/handlers/WebSocketHandler';
|
|
5
6
|
import { PartialDeep } from 'type-fest';
|
|
6
7
|
|
|
7
8
|
interface SetupServerCommon {
|
|
@@ -22,7 +23,7 @@ interface SetupServerCommon {
|
|
|
22
23
|
*
|
|
23
24
|
* @see {@link https://mswjs.io/docs/api/setup-server/use `server.use()` API reference}
|
|
24
25
|
*/
|
|
25
|
-
use(...handlers: Array<RequestHandler>): void;
|
|
26
|
+
use(...handlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
26
27
|
/**
|
|
27
28
|
* Marks all request handlers that respond using `res.once()` as unused.
|
|
28
29
|
*
|
|
@@ -34,13 +35,13 @@ interface SetupServerCommon {
|
|
|
34
35
|
*
|
|
35
36
|
* @see {@link https://mswjs.io/docs/api/setup-server/reset-handlers `server.reset-handlers()` API reference}
|
|
36
37
|
*/
|
|
37
|
-
resetHandlers(...nextHandlers: Array<RequestHandler>): void;
|
|
38
|
+
resetHandlers(...nextHandlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
38
39
|
/**
|
|
39
40
|
* Returns a readonly list of currently active request handlers.
|
|
40
41
|
*
|
|
41
42
|
* @see {@link https://mswjs.io/docs/api/setup-server/list-handlers `server.listHandlers()` API reference}
|
|
42
43
|
*/
|
|
43
|
-
listHandlers(): ReadonlyArray<RequestHandler
|
|
44
|
+
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>;
|
|
44
45
|
/**
|
|
45
46
|
* Life-cycle events.
|
|
46
47
|
* Life-cycle events allow you to subscribe to the internal library events occurring during the request/response handling.
|
|
@@ -60,7 +61,7 @@ declare class SetupServerCommonApi extends SetupApi<LifeCycleEventsMap> implemen
|
|
|
60
61
|
private resolvedOptions;
|
|
61
62
|
constructor(interceptors: Array<{
|
|
62
63
|
new (): Interceptor<HttpRequestEventMap>;
|
|
63
|
-
}>, handlers: Array<RequestHandler>);
|
|
64
|
+
}>, handlers: Array<RequestHandler | WebSocketHandler>);
|
|
64
65
|
/**
|
|
65
66
|
* Subscribe to all requests that are using the interceptor object
|
|
66
67
|
*/
|
package/lib/native/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { RequestHandler
|
|
1
|
+
import { RequestHandler } from "../core/handlers/RequestHandler";
|
|
2
2
|
import { BatchInterceptor, Interceptor, HttpRequestEventMap } from '@mswjs/interceptors';
|
|
3
3
|
import { SharedOptions, LifeCycleEventEmitter, LifeCycleEventsMap } from "../core/sharedOptions";
|
|
4
4
|
import { SetupApi } from "../core/SetupApi";
|
|
5
|
+
import { WebSocketHandler } from "../core/handlers/WebSocketHandler";
|
|
5
6
|
import { PartialDeep } from 'type-fest';
|
|
6
7
|
|
|
7
8
|
interface SetupServerCommon {
|
|
@@ -22,7 +23,7 @@ interface SetupServerCommon {
|
|
|
22
23
|
*
|
|
23
24
|
* @see {@link https://mswjs.io/docs/api/setup-server/use `server.use()` API reference}
|
|
24
25
|
*/
|
|
25
|
-
use(...handlers: Array<RequestHandler>): void;
|
|
26
|
+
use(...handlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
26
27
|
/**
|
|
27
28
|
* Marks all request handlers that respond using `res.once()` as unused.
|
|
28
29
|
*
|
|
@@ -34,13 +35,13 @@ interface SetupServerCommon {
|
|
|
34
35
|
*
|
|
35
36
|
* @see {@link https://mswjs.io/docs/api/setup-server/reset-handlers `server.reset-handlers()` API reference}
|
|
36
37
|
*/
|
|
37
|
-
resetHandlers(...nextHandlers: Array<RequestHandler>): void;
|
|
38
|
+
resetHandlers(...nextHandlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
38
39
|
/**
|
|
39
40
|
* Returns a readonly list of currently active request handlers.
|
|
40
41
|
*
|
|
41
42
|
* @see {@link https://mswjs.io/docs/api/setup-server/list-handlers `server.listHandlers()` API reference}
|
|
42
43
|
*/
|
|
43
|
-
listHandlers(): ReadonlyArray<RequestHandler
|
|
44
|
+
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>;
|
|
44
45
|
/**
|
|
45
46
|
* Life-cycle events.
|
|
46
47
|
* Life-cycle events allow you to subscribe to the internal library events occurring during the request/response handling.
|
|
@@ -60,7 +61,7 @@ declare class SetupServerCommonApi extends SetupApi<LifeCycleEventsMap> implemen
|
|
|
60
61
|
private resolvedOptions;
|
|
61
62
|
constructor(interceptors: Array<{
|
|
62
63
|
new (): Interceptor<HttpRequestEventMap>;
|
|
63
|
-
}>, handlers: Array<RequestHandler>);
|
|
64
|
+
}>, handlers: Array<RequestHandler | WebSocketHandler>);
|
|
64
65
|
/**
|
|
65
66
|
* Subscribe to all requests that are using the interceptor object
|
|
66
67
|
*/
|
package/lib/native/index.js
CHANGED
|
@@ -33,6 +33,8 @@ var import_SetupApi = require("../core/SetupApi.js");
|
|
|
33
33
|
var import_handleRequest = require("../core/utils/handleRequest.js");
|
|
34
34
|
var import_mergeRight = require("../core/utils/internal/mergeRight.js");
|
|
35
35
|
var import_devUtils = require("../core/utils/internal/devUtils.js");
|
|
36
|
+
var import_handleWebSocketEvent = require("../core/utils/handleWebSocketEvent.js");
|
|
37
|
+
var import_webSocketInterceptor = require("../core/ws/webSocketInterceptor.js");
|
|
36
38
|
var DEFAULT_LISTEN_OPTIONS = {
|
|
37
39
|
onUnhandledRequest: "warn"
|
|
38
40
|
};
|
|
@@ -78,6 +80,9 @@ var SetupServerCommonApi = class extends import_SetupApi.SetupApi {
|
|
|
78
80
|
);
|
|
79
81
|
}
|
|
80
82
|
);
|
|
83
|
+
(0, import_handleWebSocketEvent.handleWebSocketEvent)(() => {
|
|
84
|
+
return this.handlersController.currentHandlers();
|
|
85
|
+
});
|
|
81
86
|
}
|
|
82
87
|
listen(options = {}) {
|
|
83
88
|
this.resolvedOptions = (0, import_mergeRight.mergeRight)(
|
|
@@ -85,8 +90,10 @@ var SetupServerCommonApi = class extends import_SetupApi.SetupApi {
|
|
|
85
90
|
options
|
|
86
91
|
);
|
|
87
92
|
this.interceptor.apply();
|
|
93
|
+
import_webSocketInterceptor.webSocketInterceptor.apply();
|
|
88
94
|
this.subscriptions.push(() => {
|
|
89
95
|
this.interceptor.dispose();
|
|
96
|
+
import_webSocketInterceptor.webSocketInterceptor.dispose();
|
|
90
97
|
});
|
|
91
98
|
(0, import_outvariant.invariant)(
|
|
92
99
|
[import_interceptors.InterceptorReadyState.APPLYING, import_interceptors.InterceptorReadyState.APPLIED].includes(
|
package/lib/native/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerCommonApi.ts"],"sourcesContent":["import { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerCommonApi } from '../node/SetupServerCommonApi'\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): SetupServerCommonApi {\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 SetupServerCommonApi(\n [FetchInterceptor, XMLHttpRequestInterceptor],\n handlers,\n )\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\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\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.handlersController.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;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiC;AACjC,4BAA0C;;;ACI1C,wBAA0B;AAC1B,0BAKO;AAEP,sBAAyB;AACzB,2BAA8B;
|
|
1
|
+
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerCommonApi.ts"],"sourcesContent":["import { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerCommonApi } from '../node/SetupServerCommonApi'\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): SetupServerCommonApi {\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 SetupServerCommonApi(\n [FetchInterceptor, XMLHttpRequestInterceptor],\n handlers,\n )\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\nimport { handleWebSocketEvent } from '~/core/utils/handleWebSocketEvent'\nimport { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\n handlers: Array<RequestHandler | WebSocketHandler>,\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\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.handlersController.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 handleWebSocketEvent(() => {\n return this.handlersController.currentHandlers()\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 webSocketInterceptor.apply()\n\n this.subscriptions.push(() => {\n this.interceptor.dispose()\n webSocketInterceptor.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;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiC;AACjC,4BAA0C;;;ACI1C,wBAA0B;AAC1B,0BAKO;AAEP,sBAAyB;AACzB,2BAA8B;AAG9B,wBAA2B;AAC3B,s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MACE,CAAC,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;;;ADjHO,SAAS,eACX,UACmB;AAGtB,SAAO,IAAI;AAAA,IACT,CAAC,+BAAkB,+CAAyB;AAAA,IAC5C;AAAA,EACF;AACF;","names":[]}
|
package/lib/native/index.mjs
CHANGED
|
@@ -12,6 +12,8 @@ import { SetupApi } from '../core/SetupApi.mjs';
|
|
|
12
12
|
import { handleRequest } from '../core/utils/handleRequest.mjs';
|
|
13
13
|
import { mergeRight } from '../core/utils/internal/mergeRight.mjs';
|
|
14
14
|
import { devUtils } from '../core/utils/internal/devUtils.mjs';
|
|
15
|
+
import { handleWebSocketEvent } from '../core/utils/handleWebSocketEvent.mjs';
|
|
16
|
+
import { webSocketInterceptor } from '../core/ws/webSocketInterceptor.mjs';
|
|
15
17
|
var DEFAULT_LISTEN_OPTIONS = {
|
|
16
18
|
onUnhandledRequest: "warn"
|
|
17
19
|
};
|
|
@@ -57,6 +59,9 @@ var SetupServerCommonApi = class extends SetupApi {
|
|
|
57
59
|
);
|
|
58
60
|
}
|
|
59
61
|
);
|
|
62
|
+
handleWebSocketEvent(() => {
|
|
63
|
+
return this.handlersController.currentHandlers();
|
|
64
|
+
});
|
|
60
65
|
}
|
|
61
66
|
listen(options = {}) {
|
|
62
67
|
this.resolvedOptions = mergeRight(
|
|
@@ -64,8 +69,10 @@ var SetupServerCommonApi = class extends SetupApi {
|
|
|
64
69
|
options
|
|
65
70
|
);
|
|
66
71
|
this.interceptor.apply();
|
|
72
|
+
webSocketInterceptor.apply();
|
|
67
73
|
this.subscriptions.push(() => {
|
|
68
74
|
this.interceptor.dispose();
|
|
75
|
+
webSocketInterceptor.dispose();
|
|
69
76
|
});
|
|
70
77
|
invariant(
|
|
71
78
|
[InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(
|
package/lib/native/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerCommonApi.ts"],"sourcesContent":["import { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerCommonApi } from '../node/SetupServerCommonApi'\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): SetupServerCommonApi {\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 SetupServerCommonApi(\n [FetchInterceptor, XMLHttpRequestInterceptor],\n handlers,\n )\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\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\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.handlersController.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;;;ACI1C,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;
|
|
1
|
+
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerCommonApi.ts"],"sourcesContent":["import { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerCommonApi } from '../node/SetupServerCommonApi'\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): SetupServerCommonApi {\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 SetupServerCommonApi(\n [FetchInterceptor, XMLHttpRequestInterceptor],\n handlers,\n )\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\nimport { handleWebSocketEvent } from '~/core/utils/handleWebSocketEvent'\nimport { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\n handlers: Array<RequestHandler | WebSocketHandler>,\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\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.handlersController.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 handleWebSocketEvent(() => {\n return this.handlersController.currentHandlers()\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 webSocketInterceptor.apply()\n\n this.subscriptions.push(() => {\n this.interceptor.dispose()\n webSocketInterceptor.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.disp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GAAS;AACxD,SAAK,kBAAkB;AAAA,MACrB;AAAA,MACA;AAAA,IACF;AAGA,SAAK,YAAY,MAAM;AACvB,yBAAqB,MAAM;AAE3B,SAAK,cAAc,KAAK,MAAM;AAC5B,WAAK,YAAY,QAAQ;AACzB,2BAAqB,QAAQ;AAAA,IAC/B,CAAC;AAKD;AAAA,MACE,CAAC,sBAAsB,UAAU,sBAAsB,OAAO,EAAE;AAAA,QAC9D,KAAK,YAAY;AAAA,MACnB;AAAA,MACA,SAAS;AAAA,QACP;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEO,QAAc;AACnB,SAAK,QAAQ;AAAA,EACf;AACF;;;ADjHO,SAAS,eACX,UACmB;AAGtB,SAAO,IAAI;AAAA,IACT,CAAC,kBAAkB,yBAAyB;AAAA,IAC5C;AAAA,EACF;AACF;","names":[]}
|
package/lib/node/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PartialDeep } from 'type-fest';
|
|
2
|
-
import { RequestHandler
|
|
2
|
+
import { RequestHandler } from '~/core/handlers/RequestHandler';
|
|
3
|
+
import { WebSocketHandler } from '~/core/handlers/WebSocketHandler';
|
|
3
4
|
import { SharedOptions, LifeCycleEventEmitter, LifeCycleEventsMap } from '~/core/sharedOptions';
|
|
4
5
|
import { BatchInterceptor, Interceptor, HttpRequestEventMap } from '@mswjs/interceptors';
|
|
5
6
|
import { SetupApi } from '~/core/SetupApi';
|
|
@@ -22,7 +23,7 @@ interface SetupServerCommon {
|
|
|
22
23
|
*
|
|
23
24
|
* @see {@link https://mswjs.io/docs/api/setup-server/use `server.use()` API reference}
|
|
24
25
|
*/
|
|
25
|
-
use(...handlers: Array<RequestHandler>): void;
|
|
26
|
+
use(...handlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
26
27
|
/**
|
|
27
28
|
* Marks all request handlers that respond using `res.once()` as unused.
|
|
28
29
|
*
|
|
@@ -34,13 +35,13 @@ interface SetupServerCommon {
|
|
|
34
35
|
*
|
|
35
36
|
* @see {@link https://mswjs.io/docs/api/setup-server/reset-handlers `server.reset-handlers()` API reference}
|
|
36
37
|
*/
|
|
37
|
-
resetHandlers(...nextHandlers: Array<RequestHandler>): void;
|
|
38
|
+
resetHandlers(...nextHandlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
38
39
|
/**
|
|
39
40
|
* Returns a readonly list of currently active request handlers.
|
|
40
41
|
*
|
|
41
42
|
* @see {@link https://mswjs.io/docs/api/setup-server/list-handlers `server.listHandlers()` API reference}
|
|
42
43
|
*/
|
|
43
|
-
listHandlers(): ReadonlyArray<RequestHandler
|
|
44
|
+
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>;
|
|
44
45
|
/**
|
|
45
46
|
* Life-cycle events.
|
|
46
47
|
* Life-cycle events allow you to subscribe to the internal library events occurring during the request/response handling.
|
|
@@ -71,7 +72,7 @@ declare class SetupServerCommonApi extends SetupApi<LifeCycleEventsMap> implemen
|
|
|
71
72
|
private resolvedOptions;
|
|
72
73
|
constructor(interceptors: Array<{
|
|
73
74
|
new (): Interceptor<HttpRequestEventMap>;
|
|
74
|
-
}>, handlers: Array<RequestHandler>);
|
|
75
|
+
}>, handlers: Array<RequestHandler | WebSocketHandler>);
|
|
75
76
|
/**
|
|
76
77
|
* Subscribe to all requests that are using the interceptor object
|
|
77
78
|
*/
|
|
@@ -81,7 +82,7 @@ declare class SetupServerCommonApi extends SetupApi<LifeCycleEventsMap> implemen
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
declare class SetupServerApi extends SetupServerCommonApi implements SetupServer {
|
|
84
|
-
constructor(handlers: Array<RequestHandler>);
|
|
85
|
+
constructor(handlers: Array<RequestHandler | WebSocketHandler>);
|
|
85
86
|
boundary<Fn extends (...args: Array<any>) => unknown>(callback: Fn): (...args: Parameters<Fn>) => ReturnType<Fn>;
|
|
86
87
|
close(): void;
|
|
87
88
|
}
|
|
@@ -92,6 +93,6 @@ declare class SetupServerApi extends SetupServerCommonApi implements SetupServer
|
|
|
92
93
|
*
|
|
93
94
|
* @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}
|
|
94
95
|
*/
|
|
95
|
-
declare const setupServer: (...handlers: Array<RequestHandler>) => SetupServerApi;
|
|
96
|
+
declare const setupServer: (...handlers: Array<RequestHandler | WebSocketHandler>) => SetupServerApi;
|
|
96
97
|
|
|
97
98
|
export { type SetupServer, SetupServerApi, setupServer };
|
package/lib/node/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PartialDeep } from 'type-fest';
|
|
2
|
-
import { RequestHandler
|
|
2
|
+
import { RequestHandler } from "../core/handlers/RequestHandler";
|
|
3
|
+
import { WebSocketHandler } from "../core/handlers/WebSocketHandler";
|
|
3
4
|
import { SharedOptions, LifeCycleEventEmitter, LifeCycleEventsMap } from "../core/sharedOptions";
|
|
4
5
|
import { BatchInterceptor, Interceptor, HttpRequestEventMap } from '@mswjs/interceptors';
|
|
5
6
|
import { SetupApi } from "../core/SetupApi";
|
|
@@ -22,7 +23,7 @@ interface SetupServerCommon {
|
|
|
22
23
|
*
|
|
23
24
|
* @see {@link https://mswjs.io/docs/api/setup-server/use `server.use()` API reference}
|
|
24
25
|
*/
|
|
25
|
-
use(...handlers: Array<RequestHandler>): void;
|
|
26
|
+
use(...handlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
26
27
|
/**
|
|
27
28
|
* Marks all request handlers that respond using `res.once()` as unused.
|
|
28
29
|
*
|
|
@@ -34,13 +35,13 @@ interface SetupServerCommon {
|
|
|
34
35
|
*
|
|
35
36
|
* @see {@link https://mswjs.io/docs/api/setup-server/reset-handlers `server.reset-handlers()` API reference}
|
|
36
37
|
*/
|
|
37
|
-
resetHandlers(...nextHandlers: Array<RequestHandler>): void;
|
|
38
|
+
resetHandlers(...nextHandlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
38
39
|
/**
|
|
39
40
|
* Returns a readonly list of currently active request handlers.
|
|
40
41
|
*
|
|
41
42
|
* @see {@link https://mswjs.io/docs/api/setup-server/list-handlers `server.listHandlers()` API reference}
|
|
42
43
|
*/
|
|
43
|
-
listHandlers(): ReadonlyArray<RequestHandler
|
|
44
|
+
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>;
|
|
44
45
|
/**
|
|
45
46
|
* Life-cycle events.
|
|
46
47
|
* Life-cycle events allow you to subscribe to the internal library events occurring during the request/response handling.
|
|
@@ -71,7 +72,7 @@ declare class SetupServerCommonApi extends SetupApi<LifeCycleEventsMap> implemen
|
|
|
71
72
|
private resolvedOptions;
|
|
72
73
|
constructor(interceptors: Array<{
|
|
73
74
|
new (): Interceptor<HttpRequestEventMap>;
|
|
74
|
-
}>, handlers: Array<RequestHandler>);
|
|
75
|
+
}>, handlers: Array<RequestHandler | WebSocketHandler>);
|
|
75
76
|
/**
|
|
76
77
|
* Subscribe to all requests that are using the interceptor object
|
|
77
78
|
*/
|
|
@@ -81,7 +82,7 @@ declare class SetupServerCommonApi extends SetupApi<LifeCycleEventsMap> implemen
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
declare class SetupServerApi extends SetupServerCommonApi implements SetupServer {
|
|
84
|
-
constructor(handlers: Array<RequestHandler>);
|
|
85
|
+
constructor(handlers: Array<RequestHandler | WebSocketHandler>);
|
|
85
86
|
boundary<Fn extends (...args: Array<any>) => unknown>(callback: Fn): (...args: Parameters<Fn>) => ReturnType<Fn>;
|
|
86
87
|
close(): void;
|
|
87
88
|
}
|
|
@@ -92,6 +93,6 @@ declare class SetupServerApi extends SetupServerCommonApi implements SetupServer
|
|
|
92
93
|
*
|
|
93
94
|
* @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}
|
|
94
95
|
*/
|
|
95
|
-
declare const setupServer: (...handlers: Array<RequestHandler>) => SetupServerApi;
|
|
96
|
+
declare const setupServer: (...handlers: Array<RequestHandler | WebSocketHandler>) => SetupServerApi;
|
|
96
97
|
|
|
97
98
|
export { type SetupServer, SetupServerApi, setupServer };
|
package/lib/node/index.js
CHANGED
|
@@ -38,6 +38,8 @@ var import_SetupApi = require("../core/SetupApi.js");
|
|
|
38
38
|
var import_handleRequest = require("../core/utils/handleRequest.js");
|
|
39
39
|
var import_mergeRight = require("../core/utils/internal/mergeRight.js");
|
|
40
40
|
var import_devUtils = require("../core/utils/internal/devUtils.js");
|
|
41
|
+
var import_handleWebSocketEvent = require("../core/utils/handleWebSocketEvent.js");
|
|
42
|
+
var import_webSocketInterceptor = require("../core/ws/webSocketInterceptor.js");
|
|
41
43
|
var DEFAULT_LISTEN_OPTIONS = {
|
|
42
44
|
onUnhandledRequest: "warn"
|
|
43
45
|
};
|
|
@@ -83,6 +85,9 @@ var SetupServerCommonApi = class extends import_SetupApi.SetupApi {
|
|
|
83
85
|
);
|
|
84
86
|
}
|
|
85
87
|
);
|
|
88
|
+
(0, import_handleWebSocketEvent.handleWebSocketEvent)(() => {
|
|
89
|
+
return this.handlersController.currentHandlers();
|
|
90
|
+
});
|
|
86
91
|
}
|
|
87
92
|
listen(options = {}) {
|
|
88
93
|
this.resolvedOptions = (0, import_mergeRight.mergeRight)(
|
|
@@ -90,8 +95,10 @@ var SetupServerCommonApi = class extends import_SetupApi.SetupApi {
|
|
|
90
95
|
options
|
|
91
96
|
);
|
|
92
97
|
this.interceptor.apply();
|
|
98
|
+
import_webSocketInterceptor.webSocketInterceptor.apply();
|
|
93
99
|
this.subscriptions.push(() => {
|
|
94
100
|
this.interceptor.dispose();
|
|
101
|
+
import_webSocketInterceptor.webSocketInterceptor.dispose();
|
|
95
102
|
});
|
|
96
103
|
(0, import_outvariant.invariant)(
|
|
97
104
|
[import_interceptors.InterceptorReadyState.APPLYING, import_interceptors.InterceptorReadyState.APPLIED].includes(
|
package/lib/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/node/index.ts","../../src/node/SetupServerApi.ts","../../src/node/SetupServerCommonApi.ts","../../src/node/setupServer.ts"],"sourcesContent":["export type { SetupServer } from './glossary'\nexport { SetupServerApi } from './SetupServerApi'\nexport { setupServer } from './setupServer'\n","import { AsyncLocalStorage } from 'node:async_hooks'\nimport { ClientRequestInterceptor } from '@mswjs/interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { HandlersController } from '~/core/SetupApi'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { SetupServer } from './glossary'\nimport { SetupServerCommonApi } from './SetupServerCommonApi'\n\nconst store = new AsyncLocalStorage<RequestHandlersContext>()\n\ntype RequestHandlersContext = {\n initialHandlers: Array<RequestHandler>\n handlers: Array<RequestHandler>\n}\n\n/**\n * A handlers controller that utilizes `AsyncLocalStorage` in Node.js\n * to prevent the request handlers list from being a shared state\n * across mutliple tests.\n */\nclass AsyncHandlersController implements HandlersController {\n private rootContext: RequestHandlersContext\n\n constructor(initialHandlers: Array<RequestHandler>) {\n this.rootContext = { initialHandlers, handlers: [] }\n }\n\n get context(): RequestHandlersContext {\n return store.getStore() || this.rootContext\n }\n\n public prepend(runtimeHandlers: Array<RequestHandler>) {\n this.context.handlers.unshift(...runtimeHandlers)\n }\n\n public reset(nextHandlers: Array<RequestHandler>) {\n const context = this.context\n context.handlers = []\n context.initialHandlers =\n nextHandlers.length > 0 ? nextHandlers : context.initialHandlers\n }\n\n public currentHandlers(): Array<RequestHandler> {\n const { initialHandlers, handlers } = this.context\n return handlers.concat(initialHandlers)\n }\n}\n\nexport class SetupServerApi\n extends SetupServerCommonApi\n implements SetupServer\n{\n constructor(handlers: Array<RequestHandler>) {\n super(\n [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor],\n handlers,\n )\n\n this.handlersController = new AsyncHandlersController(handlers)\n }\n\n public boundary<Fn extends (...args: Array<any>) => unknown>(\n callback: Fn,\n ): (...args: Parameters<Fn>) => ReturnType<Fn> {\n return (...args: Parameters<Fn>): ReturnType<Fn> => {\n return store.run<any, any>(\n {\n initialHandlers: this.handlersController.currentHandlers(),\n handlers: [],\n },\n callback,\n ...args,\n )\n }\n }\n\n public close(): void {\n super.close()\n store.disable()\n }\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\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\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.handlersController.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","import type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerApi } from './SetupServerApi'\n\n/**\n * Sets up a requests interception in Node.js 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 const setupServer = (\n ...handlers: Array<RequestHandler>\n): SetupServerApi => {\n return new SetupServerApi(handlers)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,8BAAkC;AAClC,2BAAyC;AACzC,4BAA0C;AAC1C,mBAAiC;;;ACEjC,wBAA0B;AAC1B,0BAKO;AAEP,sBAAyB;AACzB,2BAA8B;
|
|
1
|
+
{"version":3,"sources":["../../src/node/index.ts","../../src/node/SetupServerApi.ts","../../src/node/SetupServerCommonApi.ts","../../src/node/setupServer.ts"],"sourcesContent":["export type { SetupServer } from './glossary'\nexport { SetupServerApi } from './SetupServerApi'\nexport { setupServer } from './setupServer'\n","import { AsyncLocalStorage } from 'node:async_hooks'\nimport { ClientRequestInterceptor } from '@mswjs/interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { HandlersController } from '~/core/SetupApi'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport type { SetupServer } from './glossary'\nimport { SetupServerCommonApi } from './SetupServerCommonApi'\n\nconst store = new AsyncLocalStorage<RequestHandlersContext>()\n\ntype RequestHandlersContext = {\n initialHandlers: Array<RequestHandler | WebSocketHandler>\n handlers: Array<RequestHandler | WebSocketHandler>\n}\n\n/**\n * A handlers controller that utilizes `AsyncLocalStorage` in Node.js\n * to prevent the request handlers list from being a shared state\n * across mutliple tests.\n */\nclass AsyncHandlersController implements HandlersController {\n private rootContext: RequestHandlersContext\n\n constructor(initialHandlers: Array<RequestHandler | WebSocketHandler>) {\n this.rootContext = { initialHandlers, handlers: [] }\n }\n\n get context(): RequestHandlersContext {\n return store.getStore() || this.rootContext\n }\n\n public prepend(runtimeHandlers: Array<RequestHandler | WebSocketHandler>) {\n this.context.handlers.unshift(...runtimeHandlers)\n }\n\n public reset(nextHandlers: Array<RequestHandler | WebSocketHandler>) {\n const context = this.context\n context.handlers = []\n context.initialHandlers =\n nextHandlers.length > 0 ? nextHandlers : context.initialHandlers\n }\n\n public currentHandlers(): Array<RequestHandler | WebSocketHandler> {\n const { initialHandlers, handlers } = this.context\n return handlers.concat(initialHandlers)\n }\n}\n\nexport class SetupServerApi\n extends SetupServerCommonApi\n implements SetupServer\n{\n constructor(handlers: Array<RequestHandler | WebSocketHandler>) {\n super(\n [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor],\n handlers,\n )\n\n this.handlersController = new AsyncHandlersController(handlers)\n }\n\n public boundary<Fn extends (...args: Array<any>) => unknown>(\n callback: Fn,\n ): (...args: Parameters<Fn>) => ReturnType<Fn> {\n return (...args: Parameters<Fn>): ReturnType<Fn> => {\n return store.run<any, any>(\n {\n initialHandlers: this.handlersController.currentHandlers(),\n handlers: [],\n },\n callback,\n ...args,\n )\n }\n }\n\n public close(): void {\n super.close()\n store.disable()\n }\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\nimport { handleWebSocketEvent } from '~/core/utils/handleWebSocketEvent'\nimport { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\n handlers: Array<RequestHandler | WebSocketHandler>,\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\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.handlersController.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 handleWebSocketEvent(() => {\n return this.handlersController.currentHandlers()\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 webSocketInterceptor.apply()\n\n this.subscriptions.push(() => {\n this.interceptor.dispose()\n webSocketInterceptor.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","import type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport { SetupServerApi } from './SetupServerApi'\n\n/**\n * Sets up a requests interception in Node.js 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 const setupServer = (\n ...handlers: Array<RequestHandler | WebSocketHandler>\n): SetupServerApi => {\n return new SetupServerApi(handlers)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AA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gBAAgB;AAAA,UACzD,UAAU,CAAC;AAAA,QACb;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAAA,EAEO,QAAc;AACnB,UAAM,MAAM;AACZ,UAAM,QAAQ;AAAA,EAChB;AACF;;;AExEO,IAAM,cAAc,IACtB,aACgB;AACnB,SAAO,IAAI,eAAe,QAAQ;AACpC;","names":[]}
|
package/lib/node/index.mjs
CHANGED
|
@@ -14,6 +14,8 @@ import { SetupApi } from '../core/SetupApi.mjs';
|
|
|
14
14
|
import { handleRequest } from '../core/utils/handleRequest.mjs';
|
|
15
15
|
import { mergeRight } from '../core/utils/internal/mergeRight.mjs';
|
|
16
16
|
import { devUtils } from '../core/utils/internal/devUtils.mjs';
|
|
17
|
+
import { handleWebSocketEvent } from '../core/utils/handleWebSocketEvent.mjs';
|
|
18
|
+
import { webSocketInterceptor } from '../core/ws/webSocketInterceptor.mjs';
|
|
17
19
|
var DEFAULT_LISTEN_OPTIONS = {
|
|
18
20
|
onUnhandledRequest: "warn"
|
|
19
21
|
};
|
|
@@ -59,6 +61,9 @@ var SetupServerCommonApi = class extends SetupApi {
|
|
|
59
61
|
);
|
|
60
62
|
}
|
|
61
63
|
);
|
|
64
|
+
handleWebSocketEvent(() => {
|
|
65
|
+
return this.handlersController.currentHandlers();
|
|
66
|
+
});
|
|
62
67
|
}
|
|
63
68
|
listen(options = {}) {
|
|
64
69
|
this.resolvedOptions = mergeRight(
|
|
@@ -66,8 +71,10 @@ var SetupServerCommonApi = class extends SetupApi {
|
|
|
66
71
|
options
|
|
67
72
|
);
|
|
68
73
|
this.interceptor.apply();
|
|
74
|
+
webSocketInterceptor.apply();
|
|
69
75
|
this.subscriptions.push(() => {
|
|
70
76
|
this.interceptor.dispose();
|
|
77
|
+
webSocketInterceptor.dispose();
|
|
71
78
|
});
|
|
72
79
|
invariant(
|
|
73
80
|
[InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(
|
package/lib/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/node/SetupServerApi.ts","../../src/node/SetupServerCommonApi.ts","../../src/node/setupServer.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\nimport { ClientRequestInterceptor } from '@mswjs/interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { HandlersController } from '~/core/SetupApi'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { SetupServer } from './glossary'\nimport { SetupServerCommonApi } from './SetupServerCommonApi'\n\nconst store = new AsyncLocalStorage<RequestHandlersContext>()\n\ntype RequestHandlersContext = {\n initialHandlers: Array<RequestHandler>\n handlers: Array<RequestHandler>\n}\n\n/**\n * A handlers controller that utilizes `AsyncLocalStorage` in Node.js\n * to prevent the request handlers list from being a shared state\n * across mutliple tests.\n */\nclass AsyncHandlersController implements HandlersController {\n private rootContext: RequestHandlersContext\n\n constructor(initialHandlers: Array<RequestHandler>) {\n this.rootContext = { initialHandlers, handlers: [] }\n }\n\n get context(): RequestHandlersContext {\n return store.getStore() || this.rootContext\n }\n\n public prepend(runtimeHandlers: Array<RequestHandler>) {\n this.context.handlers.unshift(...runtimeHandlers)\n }\n\n public reset(nextHandlers: Array<RequestHandler>) {\n const context = this.context\n context.handlers = []\n context.initialHandlers =\n nextHandlers.length > 0 ? nextHandlers : context.initialHandlers\n }\n\n public currentHandlers(): Array<RequestHandler> {\n const { initialHandlers, handlers } = this.context\n return handlers.concat(initialHandlers)\n }\n}\n\nexport class SetupServerApi\n extends SetupServerCommonApi\n implements SetupServer\n{\n constructor(handlers: Array<RequestHandler>) {\n super(\n [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor],\n handlers,\n )\n\n this.handlersController = new AsyncHandlersController(handlers)\n }\n\n public boundary<Fn extends (...args: Array<any>) => unknown>(\n callback: Fn,\n ): (...args: Parameters<Fn>) => ReturnType<Fn> {\n return (...args: Parameters<Fn>): ReturnType<Fn> => {\n return store.run<any, any>(\n {\n initialHandlers: this.handlersController.currentHandlers(),\n handlers: [],\n },\n callback,\n ...args,\n )\n }\n }\n\n public close(): void {\n super.close()\n store.disable()\n }\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\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\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.handlersController.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","import type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerApi } from './SetupServerApi'\n\n/**\n * Sets up a requests interception in Node.js 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 const setupServer = (\n ...handlers: Array<RequestHandler>\n): SetupServerApi => {\n return new SetupServerApi(handlers)\n}\n"],"mappings":";AAAA,SAAS,yBAAyB;AAClC,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAC1C,SAAS,wBAAwB;;;ACEjC,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;
|
|
1
|
+
{"version":3,"sources":["../../src/node/SetupServerApi.ts","../../src/node/SetupServerCommonApi.ts","../../src/node/setupServer.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\nimport { ClientRequestInterceptor } from '@mswjs/interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { HandlersController } from '~/core/SetupApi'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport type { SetupServer } from './glossary'\nimport { SetupServerCommonApi } from './SetupServerCommonApi'\n\nconst store = new AsyncLocalStorage<RequestHandlersContext>()\n\ntype RequestHandlersContext = {\n initialHandlers: Array<RequestHandler | WebSocketHandler>\n handlers: Array<RequestHandler | WebSocketHandler>\n}\n\n/**\n * A handlers controller that utilizes `AsyncLocalStorage` in Node.js\n * to prevent the request handlers list from being a shared state\n * across mutliple tests.\n */\nclass AsyncHandlersController implements HandlersController {\n private rootContext: RequestHandlersContext\n\n constructor(initialHandlers: Array<RequestHandler | WebSocketHandler>) {\n this.rootContext = { initialHandlers, handlers: [] }\n }\n\n get context(): RequestHandlersContext {\n return store.getStore() || this.rootContext\n }\n\n public prepend(runtimeHandlers: Array<RequestHandler | WebSocketHandler>) {\n this.context.handlers.unshift(...runtimeHandlers)\n }\n\n public reset(nextHandlers: Array<RequestHandler | WebSocketHandler>) {\n const context = this.context\n context.handlers = []\n context.initialHandlers =\n nextHandlers.length > 0 ? nextHandlers : context.initialHandlers\n }\n\n public currentHandlers(): Array<RequestHandler | WebSocketHandler> {\n const { initialHandlers, handlers } = this.context\n return handlers.concat(initialHandlers)\n }\n}\n\nexport class SetupServerApi\n extends SetupServerCommonApi\n implements SetupServer\n{\n constructor(handlers: Array<RequestHandler | WebSocketHandler>) {\n super(\n [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor],\n handlers,\n )\n\n this.handlersController = new AsyncHandlersController(handlers)\n }\n\n public boundary<Fn extends (...args: Array<any>) => unknown>(\n callback: Fn,\n ): (...args: Parameters<Fn>) => ReturnType<Fn> {\n return (...args: Parameters<Fn>): ReturnType<Fn> => {\n return store.run<any, any>(\n {\n initialHandlers: this.handlersController.currentHandlers(),\n handlers: [],\n },\n callback,\n ...args,\n )\n }\n }\n\n public close(): void {\n super.close()\n store.disable()\n }\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\nimport { handleWebSocketEvent } from '~/core/utils/handleWebSocketEvent'\nimport { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\n handlers: Array<RequestHandler | WebSocketHandler>,\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\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.handlersController.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 handleWebSocketEvent(() => {\n return this.handlersController.currentHandlers()\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 webSocketInterceptor.apply()\n\n this.subscriptions.push(() => {\n this.interceptor.dispose()\n webSocketInterceptor.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","import type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport { SetupServerApi } from './SetupServerApi'\n\n/**\n * Sets up a requests interception in Node.js 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 const setupServer = (\n ...handlers: Array<RequestHandler | WebSocketHandler>\n): SetupServerApi => {\n return new SetupServerApi(handlers)\n}\n"],"mappings":";AAAA,SAAS,yBAAyB;AAClC,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAC1C,SAAS,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mB,gBAAgB;AAAA,UACzD,UAAU,CAAC;AAAA,QACb;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAAA,EAEO,QAAc;AACnB,UAAM,MAAM;AACZ,UAAM,QAAQ;AAAA,EAChB;AACF;;;AExEO,IAAM,cAAc,IACtB,aACgB;AACnB,SAAO,IAAI,eAAe,QAAQ;AACpC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0-ws.rc-1",
|
|
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",
|
|
@@ -55,6 +55,26 @@
|
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">=18"
|
|
57
57
|
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"start": "tsup --watch",
|
|
60
|
+
"clean": "rimraf ./lib",
|
|
61
|
+
"lint": "eslint \"{cli,config,src,test}/**/*.ts\"",
|
|
62
|
+
"build": "pnpm clean && cross-env NODE_ENV=production tsup && pnpm patch:dts",
|
|
63
|
+
"patch:dts": "node \"./config/scripts/patch-ts.js\"",
|
|
64
|
+
"check:exports": "node \"./config/scripts/validate-esm.js\"",
|
|
65
|
+
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native",
|
|
66
|
+
"test:unit": "vitest",
|
|
67
|
+
"test:node": "vitest run --config=./test/node/vitest.config.ts",
|
|
68
|
+
"test:native": "vitest --config=./test/native/vitest.config.ts",
|
|
69
|
+
"test:browser": "playwright test -c ./test/browser/playwright.config.ts",
|
|
70
|
+
"test:modules:node": "vitest run --config=./test/modules/node/vitest.config.ts",
|
|
71
|
+
"test:modules:browser": "playwright test -c ./test/modules/browser/playwright.config.ts",
|
|
72
|
+
"test:ts": "ts-node test/typings/run.ts",
|
|
73
|
+
"prepare": "pnpm simple-git-hooks init",
|
|
74
|
+
"prepack": "pnpm build",
|
|
75
|
+
"release": "release publish",
|
|
76
|
+
"postinstall": "node -e \"try{require('./config/scripts/postinstall')}catch(e){}\""
|
|
77
|
+
},
|
|
58
78
|
"lint-staged": {
|
|
59
79
|
"**/*.ts": [
|
|
60
80
|
"eslint --fix"
|
|
@@ -108,7 +128,7 @@
|
|
|
108
128
|
"@bundled-es-modules/statuses": "^1.0.1",
|
|
109
129
|
"@inquirer/confirm": "^3.0.0",
|
|
110
130
|
"@mswjs/cookies": "^1.1.0",
|
|
111
|
-
"@mswjs/interceptors": "^0.
|
|
131
|
+
"@mswjs/interceptors": "^0.26.8",
|
|
112
132
|
"@open-draft/until": "^2.1.0",
|
|
113
133
|
"@types/cookie": "^0.6.0",
|
|
114
134
|
"@types/statuses": "^2.0.4",
|
|
@@ -125,6 +145,7 @@
|
|
|
125
145
|
"devDependencies": {
|
|
126
146
|
"@commitlint/cli": "^18.4.4",
|
|
127
147
|
"@commitlint/config-conventional": "^18.4.4",
|
|
148
|
+
"@fastify/websocket": "^8.3.1",
|
|
128
149
|
"@open-draft/test-server": "^0.4.2",
|
|
129
150
|
"@ossjs/release": "^0.8.0",
|
|
130
151
|
"@playwright/test": "^1.40.1",
|
|
@@ -134,6 +155,7 @@
|
|
|
134
155
|
"@types/glob": "^8.1.0",
|
|
135
156
|
"@types/json-bigint": "^1.0.4",
|
|
136
157
|
"@types/node": "18.x",
|
|
158
|
+
"@types/ws": "^8.5.10",
|
|
137
159
|
"@typescript-eslint/eslint-plugin": "^5.11.0",
|
|
138
160
|
"@typescript-eslint/parser": "^5.11.0",
|
|
139
161
|
"@web/dev-server": "^0.1.38",
|
|
@@ -149,6 +171,7 @@
|
|
|
149
171
|
"eslint-config-prettier": "^9.1.0",
|
|
150
172
|
"eslint-plugin-prettier": "^5.1.3",
|
|
151
173
|
"express": "^4.18.2",
|
|
174
|
+
"fastify": "^4.26.0",
|
|
152
175
|
"fs-extra": "^11.2.0",
|
|
153
176
|
"fs-teardown": "^0.3.0",
|
|
154
177
|
"glob": "^10.3.10",
|
|
@@ -165,7 +188,7 @@
|
|
|
165
188
|
"typescript": "^5.4.2",
|
|
166
189
|
"undici": "^5.20.0",
|
|
167
190
|
"url-loader": "^4.1.1",
|
|
168
|
-
"vitest": "^
|
|
191
|
+
"vitest": "^1.2.2",
|
|
169
192
|
"vitest-environment-miniflare": "^2.14.1",
|
|
170
193
|
"webpack": "^5.89.0",
|
|
171
194
|
"webpack-http-server": "^0.5.0"
|
|
@@ -187,23 +210,5 @@
|
|
|
187
210
|
"pre-commit": "pnpm lint-staged",
|
|
188
211
|
"prepare-commit-msg": "grep -qE '^[^#]' .git/COMMIT_EDITMSG || (exec < /dev/tty && pnpm cz --hook || true)",
|
|
189
212
|
"commit-msg": "pnpm commitlint --edit $1"
|
|
190
|
-
},
|
|
191
|
-
"scripts": {
|
|
192
|
-
"start": "tsup --watch",
|
|
193
|
-
"clean": "rimraf ./lib",
|
|
194
|
-
"lint": "eslint \"{cli,config,src,test}/**/*.ts\"",
|
|
195
|
-
"build": "pnpm clean && cross-env NODE_ENV=production tsup && pnpm patch:dts",
|
|
196
|
-
"patch:dts": "node \"./config/scripts/patch-ts.js\"",
|
|
197
|
-
"check:exports": "node \"./config/scripts/validate-esm.js\"",
|
|
198
|
-
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native",
|
|
199
|
-
"test:unit": "vitest",
|
|
200
|
-
"test:node": "vitest run --config=./test/node/vitest.config.ts",
|
|
201
|
-
"test:native": "vitest --config=./test/native/vitest.config.ts",
|
|
202
|
-
"test:browser": "playwright test -c ./test/browser/playwright.config.ts",
|
|
203
|
-
"test:modules:node": "vitest --config=./test/modules/node/vitest.config.ts",
|
|
204
|
-
"test:modules:browser": "playwright test -c ./test/modules/browser/playwright.config.ts",
|
|
205
|
-
"test:ts": "ts-node test/typings/run.ts",
|
|
206
|
-
"release": "release publish",
|
|
207
|
-
"postinstall": "node -e \"try{require('./config/scripts/postinstall')}catch(e){}\""
|
|
208
213
|
}
|
|
209
|
-
}
|
|
214
|
+
}
|