@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,97 @@
|
|
|
1
|
+
import { until } from 'until-async'
|
|
2
|
+
import { devUtils } from '~/core/utils/internal/devUtils'
|
|
3
|
+
import { getAbsoluteWorkerUrl } from '../../../utils/getAbsoluteWorkerUrl'
|
|
4
|
+
import { getWorkerByRegistration } from './getWorkerByRegistration'
|
|
5
|
+
import { ServiceWorkerInstanceTuple, FindWorker } from '../../glossary'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns an active Service Worker instance.
|
|
9
|
+
* When not found, registers a new Service Worker.
|
|
10
|
+
*/
|
|
11
|
+
export const getWorkerInstance = async (
|
|
12
|
+
url: string,
|
|
13
|
+
options: RegistrationOptions = {},
|
|
14
|
+
findWorker: FindWorker,
|
|
15
|
+
): Promise<ServiceWorkerInstanceTuple> => {
|
|
16
|
+
// Resolve the absolute Service Worker URL.
|
|
17
|
+
const absoluteWorkerUrl = getAbsoluteWorkerUrl(url)
|
|
18
|
+
|
|
19
|
+
const mockRegistrations = await navigator.serviceWorker
|
|
20
|
+
.getRegistrations()
|
|
21
|
+
.then((registrations) =>
|
|
22
|
+
registrations.filter((registration) =>
|
|
23
|
+
getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker),
|
|
24
|
+
),
|
|
25
|
+
)
|
|
26
|
+
if (!navigator.serviceWorker.controller && mockRegistrations.length > 0) {
|
|
27
|
+
// Reload the page when it has associated workers, but no active controller.
|
|
28
|
+
// The absence of a controller can mean either:
|
|
29
|
+
// - page has no Service Worker associated with it
|
|
30
|
+
// - page has been hard-reloaded and its workers won't be used until the next reload.
|
|
31
|
+
// Since we've checked that there are registrations associated with this page,
|
|
32
|
+
// at this point we are sure it's hard reload that falls into this clause.
|
|
33
|
+
location.reload()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const [existingRegistration] = mockRegistrations
|
|
37
|
+
|
|
38
|
+
if (existingRegistration) {
|
|
39
|
+
// Schedule the worker update in the background.
|
|
40
|
+
// Update ensures the existing worker is up-to-date.
|
|
41
|
+
existingRegistration.update()
|
|
42
|
+
|
|
43
|
+
// Return the worker reference immediately.
|
|
44
|
+
return [
|
|
45
|
+
getWorkerByRegistration(
|
|
46
|
+
existingRegistration,
|
|
47
|
+
absoluteWorkerUrl,
|
|
48
|
+
findWorker,
|
|
49
|
+
),
|
|
50
|
+
existingRegistration,
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// When the Service Worker wasn't found, register it anew and return the reference.
|
|
55
|
+
const [registrationError, registrationResult] = await until<
|
|
56
|
+
Error,
|
|
57
|
+
ServiceWorkerInstanceTuple
|
|
58
|
+
>(async () => {
|
|
59
|
+
const registration = await navigator.serviceWorker.register(url, options)
|
|
60
|
+
return [
|
|
61
|
+
// Compare existing worker registration by its worker URL,
|
|
62
|
+
// to prevent irrelevant workers to resolve here (such as Codesandbox worker).
|
|
63
|
+
getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker),
|
|
64
|
+
registration,
|
|
65
|
+
]
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Handle Service Worker registration errors.
|
|
69
|
+
if (registrationError) {
|
|
70
|
+
const isWorkerMissing = registrationError.message.includes('(404)')
|
|
71
|
+
|
|
72
|
+
// Produce a custom error message when given a non-existing Service Worker url.
|
|
73
|
+
// Suggest developers to check their setup.
|
|
74
|
+
if (isWorkerMissing) {
|
|
75
|
+
const scopeUrl = new URL(options?.scope || '/', location.href)
|
|
76
|
+
|
|
77
|
+
throw new Error(
|
|
78
|
+
devUtils.formatMessage(`\
|
|
79
|
+
Failed to register a Service Worker for scope ('${scopeUrl.href}') with script ('${absoluteWorkerUrl}'): Service Worker script does not exist at the given path.
|
|
80
|
+
|
|
81
|
+
Did you forget to run "npx msw init <PUBLIC_DIR>"?
|
|
82
|
+
|
|
83
|
+
Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/init`),
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Fallback error message for any other registration errors.
|
|
88
|
+
throw new Error(
|
|
89
|
+
devUtils.formatMessage(
|
|
90
|
+
'Failed to register the Service Worker:\n\n%s',
|
|
91
|
+
registrationError.message,
|
|
92
|
+
),
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return registrationResult
|
|
97
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { SetupWorkerInternalContext, StartOptions } from '../../glossary'
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_START_OPTIONS,
|
|
4
|
+
resolveStartOptions,
|
|
5
|
+
prepareStartHandler,
|
|
6
|
+
} from './prepareStartHandler'
|
|
7
|
+
|
|
8
|
+
describe('resolveStartOptions', () => {
|
|
9
|
+
test('returns default options given no custom start options', () => {
|
|
10
|
+
expect(resolveStartOptions()).toEqual(DEFAULT_START_OPTIONS)
|
|
11
|
+
expect(resolveStartOptions(undefined)).toEqual(DEFAULT_START_OPTIONS)
|
|
12
|
+
expect(resolveStartOptions({})).toEqual(DEFAULT_START_OPTIONS)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('deeply merges the default and custom start options', () => {
|
|
16
|
+
expect(
|
|
17
|
+
resolveStartOptions({
|
|
18
|
+
quiet: true,
|
|
19
|
+
serviceWorker: {
|
|
20
|
+
url: './custom.js',
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
).toEqual({
|
|
24
|
+
...DEFAULT_START_OPTIONS,
|
|
25
|
+
quiet: true,
|
|
26
|
+
serviceWorker: {
|
|
27
|
+
url: './custom.js',
|
|
28
|
+
options: null,
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('prepareStartHandler', () => {
|
|
35
|
+
test('exposes resolved start options to the generated star handler', () => {
|
|
36
|
+
const createStartHandler = vi.fn()
|
|
37
|
+
const context: SetupWorkerInternalContext = {} as any
|
|
38
|
+
const startHandler = prepareStartHandler(createStartHandler, context)
|
|
39
|
+
expect(startHandler).toBeInstanceOf(Function)
|
|
40
|
+
|
|
41
|
+
const initialOptions: StartOptions = {
|
|
42
|
+
quiet: true,
|
|
43
|
+
serviceWorker: {
|
|
44
|
+
url: './custom.js',
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
const resolvedOptions = resolveStartOptions(initialOptions)
|
|
48
|
+
startHandler(initialOptions)
|
|
49
|
+
|
|
50
|
+
// Calls the handler creator with both resolved and initial options.
|
|
51
|
+
expect(createStartHandler).toHaveBeenCalledWith(
|
|
52
|
+
resolvedOptions,
|
|
53
|
+
initialOptions,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
// Sets the resolved options on the internal context.
|
|
57
|
+
expect(context).toHaveProperty('startOptions', resolvedOptions)
|
|
58
|
+
})
|
|
59
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { RequiredDeep } from '~/core/typeUtils'
|
|
2
|
+
import { mergeRight } from '~/core/utils/internal/mergeRight'
|
|
3
|
+
import {
|
|
4
|
+
SetupWorker,
|
|
5
|
+
SetupWorkerInternalContext,
|
|
6
|
+
StartHandler,
|
|
7
|
+
StartOptions,
|
|
8
|
+
} from '../../glossary'
|
|
9
|
+
|
|
10
|
+
export const DEFAULT_START_OPTIONS: RequiredDeep<StartOptions> = {
|
|
11
|
+
serviceWorker: {
|
|
12
|
+
url: '/mockServiceWorker.js',
|
|
13
|
+
options: null as any,
|
|
14
|
+
},
|
|
15
|
+
quiet: false,
|
|
16
|
+
waitUntilReady: true,
|
|
17
|
+
onUnhandledRequest: 'warn',
|
|
18
|
+
findWorker(scriptURL, mockServiceWorkerUrl) {
|
|
19
|
+
return scriptURL === mockServiceWorkerUrl
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns resolved worker start options, merging the default options
|
|
25
|
+
* with the given custom options.
|
|
26
|
+
*/
|
|
27
|
+
export function resolveStartOptions(
|
|
28
|
+
initialOptions?: StartOptions,
|
|
29
|
+
): RequiredDeep<StartOptions> {
|
|
30
|
+
return mergeRight(
|
|
31
|
+
DEFAULT_START_OPTIONS,
|
|
32
|
+
initialOptions || {},
|
|
33
|
+
) as RequiredDeep<StartOptions>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function prepareStartHandler(
|
|
37
|
+
handler: StartHandler,
|
|
38
|
+
context: SetupWorkerInternalContext,
|
|
39
|
+
): SetupWorker['start'] {
|
|
40
|
+
return (initialOptions) => {
|
|
41
|
+
context.startOptions = resolveStartOptions(initialOptions)
|
|
42
|
+
return handler(context.startOptions, initialOptions || {})
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { printStartMessage } from './printStartMessage'
|
|
2
|
+
|
|
3
|
+
beforeEach(() => {
|
|
4
|
+
vi.spyOn(console, 'groupCollapsed').mockImplementation(() => void 0)
|
|
5
|
+
vi.spyOn(console, 'log').mockImplementation(() => void 0)
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
vi.restoreAllMocks()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test('prints out a default start message into console', () => {
|
|
13
|
+
printStartMessage({
|
|
14
|
+
workerScope: 'http://localhost:3000/',
|
|
15
|
+
workerUrl: 'http://localhost:3000/worker.js',
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
expect(console.groupCollapsed).toHaveBeenCalledWith(
|
|
19
|
+
'%c[MSW] Mocking enabled.',
|
|
20
|
+
expect.anything(),
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
// Includes a link to the documentation.
|
|
24
|
+
expect(console.log).toHaveBeenCalledWith(
|
|
25
|
+
'%cDocumentation: %chttps://mswjs.io/docs',
|
|
26
|
+
expect.anything(),
|
|
27
|
+
expect.anything(),
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
// Includes a link to the GitHub issues page.
|
|
31
|
+
expect(console.log).toHaveBeenCalledWith(
|
|
32
|
+
'Found an issue? https://github.com/mswjs/msw/issues',
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
// Includes service worker scope.
|
|
36
|
+
expect(console.log).toHaveBeenCalledWith(
|
|
37
|
+
'Worker scope:',
|
|
38
|
+
'http://localhost:3000/',
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
// Includes service worker script location.
|
|
42
|
+
expect(console.log).toHaveBeenCalledWith(
|
|
43
|
+
'Worker script URL:',
|
|
44
|
+
'http://localhost:3000/worker.js',
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('supports printing a custom start message', () => {
|
|
49
|
+
printStartMessage({ message: 'Custom start message' })
|
|
50
|
+
|
|
51
|
+
expect(console.groupCollapsed).toHaveBeenCalledWith(
|
|
52
|
+
'%c[MSW] Custom start message',
|
|
53
|
+
expect.anything(),
|
|
54
|
+
)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('does not print any messages when log level is quiet', () => {
|
|
58
|
+
printStartMessage({ quiet: true })
|
|
59
|
+
|
|
60
|
+
expect(console.groupCollapsed).not.toHaveBeenCalled()
|
|
61
|
+
expect(console.log).not.toHaveBeenCalled()
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('prints a worker scope in the start message', () => {
|
|
65
|
+
printStartMessage({
|
|
66
|
+
workerScope: 'http://localhost:3000/user',
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
expect(console.log).toHaveBeenCalledWith(
|
|
70
|
+
'Worker scope:',
|
|
71
|
+
'http://localhost:3000/user',
|
|
72
|
+
)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('prints a worker script url in the start message', () => {
|
|
76
|
+
printStartMessage({
|
|
77
|
+
workerUrl: 'http://localhost:3000/mockServiceWorker.js',
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
expect(console.log).toHaveBeenCalledWith(
|
|
81
|
+
'Worker script URL:',
|
|
82
|
+
'http://localhost:3000/mockServiceWorker.js',
|
|
83
|
+
)
|
|
84
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ServiceWorkerIncomingEventsMap } from '../../glossary'
|
|
2
|
+
import { devUtils } from '~/core/utils/internal/devUtils'
|
|
3
|
+
|
|
4
|
+
interface PrintStartMessageArgs {
|
|
5
|
+
quiet?: boolean
|
|
6
|
+
message?: string
|
|
7
|
+
workerUrl?: string
|
|
8
|
+
workerScope?: string
|
|
9
|
+
client?: ServiceWorkerIncomingEventsMap['MOCKING_ENABLED']['client']
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Prints a worker activation message in the browser's console.
|
|
14
|
+
*/
|
|
15
|
+
export function printStartMessage(args: PrintStartMessageArgs = {}) {
|
|
16
|
+
if (args.quiet) {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const message = args.message || 'Mocking enabled.'
|
|
21
|
+
|
|
22
|
+
console.groupCollapsed(
|
|
23
|
+
`%c${devUtils.formatMessage(message)}`,
|
|
24
|
+
'color:orangered;font-weight:bold;',
|
|
25
|
+
)
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
27
|
+
console.log(
|
|
28
|
+
'%cDocumentation: %chttps://mswjs.io/docs',
|
|
29
|
+
'font-weight:bold',
|
|
30
|
+
'font-weight:normal',
|
|
31
|
+
)
|
|
32
|
+
// eslint-disable-next-line no-console
|
|
33
|
+
console.log('Found an issue? https://github.com/mswjs/msw/issues')
|
|
34
|
+
|
|
35
|
+
if (args.workerUrl) {
|
|
36
|
+
// eslint-disable-next-line no-console
|
|
37
|
+
console.log('Worker script URL:', args.workerUrl)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (args.workerScope) {
|
|
41
|
+
// eslint-disable-next-line no-console
|
|
42
|
+
console.log('Worker scope:', args.workerScope)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (args.client) {
|
|
46
|
+
// eslint-disable-next-line no-console
|
|
47
|
+
console.log('Client ID: %s (%s)', args.client.id, args.client.frameType)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
console.groupEnd()
|
|
51
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { devUtils } from '~/core/utils/internal/devUtils'
|
|
2
|
+
import { StartOptions } from '../../glossary'
|
|
3
|
+
|
|
4
|
+
export function validateWorkerScope(
|
|
5
|
+
registration: ServiceWorkerRegistration,
|
|
6
|
+
options?: StartOptions,
|
|
7
|
+
): void {
|
|
8
|
+
if (!options?.quiet && !location.href.startsWith(registration.scope)) {
|
|
9
|
+
devUtils.warn(
|
|
10
|
+
`\
|
|
11
|
+
Cannot intercept requests on this page because it's outside of the worker's scope ("${registration.scope}"). If you wish to mock API requests on this page, you must resolve this scope issue.
|
|
12
|
+
|
|
13
|
+
- (Recommended) Register the worker at the root level ("/") of your application.
|
|
14
|
+
- Set the "Service-Worker-Allowed" response header to allow out-of-scope workers.\
|
|
15
|
+
`,
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { printStopMessage } from './printStopMessage'
|
|
2
|
+
|
|
3
|
+
beforeAll(() => {
|
|
4
|
+
vi.spyOn(global.console, 'log').mockImplementation(() => void 0)
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
vi.resetAllMocks()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
afterAll(() => {
|
|
12
|
+
vi.restoreAllMocks()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('prints a stop message to the console', () => {
|
|
16
|
+
printStopMessage()
|
|
17
|
+
expect(console.log).toHaveBeenCalledWith(
|
|
18
|
+
'%c[MSW] Mocking disabled.',
|
|
19
|
+
'color:orangered;font-weight:bold;',
|
|
20
|
+
)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('does not print any message when log level is quiet', () => {
|
|
24
|
+
printStopMessage({ quiet: true })
|
|
25
|
+
expect(console.log).not.toHaveBeenCalled()
|
|
26
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { devUtils } from '~/core/utils/internal/devUtils'
|
|
2
|
+
|
|
3
|
+
export function printStopMessage(args: { quiet?: boolean } = {}): void {
|
|
4
|
+
if (args.quiet) {
|
|
5
|
+
return
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line no-console
|
|
9
|
+
console.log(
|
|
10
|
+
`%c${devUtils.formatMessage('Mocking disabled.')}`,
|
|
11
|
+
'color:orangered;font-weight:bold;',
|
|
12
|
+
)
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig.src.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// Expose browser-specific libraries only for the
|
|
5
|
+
// source code under the "src/browser" directory.
|
|
6
|
+
"lib": ["DOM", "WebWorker", "DOM.Iterable"]
|
|
7
|
+
},
|
|
8
|
+
"include": ["../../global.d.ts", "./global.browser.d.ts", "./**/*.ts"]
|
|
9
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { devUtils } from '~/core/utils/internal/devUtils'
|
|
2
|
+
import type { SetupWorkerInternalContext } from '../setupWorker/glossary'
|
|
3
|
+
import { DeferredPromise } from '@open-draft/deferred-promise'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Check whether the registered Service Worker has been
|
|
7
|
+
* generated by the installed version of the library.
|
|
8
|
+
* Prints a warning message if the worker scripts mismatch.
|
|
9
|
+
*/
|
|
10
|
+
export function checkWorkerIntegrity(
|
|
11
|
+
context: SetupWorkerInternalContext,
|
|
12
|
+
): Promise<void> {
|
|
13
|
+
const integrityCheckPromise = new DeferredPromise<void>()
|
|
14
|
+
|
|
15
|
+
// Request the integrity checksum from the registered worker.
|
|
16
|
+
context.workerChannel.postMessage('INTEGRITY_CHECK_REQUEST')
|
|
17
|
+
context.workerChannel.once('INTEGRITY_CHECK_RESPONSE', (event) => {
|
|
18
|
+
const { checksum, packageVersion } = event.data
|
|
19
|
+
|
|
20
|
+
// Compare the response from the Service Worker and the
|
|
21
|
+
// global variable set during the build.
|
|
22
|
+
|
|
23
|
+
// The integrity is validated based on the worker script's checksum
|
|
24
|
+
// that's derived from its minified content during the build.
|
|
25
|
+
// The "SERVICE_WORKER_CHECKSUM" global variable is injected by the build.
|
|
26
|
+
if (checksum !== SERVICE_WORKER_CHECKSUM) {
|
|
27
|
+
devUtils.warn(
|
|
28
|
+
`The currently registered Service Worker has been generated by a different version of MSW (${packageVersion}) and may not be fully compatible with the installed version.
|
|
29
|
+
|
|
30
|
+
It's recommended you update your worker script by running this command:
|
|
31
|
+
|
|
32
|
+
\u2022 npx msw init <PUBLIC_DIR>
|
|
33
|
+
|
|
34
|
+
You can also automate this process and make the worker script update automatically upon the library installations. Read more: https://mswjs.io/docs/cli/init.`,
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
integrityCheckPromise.resolve()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return integrityCheckPromise
|
|
42
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { pruneGetRequestBody } from './pruneGetRequestBody'
|
|
2
|
+
import type { ServiceWorkerIncomingRequest } from '../setupWorker/glossary'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts a given request received from the Service Worker
|
|
6
|
+
* into a Fetch `Request` instance.
|
|
7
|
+
*/
|
|
8
|
+
export function deserializeRequest(
|
|
9
|
+
serializedRequest: ServiceWorkerIncomingRequest,
|
|
10
|
+
): Request {
|
|
11
|
+
return new Request(serializedRequest.url, {
|
|
12
|
+
...serializedRequest,
|
|
13
|
+
body: pruneGetRequestBody(serializedRequest),
|
|
14
|
+
})
|
|
15
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { getAbsoluteWorkerUrl } from './getAbsoluteWorkerUrl'
|
|
3
|
+
|
|
4
|
+
const rawLocation = window.location
|
|
5
|
+
|
|
6
|
+
afterAll(() => {
|
|
7
|
+
Object.defineProperty(window, 'location', {
|
|
8
|
+
value: rawLocation,
|
|
9
|
+
})
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('returns absolute worker url relatively to the root', () => {
|
|
13
|
+
expect(getAbsoluteWorkerUrl('./worker.js')).toBe('http://localhost/worker.js')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('returns an absolute worker url relatively to the current path', () => {
|
|
17
|
+
Object.defineProperty(window, 'location', {
|
|
18
|
+
value: {
|
|
19
|
+
href: 'http://localhost/path/to/page',
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
expect(getAbsoluteWorkerUrl('./worker.js')).toBe(
|
|
24
|
+
'http://localhost/path/to/worker.js',
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
// Leading slash must still resolve to the root.
|
|
28
|
+
expect(getAbsoluteWorkerUrl('/worker.js')).toBe('http://localhost/worker.js')
|
|
29
|
+
})
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { TextEncoder } from 'util'
|
|
5
|
+
import { pruneGetRequestBody } from './pruneGetRequestBody'
|
|
6
|
+
|
|
7
|
+
test('sets empty GET request body to undefined', () => {
|
|
8
|
+
expect(
|
|
9
|
+
pruneGetRequestBody({
|
|
10
|
+
method: 'GET',
|
|
11
|
+
}),
|
|
12
|
+
).toBeUndefined()
|
|
13
|
+
|
|
14
|
+
expect(
|
|
15
|
+
pruneGetRequestBody({
|
|
16
|
+
method: 'GET',
|
|
17
|
+
// There's no such thing as a GET request with a body.
|
|
18
|
+
body: new ArrayBuffer(5),
|
|
19
|
+
}),
|
|
20
|
+
).toBeUndefined()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('sets HEAD request body to undefined', () => {
|
|
24
|
+
expect(
|
|
25
|
+
pruneGetRequestBody({
|
|
26
|
+
method: 'HEAD',
|
|
27
|
+
}),
|
|
28
|
+
).toBeUndefined()
|
|
29
|
+
|
|
30
|
+
expect(
|
|
31
|
+
pruneGetRequestBody({
|
|
32
|
+
method: 'HEAD',
|
|
33
|
+
body: new ArrayBuffer(5),
|
|
34
|
+
}),
|
|
35
|
+
).toBeUndefined()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('ignores requests of the other methods than GET', () => {
|
|
39
|
+
const body = new TextEncoder().encode('hello world')
|
|
40
|
+
expect(
|
|
41
|
+
pruneGetRequestBody({
|
|
42
|
+
method: 'POST',
|
|
43
|
+
body,
|
|
44
|
+
}),
|
|
45
|
+
).toEqual(body)
|
|
46
|
+
|
|
47
|
+
expect(
|
|
48
|
+
pruneGetRequestBody({
|
|
49
|
+
method: 'PUT',
|
|
50
|
+
body,
|
|
51
|
+
}),
|
|
52
|
+
).toEqual(body)
|
|
53
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ServiceWorkerIncomingRequest } from '../setupWorker/glossary'
|
|
2
|
+
|
|
3
|
+
type Input = Pick<ServiceWorkerIncomingRequest, 'method' | 'body'>
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Ensures that an empty GET request body is always represented as `undefined`.
|
|
7
|
+
*/
|
|
8
|
+
export function pruneGetRequestBody(
|
|
9
|
+
request: Input,
|
|
10
|
+
): ServiceWorkerIncomingRequest['body'] {
|
|
11
|
+
// Force HEAD/GET request body to always be empty.
|
|
12
|
+
// The worker reads any request's body as ArrayBuffer,
|
|
13
|
+
// and you cannot re-construct a GET/HEAD Request
|
|
14
|
+
// with an ArrayBuffer, even if empty. Also note that
|
|
15
|
+
// "request.body" is always undefined in the worker.
|
|
16
|
+
if (['HEAD', 'GET'].includes(request.method)) {
|
|
17
|
+
return undefined
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return request.body
|
|
21
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the Service Worker API is supproted and available
|
|
3
|
+
* in the current browsing context.
|
|
4
|
+
*/
|
|
5
|
+
export function supportsServiceWorker(): boolean {
|
|
6
|
+
return (
|
|
7
|
+
typeof navigator !== 'undefined' &&
|
|
8
|
+
'serviceWorker' in navigator &&
|
|
9
|
+
typeof location !== 'undefined' &&
|
|
10
|
+
location.protocol !== 'file:'
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns a boolean indicating whether the current browser
|
|
16
|
+
* supports `ReadableStream` as a `Transferable` when posting
|
|
17
|
+
* messages.
|
|
18
|
+
*/
|
|
19
|
+
export function supportsReadableStreamTransfer() {
|
|
20
|
+
try {
|
|
21
|
+
const stream = new ReadableStream({
|
|
22
|
+
start: (controller) => controller.close(),
|
|
23
|
+
})
|
|
24
|
+
const message = new MessageChannel()
|
|
25
|
+
message.port1.postMessage(stream, [stream])
|
|
26
|
+
return true
|
|
27
|
+
} catch {
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
}
|