@depup/msw 2.12.13-depup.0
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/LICENSE.md +21 -0
- package/README.md +40 -0
- package/browser/package.json +31 -0
- package/changes.json +46 -0
- package/cli/index.js +35 -0
- package/cli/init.js +226 -0
- package/cli/invariant.js +9 -0
- package/cli/package.json +3 -0
- package/config/constants.js +13 -0
- package/config/package.json +3 -0
- package/config/scripts/postinstall.js +36 -0
- package/lib/browser/index.d.mts +102 -0
- package/lib/browser/index.d.ts +102 -0
- package/lib/browser/index.js +2911 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/index.mjs +2888 -0
- package/lib/browser/index.mjs.map +1 -0
- package/lib/core/HttpResponse-Be4eT3x6.d.mts +338 -0
- package/lib/core/HttpResponse-Dj6ibgFJ.d.ts +338 -0
- package/lib/core/HttpResponse.d.mts +6 -0
- package/lib/core/HttpResponse.d.ts +6 -0
- package/lib/core/HttpResponse.js +176 -0
- package/lib/core/HttpResponse.js.map +1 -0
- package/lib/core/HttpResponse.mjs +159 -0
- package/lib/core/HttpResponse.mjs.map +1 -0
- package/lib/core/SetupApi.d.mts +44 -0
- package/lib/core/SetupApi.d.ts +44 -0
- package/lib/core/SetupApi.js +112 -0
- package/lib/core/SetupApi.js.map +1 -0
- package/lib/core/SetupApi.mjs +92 -0
- package/lib/core/SetupApi.mjs.map +1 -0
- package/lib/core/bypass.d.mts +16 -0
- package/lib/core/bypass.d.ts +16 -0
- package/lib/core/bypass.js +42 -0
- package/lib/core/bypass.js.map +1 -0
- package/lib/core/bypass.mjs +22 -0
- package/lib/core/bypass.mjs.map +1 -0
- package/lib/core/delay.d.mts +18 -0
- package/lib/core/delay.d.ts +18 -0
- package/lib/core/delay.js +77 -0
- package/lib/core/delay.js.map +1 -0
- package/lib/core/delay.mjs +57 -0
- package/lib/core/delay.mjs.map +1 -0
- package/lib/core/getResponse.d.mts +18 -0
- package/lib/core/getResponse.d.ts +18 -0
- package/lib/core/getResponse.js +35 -0
- package/lib/core/getResponse.js.map +1 -0
- package/lib/core/getResponse.mjs +17 -0
- package/lib/core/getResponse.mjs.map +1 -0
- package/lib/core/graphql.d.mts +76 -0
- package/lib/core/graphql.d.ts +76 -0
- package/lib/core/graphql.js +90 -0
- package/lib/core/graphql.js.map +1 -0
- package/lib/core/graphql.mjs +72 -0
- package/lib/core/graphql.mjs.map +1 -0
- package/lib/core/handlers/GraphQLHandler.d.mts +6 -0
- package/lib/core/handlers/GraphQLHandler.d.ts +6 -0
- package/lib/core/handlers/GraphQLHandler.js +231 -0
- package/lib/core/handlers/GraphQLHandler.js.map +1 -0
- package/lib/core/handlers/GraphQLHandler.mjs +218 -0
- package/lib/core/handlers/GraphQLHandler.mjs.map +1 -0
- package/lib/core/handlers/HttpHandler.d.mts +75 -0
- package/lib/core/handlers/HttpHandler.d.ts +75 -0
- package/lib/core/handlers/HttpHandler.js +128 -0
- package/lib/core/handlers/HttpHandler.js.map +1 -0
- package/lib/core/handlers/HttpHandler.mjs +112 -0
- package/lib/core/handlers/HttpHandler.mjs.map +1 -0
- package/lib/core/handlers/RequestHandler.d.mts +6 -0
- package/lib/core/handlers/RequestHandler.d.ts +6 -0
- package/lib/core/handlers/RequestHandler.js +173 -0
- package/lib/core/handlers/RequestHandler.js.map +1 -0
- package/lib/core/handlers/RequestHandler.mjs +155 -0
- package/lib/core/handlers/RequestHandler.mjs.map +1 -0
- package/lib/core/handlers/WebSocketHandler.d.mts +42 -0
- package/lib/core/handlers/WebSocketHandler.d.ts +42 -0
- package/lib/core/handlers/WebSocketHandler.js +147 -0
- package/lib/core/handlers/WebSocketHandler.js.map +1 -0
- package/lib/core/handlers/WebSocketHandler.mjs +129 -0
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -0
- package/lib/core/handlers/common.d.mts +3 -0
- package/lib/core/handlers/common.d.ts +3 -0
- package/lib/core/handlers/common.js +17 -0
- package/lib/core/handlers/common.js.map +1 -0
- package/lib/core/handlers/common.mjs +1 -0
- package/lib/core/handlers/common.mjs.map +1 -0
- package/lib/core/http.d.mts +31 -0
- package/lib/core/http.d.ts +31 -0
- package/lib/core/http.js +40 -0
- package/lib/core/http.js.map +1 -0
- package/lib/core/http.mjs +23 -0
- package/lib/core/http.mjs.map +1 -0
- package/lib/core/index.d.mts +32 -0
- package/lib/core/index.d.ts +32 -0
- package/lib/core/index.js +64 -0
- package/lib/core/index.js.map +1 -0
- package/lib/core/index.mjs +52 -0
- package/lib/core/index.mjs.map +1 -0
- package/lib/core/isCommonAssetRequest.d.mts +20 -0
- package/lib/core/isCommonAssetRequest.d.ts +20 -0
- package/lib/core/isCommonAssetRequest.js +42 -0
- package/lib/core/isCommonAssetRequest.js.map +1 -0
- package/lib/core/isCommonAssetRequest.mjs +22 -0
- package/lib/core/isCommonAssetRequest.mjs.map +1 -0
- package/lib/core/passthrough.d.mts +24 -0
- package/lib/core/passthrough.d.ts +24 -0
- package/lib/core/passthrough.js +33 -0
- package/lib/core/passthrough.js.map +1 -0
- package/lib/core/passthrough.mjs +13 -0
- package/lib/core/passthrough.mjs.map +1 -0
- package/lib/core/sharedOptions.d.mts +64 -0
- package/lib/core/sharedOptions.d.ts +64 -0
- package/lib/core/sharedOptions.js +17 -0
- package/lib/core/sharedOptions.js.map +1 -0
- package/lib/core/sharedOptions.mjs +1 -0
- package/lib/core/sharedOptions.mjs.map +1 -0
- package/lib/core/sse.d.mts +116 -0
- package/lib/core/sse.d.ts +116 -0
- package/lib/core/sse.js +607 -0
- package/lib/core/sse.js.map +1 -0
- package/lib/core/sse.mjs +589 -0
- package/lib/core/sse.mjs.map +1 -0
- package/lib/core/typeUtils.d.mts +12 -0
- package/lib/core/typeUtils.d.ts +12 -0
- package/lib/core/typeUtils.js +17 -0
- package/lib/core/typeUtils.js.map +1 -0
- package/lib/core/typeUtils.mjs +1 -0
- package/lib/core/typeUtils.mjs.map +1 -0
- package/lib/core/utils/HttpResponse/decorators.d.mts +17 -0
- package/lib/core/utils/HttpResponse/decorators.d.ts +17 -0
- package/lib/core/utils/HttpResponse/decorators.js +77 -0
- package/lib/core/utils/HttpResponse/decorators.js.map +1 -0
- package/lib/core/utils/HttpResponse/decorators.mjs +47 -0
- package/lib/core/utils/HttpResponse/decorators.mjs.map +1 -0
- package/lib/core/utils/cookieStore.d.mts +13 -0
- package/lib/core/utils/cookieStore.d.ts +13 -0
- package/lib/core/utils/cookieStore.js +90 -0
- package/lib/core/utils/cookieStore.js.map +1 -0
- package/lib/core/utils/cookieStore.mjs +74 -0
- package/lib/core/utils/cookieStore.mjs.map +1 -0
- package/lib/core/utils/executeHandlers.d.mts +6 -0
- package/lib/core/utils/executeHandlers.d.ts +6 -0
- package/lib/core/utils/executeHandlers.js +50 -0
- package/lib/core/utils/executeHandlers.js.map +1 -0
- package/lib/core/utils/executeHandlers.mjs +30 -0
- package/lib/core/utils/executeHandlers.mjs.map +1 -0
- package/lib/core/utils/handleRequest.d.mts +29 -0
- package/lib/core/utils/handleRequest.d.ts +29 -0
- package/lib/core/utils/handleRequest.js +76 -0
- package/lib/core/utils/handleRequest.js.map +1 -0
- package/lib/core/utils/handleRequest.mjs +58 -0
- package/lib/core/utils/handleRequest.mjs.map +1 -0
- package/lib/core/utils/internal/Disposable.d.mts +7 -0
- package/lib/core/utils/internal/Disposable.d.ts +7 -0
- package/lib/core/utils/internal/Disposable.js +33 -0
- package/lib/core/utils/internal/Disposable.js.map +1 -0
- package/lib/core/utils/internal/Disposable.mjs +13 -0
- package/lib/core/utils/internal/Disposable.mjs.map +1 -0
- package/lib/core/utils/internal/checkGlobals.d.mts +3 -0
- package/lib/core/utils/internal/checkGlobals.d.ts +3 -0
- package/lib/core/utils/internal/checkGlobals.js +34 -0
- package/lib/core/utils/internal/checkGlobals.js.map +1 -0
- package/lib/core/utils/internal/checkGlobals.mjs +14 -0
- package/lib/core/utils/internal/checkGlobals.mjs.map +1 -0
- package/lib/core/utils/internal/devUtils.d.mts +28 -0
- package/lib/core/utils/internal/devUtils.d.ts +28 -0
- package/lib/core/utils/internal/devUtils.js +48 -0
- package/lib/core/utils/internal/devUtils.js.map +1 -0
- package/lib/core/utils/internal/devUtils.mjs +28 -0
- package/lib/core/utils/internal/devUtils.mjs.map +1 -0
- package/lib/core/utils/internal/getCallFrame.d.mts +6 -0
- package/lib/core/utils/internal/getCallFrame.d.ts +6 -0
- package/lib/core/utils/internal/getCallFrame.js +41 -0
- package/lib/core/utils/internal/getCallFrame.js.map +1 -0
- package/lib/core/utils/internal/getCallFrame.mjs +21 -0
- package/lib/core/utils/internal/getCallFrame.mjs.map +1 -0
- package/lib/core/utils/internal/hasRefCounted.d.mts +3 -0
- package/lib/core/utils/internal/hasRefCounted.d.ts +3 -0
- package/lib/core/utils/internal/hasRefCounted.js +27 -0
- package/lib/core/utils/internal/hasRefCounted.js.map +1 -0
- package/lib/core/utils/internal/hasRefCounted.mjs +7 -0
- package/lib/core/utils/internal/hasRefCounted.mjs.map +1 -0
- package/lib/core/utils/internal/isHandlerKind.d.mts +19 -0
- package/lib/core/utils/internal/isHandlerKind.d.ts +19 -0
- package/lib/core/utils/internal/isHandlerKind.js +29 -0
- package/lib/core/utils/internal/isHandlerKind.js.map +1 -0
- package/lib/core/utils/internal/isHandlerKind.mjs +9 -0
- package/lib/core/utils/internal/isHandlerKind.mjs.map +1 -0
- package/lib/core/utils/internal/isIterable.d.mts +20 -0
- package/lib/core/utils/internal/isIterable.d.ts +20 -0
- package/lib/core/utils/internal/isIterable.js +30 -0
- package/lib/core/utils/internal/isIterable.js.map +1 -0
- package/lib/core/utils/internal/isIterable.mjs +10 -0
- package/lib/core/utils/internal/isIterable.mjs.map +1 -0
- package/lib/core/utils/internal/isObject.d.mts +6 -0
- package/lib/core/utils/internal/isObject.d.ts +6 -0
- package/lib/core/utils/internal/isObject.js +27 -0
- package/lib/core/utils/internal/isObject.js.map +1 -0
- package/lib/core/utils/internal/isObject.mjs +7 -0
- package/lib/core/utils/internal/isObject.mjs.map +1 -0
- package/lib/core/utils/internal/isStringEqual.d.mts +6 -0
- package/lib/core/utils/internal/isStringEqual.d.ts +6 -0
- package/lib/core/utils/internal/isStringEqual.js +27 -0
- package/lib/core/utils/internal/isStringEqual.js.map +1 -0
- package/lib/core/utils/internal/isStringEqual.mjs +7 -0
- package/lib/core/utils/internal/isStringEqual.mjs.map +1 -0
- package/lib/core/utils/internal/jsonParse.d.mts +7 -0
- package/lib/core/utils/internal/jsonParse.d.ts +7 -0
- package/lib/core/utils/internal/jsonParse.js +31 -0
- package/lib/core/utils/internal/jsonParse.js.map +1 -0
- package/lib/core/utils/internal/jsonParse.mjs +11 -0
- package/lib/core/utils/internal/jsonParse.mjs.map +1 -0
- package/lib/core/utils/internal/mergeRight.d.mts +7 -0
- package/lib/core/utils/internal/mergeRight.d.ts +7 -0
- package/lib/core/utils/internal/mergeRight.js +43 -0
- package/lib/core/utils/internal/mergeRight.js.map +1 -0
- package/lib/core/utils/internal/mergeRight.mjs +23 -0
- package/lib/core/utils/internal/mergeRight.mjs.map +1 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +6 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +6 -0
- package/lib/core/utils/internal/parseGraphQLRequest.js +146 -0
- package/lib/core/utils/internal/parseGraphQLRequest.js.map +1 -0
- package/lib/core/utils/internal/parseGraphQLRequest.mjs +129 -0
- package/lib/core/utils/internal/parseGraphQLRequest.mjs.map +1 -0
- package/lib/core/utils/internal/parseMultipartData.d.mts +14 -0
- package/lib/core/utils/internal/parseMultipartData.d.ts +14 -0
- package/lib/core/utils/internal/parseMultipartData.js +83 -0
- package/lib/core/utils/internal/parseMultipartData.js.map +1 -0
- package/lib/core/utils/internal/parseMultipartData.mjs +63 -0
- package/lib/core/utils/internal/parseMultipartData.mjs.map +1 -0
- package/lib/core/utils/internal/pipeEvents.d.mts +8 -0
- package/lib/core/utils/internal/pipeEvents.d.ts +8 -0
- package/lib/core/utils/internal/pipeEvents.js +36 -0
- package/lib/core/utils/internal/pipeEvents.js.map +1 -0
- package/lib/core/utils/internal/pipeEvents.mjs +16 -0
- package/lib/core/utils/internal/pipeEvents.mjs.map +1 -0
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +12 -0
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +12 -0
- package/lib/core/utils/internal/requestHandlerUtils.js +37 -0
- package/lib/core/utils/internal/requestHandlerUtils.js.map +1 -0
- package/lib/core/utils/internal/requestHandlerUtils.mjs +17 -0
- package/lib/core/utils/internal/requestHandlerUtils.mjs.map +1 -0
- package/lib/core/utils/internal/toReadonlyArray.d.mts +6 -0
- package/lib/core/utils/internal/toReadonlyArray.d.ts +6 -0
- package/lib/core/utils/internal/toReadonlyArray.js +29 -0
- package/lib/core/utils/internal/toReadonlyArray.js.map +1 -0
- package/lib/core/utils/internal/toReadonlyArray.mjs +9 -0
- package/lib/core/utils/internal/toReadonlyArray.mjs.map +1 -0
- package/lib/core/utils/internal/tryCatch.d.mts +3 -0
- package/lib/core/utils/internal/tryCatch.d.ts +3 -0
- package/lib/core/utils/internal/tryCatch.js +32 -0
- package/lib/core/utils/internal/tryCatch.js.map +1 -0
- package/lib/core/utils/internal/tryCatch.mjs +12 -0
- package/lib/core/utils/internal/tryCatch.mjs.map +1 -0
- package/lib/core/utils/logging/getStatusCodeColor.d.mts +11 -0
- package/lib/core/utils/logging/getStatusCodeColor.d.ts +11 -0
- package/lib/core/utils/logging/getStatusCodeColor.js +40 -0
- package/lib/core/utils/logging/getStatusCodeColor.js.map +1 -0
- package/lib/core/utils/logging/getStatusCodeColor.mjs +20 -0
- package/lib/core/utils/logging/getStatusCodeColor.mjs.map +1 -0
- package/lib/core/utils/logging/getTimestamp.d.mts +9 -0
- package/lib/core/utils/logging/getTimestamp.d.ts +9 -0
- package/lib/core/utils/logging/getTimestamp.js +32 -0
- package/lib/core/utils/logging/getTimestamp.js.map +1 -0
- package/lib/core/utils/logging/getTimestamp.mjs +12 -0
- package/lib/core/utils/logging/getTimestamp.mjs.map +1 -0
- package/lib/core/utils/logging/serializeRequest.d.mts +12 -0
- package/lib/core/utils/logging/serializeRequest.d.ts +12 -0
- package/lib/core/utils/logging/serializeRequest.js +34 -0
- package/lib/core/utils/logging/serializeRequest.js.map +1 -0
- package/lib/core/utils/logging/serializeRequest.mjs +14 -0
- package/lib/core/utils/logging/serializeRequest.mjs.map +1 -0
- package/lib/core/utils/logging/serializeResponse.d.mts +9 -0
- package/lib/core/utils/logging/serializeResponse.d.ts +9 -0
- package/lib/core/utils/logging/serializeResponse.js +48 -0
- package/lib/core/utils/logging/serializeResponse.js.map +1 -0
- package/lib/core/utils/logging/serializeResponse.mjs +18 -0
- package/lib/core/utils/logging/serializeResponse.mjs.map +1 -0
- package/lib/core/utils/matching/matchRequestUrl.d.mts +20 -0
- package/lib/core/utils/matching/matchRequestUrl.d.ts +20 -0
- package/lib/core/utils/matching/matchRequestUrl.js +55 -0
- package/lib/core/utils/matching/matchRequestUrl.js.map +1 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs +35 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -0
- package/lib/core/utils/matching/normalizePath.d.mts +13 -0
- package/lib/core/utils/matching/normalizePath.d.ts +13 -0
- package/lib/core/utils/matching/normalizePath.js +33 -0
- package/lib/core/utils/matching/normalizePath.js.map +1 -0
- package/lib/core/utils/matching/normalizePath.mjs +13 -0
- package/lib/core/utils/matching/normalizePath.mjs.map +1 -0
- package/lib/core/utils/request/getAllAcceptedMimeTypes.d.mts +14 -0
- package/lib/core/utils/request/getAllAcceptedMimeTypes.d.ts +14 -0
- package/lib/core/utils/request/getAllAcceptedMimeTypes.js +61 -0
- package/lib/core/utils/request/getAllAcceptedMimeTypes.js.map +1 -0
- package/lib/core/utils/request/getAllAcceptedMimeTypes.mjs +41 -0
- package/lib/core/utils/request/getAllAcceptedMimeTypes.mjs.map +1 -0
- package/lib/core/utils/request/getRequestCookies.d.mts +3 -0
- package/lib/core/utils/request/getRequestCookies.d.ts +3 -0
- package/lib/core/utils/request/getRequestCookies.js +79 -0
- package/lib/core/utils/request/getRequestCookies.js.map +1 -0
- package/lib/core/utils/request/getRequestCookies.mjs +62 -0
- package/lib/core/utils/request/getRequestCookies.mjs.map +1 -0
- package/lib/core/utils/request/onUnhandledRequest.d.mts +9 -0
- package/lib/core/utils/request/onUnhandledRequest.d.ts +9 -0
- package/lib/core/utils/request/onUnhandledRequest.js +76 -0
- package/lib/core/utils/request/onUnhandledRequest.js.map +1 -0
- package/lib/core/utils/request/onUnhandledRequest.mjs +56 -0
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -0
- package/lib/core/utils/request/storeResponseCookies.d.mts +3 -0
- package/lib/core/utils/request/storeResponseCookies.d.ts +3 -0
- package/lib/core/utils/request/storeResponseCookies.js +32 -0
- package/lib/core/utils/request/storeResponseCookies.js.map +1 -0
- package/lib/core/utils/request/storeResponseCookies.mjs +12 -0
- package/lib/core/utils/request/storeResponseCookies.mjs.map +1 -0
- package/lib/core/utils/request/toPublicUrl.d.mts +7 -0
- package/lib/core/utils/request/toPublicUrl.d.ts +7 -0
- package/lib/core/utils/request/toPublicUrl.js +31 -0
- package/lib/core/utils/request/toPublicUrl.js.map +1 -0
- package/lib/core/utils/request/toPublicUrl.mjs +11 -0
- package/lib/core/utils/request/toPublicUrl.mjs.map +1 -0
- package/lib/core/utils/toResponseInit.d.mts +3 -0
- package/lib/core/utils/toResponseInit.d.ts +3 -0
- package/lib/core/utils/toResponseInit.js +31 -0
- package/lib/core/utils/toResponseInit.js.map +1 -0
- package/lib/core/utils/toResponseInit.mjs +11 -0
- package/lib/core/utils/toResponseInit.mjs.map +1 -0
- package/lib/core/utils/url/cleanUrl.d.mts +7 -0
- package/lib/core/utils/url/cleanUrl.d.ts +7 -0
- package/lib/core/utils/url/cleanUrl.js +31 -0
- package/lib/core/utils/url/cleanUrl.js.map +1 -0
- package/lib/core/utils/url/cleanUrl.mjs +11 -0
- package/lib/core/utils/url/cleanUrl.mjs.map +1 -0
- package/lib/core/utils/url/getAbsoluteUrl.d.mts +6 -0
- package/lib/core/utils/url/getAbsoluteUrl.d.ts +6 -0
- package/lib/core/utils/url/getAbsoluteUrl.js +38 -0
- package/lib/core/utils/url/getAbsoluteUrl.js.map +1 -0
- package/lib/core/utils/url/getAbsoluteUrl.mjs +18 -0
- package/lib/core/utils/url/getAbsoluteUrl.mjs.map +1 -0
- package/lib/core/utils/url/isAbsoluteUrl.d.mts +6 -0
- package/lib/core/utils/url/isAbsoluteUrl.d.ts +6 -0
- package/lib/core/utils/url/isAbsoluteUrl.js +27 -0
- package/lib/core/utils/url/isAbsoluteUrl.js.map +1 -0
- package/lib/core/utils/url/isAbsoluteUrl.mjs +7 -0
- package/lib/core/utils/url/isAbsoluteUrl.mjs.map +1 -0
- package/lib/core/ws/WebSocketClientManager.d.mts +65 -0
- package/lib/core/ws/WebSocketClientManager.d.ts +65 -0
- package/lib/core/ws/WebSocketClientManager.js +159 -0
- package/lib/core/ws/WebSocketClientManager.js.map +1 -0
- package/lib/core/ws/WebSocketClientManager.mjs +139 -0
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -0
- package/lib/core/ws/WebSocketClientStore.d.mts +13 -0
- package/lib/core/ws/WebSocketClientStore.d.ts +13 -0
- package/lib/core/ws/WebSocketClientStore.js +26 -0
- package/lib/core/ws/WebSocketClientStore.js.map +1 -0
- package/lib/core/ws/WebSocketClientStore.mjs +6 -0
- package/lib/core/ws/WebSocketClientStore.mjs.map +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.mts +14 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.ts +14 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.js +130 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +110 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.d.mts +12 -0
- package/lib/core/ws/WebSocketMemoryClientStore.d.ts +12 -0
- package/lib/core/ws/WebSocketMemoryClientStore.js +41 -0
- package/lib/core/ws/WebSocketMemoryClientStore.js.map +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.mjs +21 -0
- package/lib/core/ws/WebSocketMemoryClientStore.mjs.map +1 -0
- package/lib/core/ws/handleWebSocketEvent.d.mts +20 -0
- package/lib/core/ws/handleWebSocketEvent.d.ts +20 -0
- package/lib/core/ws/handleWebSocketEvent.js +61 -0
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -0
- package/lib/core/ws/handleWebSocketEvent.mjs +43 -0
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -0
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +18 -0
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +18 -0
- package/lib/core/ws/utils/attachWebSocketLogger.js +199 -0
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -0
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +179 -0
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -0
- package/lib/core/ws/utils/getMessageLength.d.mts +11 -0
- package/lib/core/ws/utils/getMessageLength.d.ts +11 -0
- package/lib/core/ws/utils/getMessageLength.js +34 -0
- package/lib/core/ws/utils/getMessageLength.js.map +1 -0
- package/lib/core/ws/utils/getMessageLength.mjs +14 -0
- package/lib/core/ws/utils/getMessageLength.mjs.map +1 -0
- package/lib/core/ws/utils/getPublicData.d.mts +5 -0
- package/lib/core/ws/utils/getPublicData.d.ts +5 -0
- package/lib/core/ws/utils/getPublicData.js +37 -0
- package/lib/core/ws/utils/getPublicData.js.map +1 -0
- package/lib/core/ws/utils/getPublicData.mjs +17 -0
- package/lib/core/ws/utils/getPublicData.mjs.map +1 -0
- package/lib/core/ws/utils/truncateMessage.d.mts +3 -0
- package/lib/core/ws/utils/truncateMessage.d.ts +3 -0
- package/lib/core/ws/utils/truncateMessage.js +31 -0
- package/lib/core/ws/utils/truncateMessage.js.map +1 -0
- package/lib/core/ws/utils/truncateMessage.mjs +11 -0
- package/lib/core/ws/utils/truncateMessage.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.d.mts +75 -0
- package/lib/core/ws.d.ts +75 -0
- package/lib/core/ws.js +69 -0
- package/lib/core/ws.js.map +1 -0
- package/lib/core/ws.mjs +52 -0
- package/lib/core/ws.mjs.map +1 -0
- package/lib/iife/index.js +23752 -0
- package/lib/iife/index.js.map +1 -0
- package/lib/mockServiceWorker.js +349 -0
- package/lib/native/index.d.mts +74 -0
- package/lib/native/index.d.ts +74 -0
- package/lib/native/index.js +156 -0
- package/lib/native/index.js.map +1 -0
- package/lib/native/index.mjs +134 -0
- package/lib/native/index.mjs.map +1 -0
- package/lib/node/index.d.mts +91 -0
- package/lib/node/index.d.ts +91 -0
- package/lib/node/index.js +209 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/index.mjs +184 -0
- package/lib/node/index.mjs.map +1 -0
- package/lib/shims/cookie.d.mts +7 -0
- package/lib/shims/cookie.d.ts +7 -0
- package/lib/shims/cookie.js +204 -0
- package/lib/shims/cookie.mjs +196 -0
- package/lib/shims/statuses.d.mts +6 -0
- package/lib/shims/statuses.d.ts +6 -0
- package/lib/shims/statuses.js +195 -0
- package/lib/shims/statuses.mjs +187 -0
- package/native/package.json +30 -0
- package/node/package.json +33 -0
- package/package.json +381 -0
- package/src/browser/global.browser.d.ts +1 -0
- package/src/browser/index.ts +3 -0
- package/src/browser/setupWorker/glossary.ts +138 -0
- package/src/browser/setupWorker/setupWorker.node.test.ts +10 -0
- package/src/browser/setupWorker/setupWorker.ts +184 -0
- package/src/browser/setupWorker/start/createFallbackRequestListener.ts +71 -0
- package/src/browser/setupWorker/start/createRequestListener.ts +138 -0
- package/src/browser/setupWorker/start/createResponseListener.ts +57 -0
- package/src/browser/setupWorker/start/createStartHandler.ts +137 -0
- package/src/browser/setupWorker/start/utils/enableMocking.ts +30 -0
- package/src/browser/setupWorker/start/utils/getWorkerByRegistration.ts +25 -0
- package/src/browser/setupWorker/start/utils/getWorkerInstance.ts +97 -0
- package/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts +59 -0
- package/src/browser/setupWorker/start/utils/prepareStartHandler.ts +44 -0
- package/src/browser/setupWorker/start/utils/printStartMessage.test.ts +84 -0
- package/src/browser/setupWorker/start/utils/printStartMessage.ts +51 -0
- package/src/browser/setupWorker/start/utils/validateWorkerScope.ts +18 -0
- package/src/browser/setupWorker/stop/utils/printStopMessage.test.ts +26 -0
- package/src/browser/setupWorker/stop/utils/printStopMessage.ts +13 -0
- package/src/browser/tsconfig.browser.build.json +6 -0
- package/src/browser/tsconfig.browser.json +9 -0
- package/src/browser/utils/checkWorkerIntegrity.ts +42 -0
- package/src/browser/utils/deserializeRequest.ts +15 -0
- package/src/browser/utils/getAbsoluteWorkerUrl.test.ts +29 -0
- package/src/browser/utils/getAbsoluteWorkerUrl.ts +7 -0
- package/src/browser/utils/pruneGetRequestBody.test.ts +53 -0
- package/src/browser/utils/pruneGetRequestBody.ts +21 -0
- package/src/browser/utils/supports.ts +30 -0
- package/src/browser/utils/workerChannel.ts +159 -0
- package/src/core/HttpResponse.test.ts +378 -0
- package/src/core/HttpResponse.ts +248 -0
- package/src/core/SetupApi.ts +127 -0
- package/src/core/bypass.test.ts +80 -0
- package/src/core/bypass.ts +46 -0
- package/src/core/delay.ts +82 -0
- package/src/core/getResponse.test.ts +74 -0
- package/src/core/getResponse.ts +29 -0
- package/src/core/graphql.test.ts +11 -0
- package/src/core/graphql.ts +136 -0
- package/src/core/handlers/GraphQLHandler.test.ts +873 -0
- package/src/core/handlers/GraphQLHandler.ts +437 -0
- package/src/core/handlers/HttpHandler.test.ts +253 -0
- package/src/core/handlers/HttpHandler.ts +214 -0
- package/src/core/handlers/RequestHandler.ts +391 -0
- package/src/core/handlers/WebSocketHandler.test.ts +127 -0
- package/src/core/handlers/WebSocketHandler.ts +209 -0
- package/src/core/handlers/common.ts +1 -0
- package/src/core/http.test.ts +15 -0
- package/src/core/http.ts +64 -0
- package/src/core/index.ts +110 -0
- package/src/core/isCommonAssetRequest.ts +45 -0
- package/src/core/passthrough.test.ts +11 -0
- package/src/core/passthrough.ts +25 -0
- package/src/core/sharedOptions.ts +66 -0
- package/src/core/sse.ts +916 -0
- package/src/core/typeUtils.ts +26 -0
- package/src/core/utils/HttpResponse/decorators.ts +76 -0
- package/src/core/utils/cookieStore.ts +94 -0
- package/src/core/utils/executeHandlers.ts +69 -0
- package/src/core/utils/handleRequest.test.ts +573 -0
- package/src/core/utils/handleRequest.ts +117 -0
- package/src/core/utils/internal/Disposable.ts +12 -0
- package/src/core/utils/internal/checkGlobals.ts +17 -0
- package/src/core/utils/internal/devUtils.test.ts +21 -0
- package/src/core/utils/internal/devUtils.ts +44 -0
- package/src/core/utils/internal/getCallFrame.test.ts +154 -0
- package/src/core/utils/internal/getCallFrame.ts +35 -0
- package/src/core/utils/internal/hasRefCounted.test.ts +16 -0
- package/src/core/utils/internal/hasRefCounted.ts +8 -0
- package/src/core/utils/internal/isHandlerKind.test.ts +64 -0
- package/src/core/utils/internal/isHandlerKind.ts +21 -0
- package/src/core/utils/internal/isIterable.test.ts +23 -0
- package/src/core/utils/internal/isIterable.ts +32 -0
- package/src/core/utils/internal/isObject.test.ts +20 -0
- package/src/core/utils/internal/isObject.ts +6 -0
- package/src/core/utils/internal/isStringEqual.test.ts +45 -0
- package/src/core/utils/internal/isStringEqual.ts +6 -0
- package/src/core/utils/internal/jsonParse.test.ts +13 -0
- package/src/core/utils/internal/jsonParse.ts +13 -0
- package/src/core/utils/internal/mergeRight.test.ts +43 -0
- package/src/core/utils/internal/mergeRight.ts +30 -0
- package/src/core/utils/internal/parseGraphQLRequest.test.ts +99 -0
- package/src/core/utils/internal/parseGraphQLRequest.ts +214 -0
- package/src/core/utils/internal/parseMultipartData.test.ts +76 -0
- package/src/core/utils/internal/parseMultipartData.ts +106 -0
- package/src/core/utils/internal/pipeEvents.test.ts +14 -0
- package/src/core/utils/internal/pipeEvents.ts +25 -0
- package/src/core/utils/internal/requestHandlerUtils.ts +21 -0
- package/src/core/utils/internal/toReadonlyArray.test.ts +30 -0
- package/src/core/utils/internal/toReadonlyArray.ts +8 -0
- package/src/core/utils/internal/tryCatch.test.ts +29 -0
- package/src/core/utils/internal/tryCatch.ts +11 -0
- package/src/core/utils/logging/getStatusCodeColor.test.ts +22 -0
- package/src/core/utils/logging/getStatusCodeColor.ts +20 -0
- package/src/core/utils/logging/getTimestamp.test.ts +32 -0
- package/src/core/utils/logging/getTimestamp.ts +17 -0
- package/src/core/utils/logging/serializeRequest.test.ts +23 -0
- package/src/core/utils/logging/serializeRequest.ts +23 -0
- package/src/core/utils/logging/serializeResponse.test.ts +77 -0
- package/src/core/utils/logging/serializeResponse.ts +31 -0
- package/src/core/utils/matching/matchRequestUrl.test.ts +183 -0
- package/src/core/utils/matching/matchRequestUrl.ts +77 -0
- package/src/core/utils/matching/normalizePath.node.test.ts +44 -0
- package/src/core/utils/matching/normalizePath.test.ts +56 -0
- package/src/core/utils/matching/normalizePath.ts +22 -0
- package/src/core/utils/request/getAllAcceptedMimeTypes.test.ts +86 -0
- package/src/core/utils/request/getAllAcceptedMimeTypes.ts +70 -0
- package/src/core/utils/request/getRequestCookies.ts +88 -0
- package/src/core/utils/request/onUnhandledRequest.node.test.ts +62 -0
- package/src/core/utils/request/onUnhandledRequest.test.ts +228 -0
- package/src/core/utils/request/onUnhandledRequest.ts +81 -0
- package/src/core/utils/request/storeResponseCookies.ts +17 -0
- package/src/core/utils/request/toPublicUrl.node.test.ts +17 -0
- package/src/core/utils/request/toPublicUrl.test.ts +16 -0
- package/src/core/utils/request/toPublicUrl.ts +16 -0
- package/src/core/utils/toResponseInit.ts +7 -0
- package/src/core/utils/url/cleanUrl.test.ts +22 -0
- package/src/core/utils/url/cleanUrl.ts +16 -0
- package/src/core/utils/url/getAbsoluteUrl.node.test.ts +19 -0
- package/src/core/utils/url/getAbsoluteUrl.test.ts +47 -0
- package/src/core/utils/url/getAbsoluteUrl.ts +25 -0
- package/src/core/utils/url/isAbsoluteUrl.test.ts +32 -0
- package/src/core/utils/url/isAbsoluteUrl.ts +6 -0
- package/src/core/ws/WebSocketClientManager.test.ts +164 -0
- package/src/core/ws/WebSocketClientManager.ts +241 -0
- package/src/core/ws/WebSocketClientStore.ts +14 -0
- package/src/core/ws/WebSocketIndexedDBClientStore.ts +140 -0
- package/src/core/ws/WebSocketMemoryClientStore.ts +27 -0
- package/src/core/ws/handleWebSocketEvent.ts +64 -0
- package/src/core/ws/utils/attachWebSocketLogger.ts +245 -0
- package/src/core/ws/utils/getMessageLength.test.ts +16 -0
- package/src/core/ws/utils/getMessageLength.ts +20 -0
- package/src/core/ws/utils/getPublicData.test.ts +38 -0
- package/src/core/ws/utils/getPublicData.ts +18 -0
- package/src/core/ws/utils/truncateMessage.test.ts +12 -0
- package/src/core/ws/utils/truncateMessage.ts +9 -0
- package/src/core/ws/webSocketInterceptor.ts +3 -0
- package/src/core/ws.test.ts +23 -0
- package/src/core/ws.ts +161 -0
- package/src/iife/index.ts +2 -0
- package/src/mockServiceWorker.js +349 -0
- package/src/native/index.ts +21 -0
- package/src/node/SetupServerApi.ts +87 -0
- package/src/node/SetupServerCommonApi.ts +169 -0
- package/src/node/glossary.ts +74 -0
- package/src/node/index.ts +3 -0
- package/src/node/setupServer.ts +15 -0
- package/src/package.json +3 -0
- package/src/shims/cookie.ts +7 -0
- package/src/shims/statuses.ts +6 -0
- package/src/tsconfig.core.build.json +6 -0
- package/src/tsconfig.node.build.json +6 -0
- package/src/tsconfig.node.json +8 -0
- package/src/tsconfig.src.json +10 -0
- package/src/tsconfig.worker.json +13 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { WebSocketHandler } from './WebSocketHandler'
|
|
2
|
+
|
|
3
|
+
describe('parse', () => {
|
|
4
|
+
it('matches an exact url', () => {
|
|
5
|
+
expect(
|
|
6
|
+
new WebSocketHandler('ws://localhost:3000').parse({
|
|
7
|
+
url: new URL('ws://localhost:3000'),
|
|
8
|
+
}),
|
|
9
|
+
).toEqual({
|
|
10
|
+
match: {
|
|
11
|
+
matches: true,
|
|
12
|
+
params: {},
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('ignores trailing slash', () => {
|
|
18
|
+
expect(
|
|
19
|
+
new WebSocketHandler('ws://localhost:3000').parse({
|
|
20
|
+
url: new URL('ws://localhost:3000/'),
|
|
21
|
+
}),
|
|
22
|
+
).toEqual({
|
|
23
|
+
match: {
|
|
24
|
+
matches: true,
|
|
25
|
+
params: {},
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
expect(
|
|
30
|
+
new WebSocketHandler('ws://localhost:3000/').parse({
|
|
31
|
+
url: new URL('ws://localhost:3000/'),
|
|
32
|
+
}),
|
|
33
|
+
).toEqual({
|
|
34
|
+
match: {
|
|
35
|
+
matches: true,
|
|
36
|
+
params: {},
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('supports path parameters', () => {
|
|
42
|
+
expect(
|
|
43
|
+
new WebSocketHandler('ws://localhost:3000/:serviceName').parse({
|
|
44
|
+
url: new URL('ws://localhost:3000/auth'),
|
|
45
|
+
}),
|
|
46
|
+
).toEqual({
|
|
47
|
+
match: {
|
|
48
|
+
matches: true,
|
|
49
|
+
params: {
|
|
50
|
+
serviceName: 'auth',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('ignores "/socket.io/" prefix in the client url', () => {
|
|
57
|
+
expect(
|
|
58
|
+
new WebSocketHandler('ws://localhost:3000').parse({
|
|
59
|
+
url: new URL(
|
|
60
|
+
'ws://localhost:3000/socket.io/?EIO=4&transport=websocket',
|
|
61
|
+
),
|
|
62
|
+
}),
|
|
63
|
+
).toEqual({
|
|
64
|
+
match: {
|
|
65
|
+
matches: true,
|
|
66
|
+
params: {},
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
expect(
|
|
71
|
+
new WebSocketHandler('ws://localhost:3000/non-matching').parse({
|
|
72
|
+
url: new URL(
|
|
73
|
+
'ws://localhost:3000/socket.io/?EIO=4&transport=websocket',
|
|
74
|
+
),
|
|
75
|
+
}),
|
|
76
|
+
).toEqual({
|
|
77
|
+
match: {
|
|
78
|
+
matches: false,
|
|
79
|
+
params: {},
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('preserves non-prefix "/socket.io/" path segment', () => {
|
|
85
|
+
/**
|
|
86
|
+
* @note It is highly unlikely but we still shouldn't modify the
|
|
87
|
+
* WebSocket client URL if it contains a user-defined "socket.io" segment.
|
|
88
|
+
*/
|
|
89
|
+
expect(
|
|
90
|
+
new WebSocketHandler('ws://localhost:3000/clients/socket.io/123').parse({
|
|
91
|
+
url: new URL('ws://localhost:3000/clients/socket.io/123'),
|
|
92
|
+
}),
|
|
93
|
+
).toEqual({
|
|
94
|
+
match: {
|
|
95
|
+
matches: true,
|
|
96
|
+
params: {},
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
expect(
|
|
101
|
+
new WebSocketHandler('ws://localhost:3000').parse({
|
|
102
|
+
url: new URL('ws://localhost:3000/clients/socket.io/123'),
|
|
103
|
+
}),
|
|
104
|
+
).toEqual({
|
|
105
|
+
match: {
|
|
106
|
+
matches: false,
|
|
107
|
+
params: {},
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('supports a custom resolution context (base url)', () => {
|
|
113
|
+
expect(
|
|
114
|
+
new WebSocketHandler('/api/ws').parse({
|
|
115
|
+
url: new URL('ws://localhost:3000/api/ws'),
|
|
116
|
+
resolutionContext: {
|
|
117
|
+
baseUrl: 'ws://localhost:3000/',
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
).toEqual({
|
|
121
|
+
match: {
|
|
122
|
+
matches: true,
|
|
123
|
+
params: {},
|
|
124
|
+
},
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
})
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { Emitter } from 'strict-event-emitter'
|
|
2
|
+
import { createRequestId, resolveWebSocketUrl } from '@mswjs/interceptors'
|
|
3
|
+
import type {
|
|
4
|
+
WebSocketClientConnectionProtocol,
|
|
5
|
+
WebSocketConnectionData,
|
|
6
|
+
WebSocketServerConnectionProtocol,
|
|
7
|
+
} from '@mswjs/interceptors/WebSocket'
|
|
8
|
+
import {
|
|
9
|
+
type Match,
|
|
10
|
+
type Path,
|
|
11
|
+
type PathParams,
|
|
12
|
+
matchRequestUrl,
|
|
13
|
+
} from '../utils/matching/matchRequestUrl'
|
|
14
|
+
import { getCallFrame } from '../utils/internal/getCallFrame'
|
|
15
|
+
import type { HandlerKind } from './common'
|
|
16
|
+
|
|
17
|
+
type WebSocketHandlerParsedResult = {
|
|
18
|
+
match: Match
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type WebSocketHandlerEventMap = {
|
|
22
|
+
connection: [args: WebSocketHandlerConnection]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface WebSocketHandlerConnection {
|
|
26
|
+
client: WebSocketClientConnectionProtocol
|
|
27
|
+
server: WebSocketServerConnectionProtocol
|
|
28
|
+
info: WebSocketConnectionData['info']
|
|
29
|
+
params: PathParams
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface WebSocketResolutionContext {
|
|
33
|
+
baseUrl?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const kEmitter = Symbol('kEmitter')
|
|
37
|
+
export const kSender = Symbol('kSender')
|
|
38
|
+
const kStopPropagationPatched = Symbol('kStopPropagationPatched')
|
|
39
|
+
const KOnStopPropagation = Symbol('KOnStopPropagation')
|
|
40
|
+
|
|
41
|
+
export class WebSocketHandler {
|
|
42
|
+
private readonly __kind: HandlerKind
|
|
43
|
+
|
|
44
|
+
public id: string
|
|
45
|
+
public callFrame?: string
|
|
46
|
+
|
|
47
|
+
protected [kEmitter]: Emitter<WebSocketHandlerEventMap>
|
|
48
|
+
|
|
49
|
+
constructor(protected readonly url: Path) {
|
|
50
|
+
this.id = createRequestId()
|
|
51
|
+
|
|
52
|
+
this[kEmitter] = new Emitter()
|
|
53
|
+
this.callFrame = getCallFrame(new Error())
|
|
54
|
+
this.__kind = 'EventHandler'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public parse(args: {
|
|
58
|
+
url: URL
|
|
59
|
+
resolutionContext?: WebSocketResolutionContext
|
|
60
|
+
}): WebSocketHandlerParsedResult {
|
|
61
|
+
const clientUrl = new URL(args.url)
|
|
62
|
+
|
|
63
|
+
// Resolve the WebSocket handler path:
|
|
64
|
+
// - Plain string URLs resolved as per the specification (via Interceptors).
|
|
65
|
+
// - String URLs starting with a wildcard are preserved (prepending a scheme there will break them).
|
|
66
|
+
// - RegExp paths are preserved.
|
|
67
|
+
const resolvedHandlerUrl =
|
|
68
|
+
this.url instanceof RegExp || this.url.startsWith('*')
|
|
69
|
+
? this.url
|
|
70
|
+
: this.#resolveWebSocketUrl(this.url, args.resolutionContext?.baseUrl)
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @note Remove the Socket.IO path prefix from the WebSocket
|
|
74
|
+
* client URL. This is an exception to keep the users from
|
|
75
|
+
* including the implementation details in their handlers.
|
|
76
|
+
*/
|
|
77
|
+
clientUrl.pathname = clientUrl.pathname.replace(/^\/socket.io\//, '/')
|
|
78
|
+
|
|
79
|
+
const match = matchRequestUrl(
|
|
80
|
+
clientUrl,
|
|
81
|
+
resolvedHandlerUrl,
|
|
82
|
+
args.resolutionContext?.baseUrl,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
match,
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public predicate(args: {
|
|
91
|
+
url: URL
|
|
92
|
+
parsedResult: WebSocketHandlerParsedResult
|
|
93
|
+
}): boolean {
|
|
94
|
+
return args.parsedResult.match.matches
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public async run(
|
|
98
|
+
connection: Omit<WebSocketHandlerConnection, 'params'>,
|
|
99
|
+
resolutionContext?: WebSocketResolutionContext,
|
|
100
|
+
): Promise<boolean> {
|
|
101
|
+
const parsedResult = this.parse({
|
|
102
|
+
url: connection.client.url,
|
|
103
|
+
resolutionContext,
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
if (!this.predicate({ url: connection.client.url, parsedResult })) {
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const resolvedConnection: WebSocketHandlerConnection = {
|
|
111
|
+
...connection,
|
|
112
|
+
params: parsedResult.match.params || {},
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return this.connect(resolvedConnection)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
protected connect(connection: WebSocketHandlerConnection): boolean {
|
|
119
|
+
// Support `event.stopPropagation()` for various client/server events.
|
|
120
|
+
connection.client.addEventListener(
|
|
121
|
+
'message',
|
|
122
|
+
createStopPropagationListener(this),
|
|
123
|
+
)
|
|
124
|
+
connection.client.addEventListener(
|
|
125
|
+
'close',
|
|
126
|
+
createStopPropagationListener(this),
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
connection.server.addEventListener(
|
|
130
|
+
'open',
|
|
131
|
+
createStopPropagationListener(this),
|
|
132
|
+
)
|
|
133
|
+
connection.server.addEventListener(
|
|
134
|
+
'message',
|
|
135
|
+
createStopPropagationListener(this),
|
|
136
|
+
)
|
|
137
|
+
connection.server.addEventListener(
|
|
138
|
+
'error',
|
|
139
|
+
createStopPropagationListener(this),
|
|
140
|
+
)
|
|
141
|
+
connection.server.addEventListener(
|
|
142
|
+
'close',
|
|
143
|
+
createStopPropagationListener(this),
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
// Emit the connection event on the handler.
|
|
147
|
+
// This is what the developer adds listeners for.
|
|
148
|
+
return this[kEmitter].emit('connection', connection)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
#resolveWebSocketUrl(url: string, baseUrl?: string): string {
|
|
152
|
+
const resolvedUrl = resolveWebSocketUrl(
|
|
153
|
+
baseUrl
|
|
154
|
+
? /**
|
|
155
|
+
* @note Resolve against the base URL preemtively because `resolveWebSocketUrl` only
|
|
156
|
+
* resolves against `location.href`, which is missing in Node.js. Base URL allows
|
|
157
|
+
* the handler to accept a relative URL in Node.js.
|
|
158
|
+
*/
|
|
159
|
+
new URL(url, baseUrl)
|
|
160
|
+
: url,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @note Omit the trailing slash.
|
|
165
|
+
* While the browser always produces a trailing slash at the end of a WebSocket URL,
|
|
166
|
+
* having it in as the handler's predicate would mean it is *required* in the actual URL.
|
|
167
|
+
*/
|
|
168
|
+
return resolvedUrl.replace(/\/$/, '')
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function createStopPropagationListener(handler: WebSocketHandler) {
|
|
173
|
+
return function stopPropagationListener(event: Event) {
|
|
174
|
+
const propagationStoppedAt = Reflect.get(event, 'kPropagationStoppedAt') as
|
|
175
|
+
| string
|
|
176
|
+
| undefined
|
|
177
|
+
|
|
178
|
+
if (propagationStoppedAt && handler.id !== propagationStoppedAt) {
|
|
179
|
+
event.stopImmediatePropagation()
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
Object.defineProperty(event, KOnStopPropagation, {
|
|
184
|
+
value(this: WebSocketHandler) {
|
|
185
|
+
Object.defineProperty(event, 'kPropagationStoppedAt', {
|
|
186
|
+
value: handler.id,
|
|
187
|
+
})
|
|
188
|
+
},
|
|
189
|
+
configurable: true,
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
// Since the same event instance is shared between all client/server objects,
|
|
193
|
+
// make sure to patch its `stopPropagation` method only once.
|
|
194
|
+
if (!Reflect.get(event, kStopPropagationPatched)) {
|
|
195
|
+
event.stopPropagation = new Proxy(event.stopPropagation, {
|
|
196
|
+
apply: (target, thisArg, args) => {
|
|
197
|
+
Reflect.get(event, KOnStopPropagation)?.call(handler)
|
|
198
|
+
return Reflect.apply(target, thisArg, args)
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
Object.defineProperty(event, kStopPropagationPatched, {
|
|
203
|
+
value: true,
|
|
204
|
+
// If something else attempts to redefine this, throw.
|
|
205
|
+
configurable: false,
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type HandlerKind = 'RequestHandler' | 'EventHandler'
|
package/src/core/http.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DefaultBodyType,
|
|
3
|
+
RequestHandlerOptions,
|
|
4
|
+
ResponseResolver,
|
|
5
|
+
} from './handlers/RequestHandler'
|
|
6
|
+
import {
|
|
7
|
+
HttpMethods,
|
|
8
|
+
HttpHandler,
|
|
9
|
+
HttpRequestResolverExtras,
|
|
10
|
+
HttpRequestPredicate,
|
|
11
|
+
} from './handlers/HttpHandler'
|
|
12
|
+
import type { PathParams } from './utils/matching/matchRequestUrl'
|
|
13
|
+
|
|
14
|
+
export type HttpRequestHandler = <
|
|
15
|
+
Params extends PathParams<keyof Params> = PathParams,
|
|
16
|
+
RequestBodyType extends DefaultBodyType = DefaultBodyType,
|
|
17
|
+
// Response body type MUST be undefined by default.
|
|
18
|
+
// This is how we can distinguish between a handler that
|
|
19
|
+
// returns plain "Response" and the one returning "HttpResponse"
|
|
20
|
+
// to enforce a stricter response body type.
|
|
21
|
+
ResponseBodyType extends DefaultBodyType = undefined,
|
|
22
|
+
>(
|
|
23
|
+
predicate: HttpRequestPredicate<Params>,
|
|
24
|
+
resolver: HttpResponseResolver<Params, RequestBodyType, ResponseBodyType>,
|
|
25
|
+
options?: RequestHandlerOptions,
|
|
26
|
+
) => HttpHandler
|
|
27
|
+
|
|
28
|
+
export type HttpResponseResolver<
|
|
29
|
+
Params extends PathParams<keyof Params> = PathParams,
|
|
30
|
+
RequestBodyType extends DefaultBodyType = DefaultBodyType,
|
|
31
|
+
ResponseBodyType extends DefaultBodyType = DefaultBodyType,
|
|
32
|
+
> = ResponseResolver<
|
|
33
|
+
HttpRequestResolverExtras<Params>,
|
|
34
|
+
RequestBodyType,
|
|
35
|
+
ResponseBodyType
|
|
36
|
+
>
|
|
37
|
+
|
|
38
|
+
function createHttpHandler<Method extends HttpMethods | RegExp>(
|
|
39
|
+
method: Method,
|
|
40
|
+
): HttpRequestHandler {
|
|
41
|
+
return (predicate, resolver, options = {}) => {
|
|
42
|
+
return new HttpHandler(method, predicate, resolver, options)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A namespace to intercept and mock HTTP requests.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* http.get('/user', resolver)
|
|
51
|
+
* http.post('/post/:id', resolver)
|
|
52
|
+
*
|
|
53
|
+
* @see {@link https://mswjs.io/docs/api/http `http` API reference}
|
|
54
|
+
*/
|
|
55
|
+
export const http = {
|
|
56
|
+
all: createHttpHandler(/.+/),
|
|
57
|
+
head: createHttpHandler(HttpMethods.HEAD),
|
|
58
|
+
get: createHttpHandler(HttpMethods.GET),
|
|
59
|
+
post: createHttpHandler(HttpMethods.POST),
|
|
60
|
+
put: createHttpHandler(HttpMethods.PUT),
|
|
61
|
+
delete: createHttpHandler(HttpMethods.DELETE),
|
|
62
|
+
patch: createHttpHandler(HttpMethods.PATCH),
|
|
63
|
+
options: createHttpHandler(HttpMethods.OPTIONS),
|
|
64
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { checkGlobals } from './utils/internal/checkGlobals'
|
|
2
|
+
|
|
3
|
+
export { SetupApi } from './SetupApi'
|
|
4
|
+
|
|
5
|
+
/* HTTP handlers */
|
|
6
|
+
export { RequestHandler } from './handlers/RequestHandler'
|
|
7
|
+
export { http } from './http'
|
|
8
|
+
export { HttpHandler, HttpMethods } from './handlers/HttpHandler'
|
|
9
|
+
export { graphql } from './graphql'
|
|
10
|
+
export { GraphQLHandler } from './handlers/GraphQLHandler'
|
|
11
|
+
|
|
12
|
+
/* WebSocket handler */
|
|
13
|
+
export { ws, type WebSocketLink } from './ws'
|
|
14
|
+
export {
|
|
15
|
+
WebSocketHandler,
|
|
16
|
+
type WebSocketHandlerEventMap,
|
|
17
|
+
type WebSocketHandlerConnection,
|
|
18
|
+
} from './handlers/WebSocketHandler'
|
|
19
|
+
|
|
20
|
+
/* Server-Sent Events */
|
|
21
|
+
export {
|
|
22
|
+
sse,
|
|
23
|
+
type ServerSentEventRequestHandler,
|
|
24
|
+
type ServerSentEventResolver,
|
|
25
|
+
type ServerSentEventResolverExtras,
|
|
26
|
+
type ServerSentEventMessage,
|
|
27
|
+
} from './sse'
|
|
28
|
+
|
|
29
|
+
import type { HttpHandler } from './handlers/HttpHandler'
|
|
30
|
+
import type { GraphQLHandler } from './handlers/GraphQLHandler'
|
|
31
|
+
import type { WebSocketHandler } from './handlers/WebSocketHandler'
|
|
32
|
+
|
|
33
|
+
export type AnyHandler = HttpHandler | GraphQLHandler | WebSocketHandler
|
|
34
|
+
|
|
35
|
+
/* Utils */
|
|
36
|
+
export { matchRequestUrl } from './utils/matching/matchRequestUrl'
|
|
37
|
+
export { handleRequest, type HandleRequestOptions } from './utils/handleRequest'
|
|
38
|
+
export {
|
|
39
|
+
onUnhandledRequest,
|
|
40
|
+
type UnhandledRequestStrategy,
|
|
41
|
+
type UnhandledRequestCallback,
|
|
42
|
+
} from './utils/request/onUnhandledRequest'
|
|
43
|
+
export { getResponse } from './getResponse'
|
|
44
|
+
export { cleanUrl } from './utils/url/cleanUrl'
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Type definitions.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
export type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'
|
|
51
|
+
|
|
52
|
+
export type {
|
|
53
|
+
ResponseResolver,
|
|
54
|
+
ResponseResolverReturnType,
|
|
55
|
+
AsyncResponseResolverReturnType,
|
|
56
|
+
RequestHandlerOptions,
|
|
57
|
+
DefaultBodyType,
|
|
58
|
+
DefaultRequestMultipartBody,
|
|
59
|
+
JsonBodyType,
|
|
60
|
+
ResponseResolverInfo,
|
|
61
|
+
} from './handlers/RequestHandler'
|
|
62
|
+
|
|
63
|
+
export type {
|
|
64
|
+
RequestQuery,
|
|
65
|
+
HttpRequestParsedResult,
|
|
66
|
+
HttpHandlerInfo,
|
|
67
|
+
HttpRequestResolverExtras,
|
|
68
|
+
HttpHandlerMethod,
|
|
69
|
+
HttpCustomPredicate,
|
|
70
|
+
} from './handlers/HttpHandler'
|
|
71
|
+
export type { HttpRequestHandler, HttpResponseResolver } from './http'
|
|
72
|
+
|
|
73
|
+
export type {
|
|
74
|
+
GraphQLQuery,
|
|
75
|
+
GraphQLVariables,
|
|
76
|
+
GraphQLRequestBody,
|
|
77
|
+
GraphQLResponseBody,
|
|
78
|
+
GraphQLJsonRequestBody,
|
|
79
|
+
GraphQLOperationType,
|
|
80
|
+
GraphQLCustomPredicate,
|
|
81
|
+
} from './handlers/GraphQLHandler'
|
|
82
|
+
export type {
|
|
83
|
+
GraphQLRequestHandler,
|
|
84
|
+
GraphQLOperationHandler,
|
|
85
|
+
GraphQLResponseResolver,
|
|
86
|
+
GraphQLLinkHandlers,
|
|
87
|
+
} from './graphql'
|
|
88
|
+
|
|
89
|
+
export type { WebSocketData, WebSocketEventListener } from './ws'
|
|
90
|
+
|
|
91
|
+
export type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'
|
|
92
|
+
export type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'
|
|
93
|
+
export type { ResponseResolutionContext } from './utils/executeHandlers'
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
HttpResponse,
|
|
97
|
+
type HttpResponseInit,
|
|
98
|
+
type StrictRequest,
|
|
99
|
+
type StrictResponse,
|
|
100
|
+
} from './HttpResponse'
|
|
101
|
+
export { delay, type DelayMode } from './delay'
|
|
102
|
+
export { bypass } from './bypass'
|
|
103
|
+
export { passthrough } from './passthrough'
|
|
104
|
+
export { isCommonAssetRequest } from './isCommonAssetRequest'
|
|
105
|
+
|
|
106
|
+
// Validate environmental globals before executing any code.
|
|
107
|
+
// This ensures that the library gives user-friendly errors
|
|
108
|
+
// when ran in the environments that require additional polyfills
|
|
109
|
+
// from the end user.
|
|
110
|
+
checkGlobals()
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if the given request is a static asset request.
|
|
3
|
+
* Useful when deciding which unhandled requests to ignore.
|
|
4
|
+
* @note Despite being ignored, you can still intercept and mock
|
|
5
|
+
* static assets by creating request handlers for them.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { isCommonAssetRequest } from 'msw'
|
|
9
|
+
*
|
|
10
|
+
* await worker.start({
|
|
11
|
+
* onUnhandledRequest(request, print) {
|
|
12
|
+
* if (!isCommonAssetRequest(request)) {
|
|
13
|
+
* print.warning()
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* })
|
|
17
|
+
*/
|
|
18
|
+
export function isCommonAssetRequest(request: Request): boolean {
|
|
19
|
+
const url = new URL(request.url)
|
|
20
|
+
|
|
21
|
+
// Ignore certain protocols.
|
|
22
|
+
if (url.protocol === 'file:') {
|
|
23
|
+
return true
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Ignore static assets hosts.
|
|
27
|
+
if (/(fonts\.googleapis\.com)/.test(url.hostname)) {
|
|
28
|
+
return true
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Ignore node modules served over HTTP.
|
|
32
|
+
if (/node_modules/.test(url.pathname)) {
|
|
33
|
+
return true
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Ignore internal Vite requests, like "/@vite/client".
|
|
37
|
+
if (url.pathname.includes('@vite')) {
|
|
38
|
+
return true
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Ignore common static assets.
|
|
42
|
+
return /\.(s?css|less|m?jsx?|m?tsx?|html|ttf|otf|woff|woff2|eot|gif|jpe?g|png|avif|webp|svg|mp4|webm|ogg|mov|mp3|wav|ogg|flac|aac|pdf|txt|csv|json|xml|md|zip|tar|gz|rar|7z)$/i.test(
|
|
43
|
+
url.pathname,
|
|
44
|
+
)
|
|
45
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { passthrough } from './passthrough'
|
|
3
|
+
|
|
4
|
+
it('creates a 302 response with the intention header', () => {
|
|
5
|
+
const response = passthrough()
|
|
6
|
+
|
|
7
|
+
expect(response).toBeInstanceOf(Response)
|
|
8
|
+
expect(response.status).toBe(302)
|
|
9
|
+
expect(response.statusText).toBe('Passthrough')
|
|
10
|
+
expect(response.headers.get('x-msw-intention')).toBe('passthrough')
|
|
11
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { HttpResponse } from './HttpResponse'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Performs the intercepted request as-is.
|
|
5
|
+
*
|
|
6
|
+
* This stops request handler lookup so no other handlers
|
|
7
|
+
* can affect this request past this point.
|
|
8
|
+
* Unlike `bypass()`, this will not trigger an additional request.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* http.get('/resource', () => {
|
|
12
|
+
* return passthrough()
|
|
13
|
+
* })
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://mswjs.io/docs/api/passthrough `passthrough()` API reference}
|
|
16
|
+
*/
|
|
17
|
+
export function passthrough(): HttpResponse<any> {
|
|
18
|
+
return new Response(null, {
|
|
19
|
+
status: 302,
|
|
20
|
+
statusText: 'Passthrough',
|
|
21
|
+
headers: {
|
|
22
|
+
'x-msw-intention': 'passthrough',
|
|
23
|
+
},
|
|
24
|
+
}) as HttpResponse<any>
|
|
25
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Emitter } from 'strict-event-emitter'
|
|
2
|
+
import type { UnhandledRequestStrategy } from './utils/request/onUnhandledRequest'
|
|
3
|
+
|
|
4
|
+
export interface SharedOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Specifies how to react to a request that has no corresponding
|
|
7
|
+
* request handler. Warns on unhandled requests by default.
|
|
8
|
+
*
|
|
9
|
+
* @example worker.start({ onUnhandledRequest: 'bypass' })
|
|
10
|
+
* @example worker.start({ onUnhandledRequest: 'warn' })
|
|
11
|
+
* @example server.listen({ onUnhandledRequest: 'error' })
|
|
12
|
+
*/
|
|
13
|
+
onUnhandledRequest?: UnhandledRequestStrategy
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type LifeCycleEventsMap = {
|
|
17
|
+
'request:start': [
|
|
18
|
+
args: {
|
|
19
|
+
request: Request
|
|
20
|
+
requestId: string
|
|
21
|
+
},
|
|
22
|
+
]
|
|
23
|
+
'request:match': [
|
|
24
|
+
args: {
|
|
25
|
+
request: Request
|
|
26
|
+
requestId: string
|
|
27
|
+
},
|
|
28
|
+
]
|
|
29
|
+
'request:unhandled': [
|
|
30
|
+
args: {
|
|
31
|
+
request: Request
|
|
32
|
+
requestId: string
|
|
33
|
+
},
|
|
34
|
+
]
|
|
35
|
+
'request:end': [
|
|
36
|
+
args: {
|
|
37
|
+
request: Request
|
|
38
|
+
requestId: string
|
|
39
|
+
},
|
|
40
|
+
]
|
|
41
|
+
'response:mocked': [
|
|
42
|
+
args: {
|
|
43
|
+
response: Response
|
|
44
|
+
request: Request
|
|
45
|
+
requestId: string
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
'response:bypass': [
|
|
49
|
+
args: {
|
|
50
|
+
response: Response
|
|
51
|
+
request: Request
|
|
52
|
+
requestId: string
|
|
53
|
+
},
|
|
54
|
+
]
|
|
55
|
+
unhandledException: [
|
|
56
|
+
args: {
|
|
57
|
+
error: Error
|
|
58
|
+
request: Request
|
|
59
|
+
requestId: string
|
|
60
|
+
},
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type LifeCycleEventEmitter<
|
|
65
|
+
EventsMap extends Record<string | symbol, any>,
|
|
66
|
+
> = Pick<Emitter<EventsMap>, 'on' | 'removeListener' | 'removeAllListeners'>
|