@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,248 @@
|
|
|
1
|
+
import { FetchResponse } from '@mswjs/interceptors'
|
|
2
|
+
import type { DefaultBodyType, JsonBodyType } from './handlers/RequestHandler'
|
|
3
|
+
import type { NoInfer } from './typeUtils'
|
|
4
|
+
import {
|
|
5
|
+
decorateResponse,
|
|
6
|
+
normalizeResponseInit,
|
|
7
|
+
} from './utils/HttpResponse/decorators'
|
|
8
|
+
|
|
9
|
+
export interface HttpResponseInit extends ResponseInit {
|
|
10
|
+
type?: ResponseType
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const bodyType: unique symbol = Symbol('bodyType')
|
|
14
|
+
export type DefaultUnsafeFetchResponse = Response & {
|
|
15
|
+
[bodyType]?: never
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface StrictRequest<BodyType extends JsonBodyType> extends Request {
|
|
19
|
+
json(): Promise<BodyType>
|
|
20
|
+
clone(): StrictRequest<BodyType>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Opaque `Response` type that supports strict body type.
|
|
25
|
+
*
|
|
26
|
+
* @deprecated Please use {@link HttpResponse} instead.
|
|
27
|
+
*/
|
|
28
|
+
export type StrictResponse<BodyType extends DefaultBodyType> =
|
|
29
|
+
HttpResponse<BodyType>
|
|
30
|
+
|
|
31
|
+
export const kDefaultContentType = Symbol.for('kDefaultContentType')
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A drop-in replacement for the standard `Response` class
|
|
35
|
+
* to allow additional features, like mocking the response `Set-Cookie` header.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* new HttpResponse('Hello world', { status: 201 })
|
|
39
|
+
* HttpResponse.json({ name: 'John' })
|
|
40
|
+
* HttpResponse.formData(form)
|
|
41
|
+
*
|
|
42
|
+
* @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}
|
|
43
|
+
*/
|
|
44
|
+
export class HttpResponse<
|
|
45
|
+
BodyType extends DefaultBodyType,
|
|
46
|
+
> extends FetchResponse {
|
|
47
|
+
readonly [bodyType]: BodyType = null as any
|
|
48
|
+
|
|
49
|
+
constructor(body?: NoInfer<BodyType> | null, init?: HttpResponseInit) {
|
|
50
|
+
const responseInit = normalizeResponseInit(init)
|
|
51
|
+
super(body as BodyInit, responseInit)
|
|
52
|
+
decorateResponse(this, responseInit)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static error(): HttpResponse<any> {
|
|
56
|
+
return super.error() as HttpResponse<any>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Create a `Response` with a `Content-Type: "text/plain"` body.
|
|
61
|
+
* @example
|
|
62
|
+
* HttpResponse.text('hello world')
|
|
63
|
+
* HttpResponse.text('Error', { status: 500 })
|
|
64
|
+
*/
|
|
65
|
+
static text<BodyType extends string>(
|
|
66
|
+
body?: NoInfer<BodyType> | null,
|
|
67
|
+
init?: HttpResponseInit,
|
|
68
|
+
): HttpResponse<BodyType> {
|
|
69
|
+
const responseInit = normalizeResponseInit(init)
|
|
70
|
+
const hasExplicitContentType = responseInit.headers.has('Content-Type')
|
|
71
|
+
|
|
72
|
+
if (!hasExplicitContentType) {
|
|
73
|
+
responseInit.headers.set('Content-Type', 'text/plain')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Automatically set the "Content-Length" response header
|
|
77
|
+
// for non-empty text responses. This enforces consistency and
|
|
78
|
+
// brings mocked responses closer to production.
|
|
79
|
+
if (!responseInit.headers.has('Content-Length')) {
|
|
80
|
+
responseInit.headers.set(
|
|
81
|
+
'Content-Length',
|
|
82
|
+
body ? new Blob([body]).size.toString() : '0',
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const response = new HttpResponse(body, responseInit)
|
|
87
|
+
|
|
88
|
+
if (!hasExplicitContentType) {
|
|
89
|
+
Object.defineProperty(response, kDefaultContentType, {
|
|
90
|
+
value: true,
|
|
91
|
+
enumerable: false,
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return response
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Create a `Response` with a `Content-Type: "application/json"` body.
|
|
100
|
+
* @example
|
|
101
|
+
* HttpResponse.json({ firstName: 'John' })
|
|
102
|
+
* HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })
|
|
103
|
+
*/
|
|
104
|
+
static json<BodyType extends JsonBodyType>(
|
|
105
|
+
body?: NoInfer<BodyType> | null | undefined,
|
|
106
|
+
init?: HttpResponseInit,
|
|
107
|
+
): HttpResponse<BodyType> {
|
|
108
|
+
const responseInit = normalizeResponseInit(init)
|
|
109
|
+
const hasExplicitContentType = responseInit.headers.has('Content-Type')
|
|
110
|
+
|
|
111
|
+
if (!hasExplicitContentType) {
|
|
112
|
+
responseInit.headers.set('Content-Type', 'application/json')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @note TypeScript is incorrect here.
|
|
117
|
+
* Stringifying undefined will return undefined.
|
|
118
|
+
*/
|
|
119
|
+
const responseText = JSON.stringify(body) as string | undefined
|
|
120
|
+
|
|
121
|
+
if (!responseInit.headers.has('Content-Length')) {
|
|
122
|
+
responseInit.headers.set(
|
|
123
|
+
'Content-Length',
|
|
124
|
+
responseText ? new Blob([responseText]).size.toString() : '0',
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const response = new HttpResponse(responseText, responseInit)
|
|
129
|
+
|
|
130
|
+
if (!hasExplicitContentType) {
|
|
131
|
+
Object.defineProperty(response, kDefaultContentType, {
|
|
132
|
+
value: true,
|
|
133
|
+
enumerable: false,
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return response as HttpResponse<BodyType>
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Create a `Response` with a `Content-Type: "application/xml"` body.
|
|
142
|
+
* @example
|
|
143
|
+
* HttpResponse.xml(`<user name="John" />`)
|
|
144
|
+
* HttpResponse.xml(`<article id="abc-123" />`, { status: 201 })
|
|
145
|
+
*/
|
|
146
|
+
static xml<BodyType extends string>(
|
|
147
|
+
body?: BodyType | null,
|
|
148
|
+
init?: HttpResponseInit,
|
|
149
|
+
): HttpResponse<BodyType> {
|
|
150
|
+
const responseInit = normalizeResponseInit(init)
|
|
151
|
+
const hasExplicitContentType = responseInit.headers.has('Content-Type')
|
|
152
|
+
|
|
153
|
+
if (!hasExplicitContentType) {
|
|
154
|
+
responseInit.headers.set('Content-Type', 'text/xml')
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const response = new HttpResponse(body, responseInit)
|
|
158
|
+
|
|
159
|
+
if (!hasExplicitContentType) {
|
|
160
|
+
Object.defineProperty(response, kDefaultContentType, {
|
|
161
|
+
value: true,
|
|
162
|
+
enumerable: false,
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return response as HttpResponse<BodyType>
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Create a `Response` with a `Content-Type: "text/html"` body.
|
|
171
|
+
* @example
|
|
172
|
+
* HttpResponse.html(`<p class="author">Jane Doe</p>`)
|
|
173
|
+
* HttpResponse.html(`<main id="abc-123">Main text</main>`, { status: 201 })
|
|
174
|
+
*/
|
|
175
|
+
static html<BodyType extends string>(
|
|
176
|
+
body?: BodyType | null,
|
|
177
|
+
init?: HttpResponseInit,
|
|
178
|
+
): HttpResponse<BodyType> {
|
|
179
|
+
const responseInit = normalizeResponseInit(init)
|
|
180
|
+
const hasExplicitContentType = responseInit.headers.has('Content-Type')
|
|
181
|
+
|
|
182
|
+
if (!hasExplicitContentType) {
|
|
183
|
+
responseInit.headers.set('Content-Type', 'text/html')
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const response = new HttpResponse(body, responseInit)
|
|
187
|
+
|
|
188
|
+
if (!hasExplicitContentType) {
|
|
189
|
+
Object.defineProperty(response, kDefaultContentType, {
|
|
190
|
+
value: true,
|
|
191
|
+
enumerable: false,
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return response as HttpResponse<BodyType>
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Create a `Response` with an `ArrayBuffer` body.
|
|
200
|
+
* @example
|
|
201
|
+
* const buffer = new ArrayBuffer(3)
|
|
202
|
+
* const view = new Uint8Array(buffer)
|
|
203
|
+
* view.set([1, 2, 3])
|
|
204
|
+
*
|
|
205
|
+
* HttpResponse.arrayBuffer(buffer)
|
|
206
|
+
*/
|
|
207
|
+
static arrayBuffer<BodyType extends ArrayBuffer | SharedArrayBuffer>(
|
|
208
|
+
body?: BodyType,
|
|
209
|
+
init?: HttpResponseInit,
|
|
210
|
+
): HttpResponse<BodyType> {
|
|
211
|
+
const responseInit = normalizeResponseInit(init)
|
|
212
|
+
const hasExplicitContentType = responseInit.headers.has('Content-Type')
|
|
213
|
+
|
|
214
|
+
if (!hasExplicitContentType) {
|
|
215
|
+
responseInit.headers.set('Content-Type', 'application/octet-stream')
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (body && !responseInit.headers.has('Content-Length')) {
|
|
219
|
+
responseInit.headers.set('Content-Length', body.byteLength.toString())
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const response = new HttpResponse(body, responseInit)
|
|
223
|
+
|
|
224
|
+
if (!hasExplicitContentType) {
|
|
225
|
+
Object.defineProperty(response, kDefaultContentType, {
|
|
226
|
+
value: true,
|
|
227
|
+
enumerable: false,
|
|
228
|
+
})
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return response as HttpResponse<BodyType>
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Create a `Response` with a `FormData` body.
|
|
236
|
+
* @example
|
|
237
|
+
* const data = new FormData()
|
|
238
|
+
* data.set('name', 'Alice')
|
|
239
|
+
*
|
|
240
|
+
* HttpResponse.formData(data)
|
|
241
|
+
*/
|
|
242
|
+
static formData(
|
|
243
|
+
body?: FormData,
|
|
244
|
+
init?: HttpResponseInit,
|
|
245
|
+
): HttpResponse<FormData> {
|
|
246
|
+
return new HttpResponse(body, normalizeResponseInit(init))
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { invariant } from 'outvariant'
|
|
2
|
+
import { EventMap, Emitter } from 'strict-event-emitter'
|
|
3
|
+
import { RequestHandler } from './handlers/RequestHandler'
|
|
4
|
+
import { LifeCycleEventEmitter } from './sharedOptions'
|
|
5
|
+
import { devUtils } from './utils/internal/devUtils'
|
|
6
|
+
import { pipeEvents } from './utils/internal/pipeEvents'
|
|
7
|
+
import { toReadonlyArray } from './utils/internal/toReadonlyArray'
|
|
8
|
+
import { Disposable } from './utils/internal/Disposable'
|
|
9
|
+
import type { WebSocketHandler } from './handlers/WebSocketHandler'
|
|
10
|
+
|
|
11
|
+
export abstract class HandlersController {
|
|
12
|
+
abstract prepend(
|
|
13
|
+
runtimeHandlers: Array<RequestHandler | WebSocketHandler>,
|
|
14
|
+
): void
|
|
15
|
+
abstract reset(nextHandles: Array<RequestHandler | WebSocketHandler>): void
|
|
16
|
+
abstract currentHandlers(): Array<RequestHandler | WebSocketHandler>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class InMemoryHandlersController implements HandlersController {
|
|
20
|
+
private handlers: Array<RequestHandler | WebSocketHandler>
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
private initialHandlers: Array<RequestHandler | WebSocketHandler>,
|
|
24
|
+
) {
|
|
25
|
+
this.handlers = [...initialHandlers]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public prepend(
|
|
29
|
+
runtimeHandles: Array<RequestHandler | WebSocketHandler>,
|
|
30
|
+
): void {
|
|
31
|
+
this.handlers.unshift(...runtimeHandles)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public reset(nextHandlers: Array<RequestHandler | WebSocketHandler>): void {
|
|
35
|
+
this.handlers =
|
|
36
|
+
nextHandlers.length > 0 ? [...nextHandlers] : [...this.initialHandlers]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public currentHandlers(): Array<RequestHandler | WebSocketHandler> {
|
|
40
|
+
return this.handlers
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Generic class for the mock API setup.
|
|
46
|
+
*/
|
|
47
|
+
export abstract class SetupApi<EventsMap extends EventMap> extends Disposable {
|
|
48
|
+
protected handlersController: HandlersController
|
|
49
|
+
protected readonly emitter: Emitter<EventsMap>
|
|
50
|
+
protected readonly publicEmitter: Emitter<EventsMap>
|
|
51
|
+
|
|
52
|
+
public readonly events: LifeCycleEventEmitter<EventsMap>
|
|
53
|
+
|
|
54
|
+
constructor(...initialHandlers: Array<RequestHandler | WebSocketHandler>) {
|
|
55
|
+
super()
|
|
56
|
+
|
|
57
|
+
invariant(
|
|
58
|
+
this.validateHandlers(initialHandlers),
|
|
59
|
+
devUtils.formatMessage(
|
|
60
|
+
`Failed to apply given request handlers: invalid input. Did you forget to spread the request handlers Array?`,
|
|
61
|
+
),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
this.handlersController = new InMemoryHandlersController(initialHandlers)
|
|
65
|
+
|
|
66
|
+
this.emitter = new Emitter<EventsMap>()
|
|
67
|
+
this.publicEmitter = new Emitter<EventsMap>()
|
|
68
|
+
pipeEvents(this.emitter, this.publicEmitter)
|
|
69
|
+
|
|
70
|
+
this.events = this.createLifeCycleEvents()
|
|
71
|
+
|
|
72
|
+
this.subscriptions.push(() => {
|
|
73
|
+
this.emitter.removeAllListeners()
|
|
74
|
+
this.publicEmitter.removeAllListeners()
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private validateHandlers(handlers: ReadonlyArray<unknown>): boolean {
|
|
79
|
+
// Guard against incorrect call signature of the setup API.
|
|
80
|
+
return handlers.every((handler) => !Array.isArray(handler))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public use(
|
|
84
|
+
...runtimeHandlers: Array<RequestHandler | WebSocketHandler>
|
|
85
|
+
): void {
|
|
86
|
+
invariant(
|
|
87
|
+
this.validateHandlers(runtimeHandlers),
|
|
88
|
+
devUtils.formatMessage(
|
|
89
|
+
`Failed to call "use()" with the given request handlers: invalid input. Did you forget to spread the array of request handlers?`,
|
|
90
|
+
),
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
this.handlersController.prepend(runtimeHandlers)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public restoreHandlers(): void {
|
|
97
|
+
this.handlersController.currentHandlers().forEach((handler) => {
|
|
98
|
+
if ('isUsed' in handler) {
|
|
99
|
+
handler.isUsed = false
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public resetHandlers(
|
|
105
|
+
...nextHandlers: Array<RequestHandler | WebSocketHandler>
|
|
106
|
+
): void {
|
|
107
|
+
this.handlersController.reset(nextHandlers)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler> {
|
|
111
|
+
return toReadonlyArray(this.handlersController.currentHandlers())
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private createLifeCycleEvents(): LifeCycleEventEmitter<EventsMap> {
|
|
115
|
+
return {
|
|
116
|
+
on: (...args: any[]) => {
|
|
117
|
+
return (this.publicEmitter.on as any)(...args)
|
|
118
|
+
},
|
|
119
|
+
removeListener: (...args: any[]) => {
|
|
120
|
+
return (this.publicEmitter.removeListener as any)(...args)
|
|
121
|
+
},
|
|
122
|
+
removeAllListeners: (...args: any[]) => {
|
|
123
|
+
return this.publicEmitter.removeAllListeners(...args)
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { bypass } from './bypass'
|
|
5
|
+
|
|
6
|
+
it('returns bypassed request given a request url string', async () => {
|
|
7
|
+
const request = bypass('https://api.example.com/resource')
|
|
8
|
+
|
|
9
|
+
// Relative URLs are rebased against the current location.
|
|
10
|
+
expect(request.method).toBe('GET')
|
|
11
|
+
expect(request.url).toBe('https://api.example.com/resource')
|
|
12
|
+
expect(Array.from(request.headers)).toEqual([['accept', 'msw/passthrough']])
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('returns bypassed request given a request url', async () => {
|
|
16
|
+
const request = bypass(new URL('/resource', 'https://api.example.com'))
|
|
17
|
+
|
|
18
|
+
expect(request.url).toBe('https://api.example.com/resource')
|
|
19
|
+
expect(Array.from(request.headers)).toEqual([['accept', 'msw/passthrough']])
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('returns bypassed request given request instance', async () => {
|
|
23
|
+
const original = new Request('http://localhost/resource', {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
headers: {
|
|
26
|
+
accept: '*/*',
|
|
27
|
+
'X-My-Header': 'value',
|
|
28
|
+
},
|
|
29
|
+
body: 'hello world',
|
|
30
|
+
})
|
|
31
|
+
const request = bypass(original)
|
|
32
|
+
|
|
33
|
+
expect(request.method).toBe('POST')
|
|
34
|
+
expect(request.url).toBe('http://localhost/resource')
|
|
35
|
+
|
|
36
|
+
const bypassedRequestBody = await request.text()
|
|
37
|
+
expect(original.bodyUsed).toBe(false)
|
|
38
|
+
|
|
39
|
+
expect(bypassedRequestBody).toEqual(await original.text())
|
|
40
|
+
expect(Array.from(request.headers)).toEqual([
|
|
41
|
+
['accept', '*/*, msw/passthrough'],
|
|
42
|
+
['content-type', 'text/plain;charset=UTF-8'],
|
|
43
|
+
['x-my-header', 'value'],
|
|
44
|
+
])
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('allows modifying the bypassed request instance', async () => {
|
|
48
|
+
const original = new Request('http://localhost/resource', {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
body: 'hello world',
|
|
51
|
+
})
|
|
52
|
+
const request = bypass(original, {
|
|
53
|
+
method: 'PUT',
|
|
54
|
+
headers: { 'x-modified-header': 'yes' },
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
expect(request.method).toBe('PUT')
|
|
58
|
+
expect(Array.from(request.headers)).toEqual([
|
|
59
|
+
['accept', 'msw/passthrough'],
|
|
60
|
+
['x-modified-header', 'yes'],
|
|
61
|
+
])
|
|
62
|
+
expect(original.bodyUsed).toBe(false)
|
|
63
|
+
expect(request.bodyUsed).toBe(false)
|
|
64
|
+
|
|
65
|
+
expect(await request.text()).toBe('hello world')
|
|
66
|
+
expect(original.bodyUsed).toBe(false)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('supports bypassing "keepalive: true" requests', async () => {
|
|
70
|
+
const original = new Request('http://localhost/resource', {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
keepalive: true,
|
|
73
|
+
})
|
|
74
|
+
const request = bypass(original)
|
|
75
|
+
|
|
76
|
+
expect(request.method).toBe('POST')
|
|
77
|
+
expect(request.url).toBe('http://localhost/resource')
|
|
78
|
+
expect(request.body).toBeNull()
|
|
79
|
+
expect(Array.from(request.headers)).toEqual([['accept', 'msw/passthrough']])
|
|
80
|
+
})
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { invariant } from 'outvariant'
|
|
2
|
+
|
|
3
|
+
export type BypassRequestInput = string | URL | Request
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a `Request` instance that will always be ignored by MSW.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* import { bypass } from 'msw'
|
|
10
|
+
*
|
|
11
|
+
* fetch(bypass('/resource'))
|
|
12
|
+
* fetch(bypass(new URL('/resource', 'https://example.com)))
|
|
13
|
+
* fetch(bypass(new Request('https://example.com/resource')))
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://mswjs.io/docs/api/bypass `bypass()` API reference}
|
|
16
|
+
*/
|
|
17
|
+
export function bypass(input: BypassRequestInput, init?: RequestInit): Request {
|
|
18
|
+
// Always create a new Request instance.
|
|
19
|
+
// This way, the "init" modifications will propagate
|
|
20
|
+
// to the bypass request instance automatically.
|
|
21
|
+
const request = new Request(
|
|
22
|
+
// If given a Request instance, clone it not to exhaust
|
|
23
|
+
// the original request's body.
|
|
24
|
+
input instanceof Request ? input.clone() : input,
|
|
25
|
+
init,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
invariant(
|
|
29
|
+
!request.bodyUsed,
|
|
30
|
+
'Failed to create a bypassed request to "%s %s": given request instance already has its body read. Make sure to clone the intercepted request if you wish to read its body before bypassing it.',
|
|
31
|
+
request.method,
|
|
32
|
+
request.url,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const requestClone = request.clone()
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Send the internal request header that would instruct MSW
|
|
39
|
+
* to perform this request as-is, ignoring any matching handlers.
|
|
40
|
+
* @note Use the `accept` header to support scenarios when the
|
|
41
|
+
* request cannot have headers (e.g. `sendBeacon` requests).
|
|
42
|
+
*/
|
|
43
|
+
requestClone.headers.append('accept', 'msw/passthrough')
|
|
44
|
+
|
|
45
|
+
return requestClone
|
|
46
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { isNodeProcess } from 'is-node-process'
|
|
2
|
+
import { hasRefCounted } from './utils/internal/hasRefCounted'
|
|
3
|
+
|
|
4
|
+
export const SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647
|
|
5
|
+
export const MIN_SERVER_RESPONSE_TIME = 100
|
|
6
|
+
export const MAX_SERVER_RESPONSE_TIME = 400
|
|
7
|
+
export const NODE_SERVER_RESPONSE_TIME = 5
|
|
8
|
+
|
|
9
|
+
function getRealisticResponseTime(): number {
|
|
10
|
+
if (isNodeProcess()) {
|
|
11
|
+
return NODE_SERVER_RESPONSE_TIME
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return Math.floor(
|
|
15
|
+
Math.random() * (MAX_SERVER_RESPONSE_TIME - MIN_SERVER_RESPONSE_TIME) +
|
|
16
|
+
MIN_SERVER_RESPONSE_TIME,
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type DelayMode = 'real' | 'infinite'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Delays the response by the given duration (ms).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* await delay() // emulate realistic server response time
|
|
27
|
+
* await delay(1200) // delay response by 1200ms
|
|
28
|
+
* await delay('infinite') // delay response infinitely
|
|
29
|
+
*
|
|
30
|
+
* @see {@link https://mswjs.io/docs/api/delay `delay()` API reference}
|
|
31
|
+
*/
|
|
32
|
+
export async function delay(
|
|
33
|
+
durationOrMode?: DelayMode | number,
|
|
34
|
+
): Promise<void> {
|
|
35
|
+
let delayTime: number
|
|
36
|
+
|
|
37
|
+
if (typeof durationOrMode === 'string') {
|
|
38
|
+
switch (durationOrMode) {
|
|
39
|
+
case 'infinite': {
|
|
40
|
+
// Using `Infinity` as a delay value executes the response timeout immediately.
|
|
41
|
+
// Instead, use the maximum allowed integer for `setTimeout`.
|
|
42
|
+
delayTime = SET_TIMEOUT_MAX_ALLOWED_INT
|
|
43
|
+
break
|
|
44
|
+
}
|
|
45
|
+
case 'real': {
|
|
46
|
+
delayTime = getRealisticResponseTime()
|
|
47
|
+
break
|
|
48
|
+
}
|
|
49
|
+
default: {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Failed to delay a response: unknown delay mode "${durationOrMode}". Please make sure you provide one of the supported modes ("real", "infinite") or a number.`,
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} else if (typeof durationOrMode === 'undefined') {
|
|
56
|
+
// Use random realistic server response time when no explicit delay duration was provided.
|
|
57
|
+
delayTime = getRealisticResponseTime()
|
|
58
|
+
} else {
|
|
59
|
+
// Guard against passing values like `Infinity` or `Number.MAX_VALUE`
|
|
60
|
+
// as the response delay duration. They don't produce the result you may expect.
|
|
61
|
+
if (durationOrMode > SET_TIMEOUT_MAX_ALLOWED_INT) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`Failed to delay a response: provided delay duration (${durationOrMode}) exceeds the maximum allowed duration for "setTimeout" (${SET_TIMEOUT_MAX_ALLOWED_INT}). This will cause the response to be returned immediately. Please use a number within the allowed range to delay the response by exact duration, or consider the "infinite" delay mode to delay the response indefinitely.`,
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
delayTime = durationOrMode
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return new Promise((resolve) => {
|
|
71
|
+
const timeoutId = setTimeout(resolve, delayTime)
|
|
72
|
+
|
|
73
|
+
if (
|
|
74
|
+
delayTime === SET_TIMEOUT_MAX_ALLOWED_INT &&
|
|
75
|
+
isNodeProcess() &&
|
|
76
|
+
hasRefCounted(timeoutId)
|
|
77
|
+
) {
|
|
78
|
+
// Prevent the process from hanging if this is the only active ref.
|
|
79
|
+
timeoutId.unref()
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { http } from './http'
|
|
3
|
+
import { getResponse } from './getResponse'
|
|
4
|
+
|
|
5
|
+
it('returns undefined given empty headers array', async () => {
|
|
6
|
+
await expect(
|
|
7
|
+
getResponse([], new Request('http://localhost/')),
|
|
8
|
+
).resolves.toBeUndefined()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('returns undefined given no matching handlers', async () => {
|
|
12
|
+
await expect(
|
|
13
|
+
getResponse(
|
|
14
|
+
[http.get('/product', () => void 0)],
|
|
15
|
+
new Request('http://localhost/user'),
|
|
16
|
+
),
|
|
17
|
+
).resolves.toBeUndefined()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('returns undefined given a matching handler that returned no response', async () => {
|
|
21
|
+
await expect(
|
|
22
|
+
getResponse(
|
|
23
|
+
[http.get('*/user', () => void 0)],
|
|
24
|
+
new Request('http://localhost/user'),
|
|
25
|
+
),
|
|
26
|
+
).resolves.toBeUndefined()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('returns undefined given a matching handler that returned explicit undefined', async () => {
|
|
30
|
+
await expect(
|
|
31
|
+
getResponse(
|
|
32
|
+
[http.get('*/user', () => undefined)],
|
|
33
|
+
new Request('http://localhost/user'),
|
|
34
|
+
),
|
|
35
|
+
).resolves.toBeUndefined()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('returns the response returned from a matching handler', async () => {
|
|
39
|
+
const response = await getResponse(
|
|
40
|
+
[http.get('*/user', () => Response.json({ name: 'John' }))],
|
|
41
|
+
new Request('http://localhost/user'),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
expect(response?.status).toBe(200)
|
|
45
|
+
expect(response?.headers.get('Content-Type')).toBe('application/json')
|
|
46
|
+
await expect(response?.json()).resolves.toEqual({ name: 'John' })
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('returns the response from the first matching handler if multiple match', async () => {
|
|
50
|
+
const response = await getResponse(
|
|
51
|
+
[
|
|
52
|
+
http.get('*/user', () => Response.json({ name: 'John' })),
|
|
53
|
+
http.get('*/user', () => Response.json({ name: 'Kate' })),
|
|
54
|
+
],
|
|
55
|
+
new Request('http://localhost/user'),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
expect(response?.status).toBe(200)
|
|
59
|
+
expect(response?.headers.get('Content-Type')).toBe('application/json')
|
|
60
|
+
await expect(response?.json()).resolves.toEqual({ name: 'John' })
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('supports custom base url', async () => {
|
|
64
|
+
const response = await getResponse(
|
|
65
|
+
[http.get('/resource', () => new Response('hello world'))],
|
|
66
|
+
new Request('https://localhost:3000/resource'),
|
|
67
|
+
{
|
|
68
|
+
baseUrl: 'https://localhost:3000/',
|
|
69
|
+
},
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
expect(response?.status).toBe(200)
|
|
73
|
+
await expect(response?.text()).resolves.toBe('hello world')
|
|
74
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createRequestId } from '@mswjs/interceptors'
|
|
2
|
+
import type { RequestHandler } from './handlers/RequestHandler'
|
|
3
|
+
import {
|
|
4
|
+
executeHandlers,
|
|
5
|
+
type ResponseResolutionContext,
|
|
6
|
+
} from './utils/executeHandlers'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Finds a response for the given request instance
|
|
10
|
+
* in the array of request handlers.
|
|
11
|
+
* @param handlers The array of request handlers.
|
|
12
|
+
* @param request The `Request` instance.
|
|
13
|
+
* @param resolutionContext Request resolution options.
|
|
14
|
+
* @returns {Response} A mocked response, if any.
|
|
15
|
+
*/
|
|
16
|
+
export const getResponse = async (
|
|
17
|
+
handlers: Array<RequestHandler>,
|
|
18
|
+
request: Request,
|
|
19
|
+
resolutionContext?: ResponseResolutionContext,
|
|
20
|
+
): Promise<Response | undefined> => {
|
|
21
|
+
const result = await executeHandlers({
|
|
22
|
+
request,
|
|
23
|
+
requestId: createRequestId(),
|
|
24
|
+
handlers,
|
|
25
|
+
resolutionContext,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
return result?.response
|
|
29
|
+
}
|