msw 2.1.3 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/index.js +1757 -27
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +1751 -23
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/sharedOptions.d.mts +0 -2
- package/lib/core/sharedOptions.d.ts +0 -2
- package/lib/core/utils/handleRequest.js +1 -1
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs +1 -1
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.d.mts +1 -4
- package/lib/core/utils/request/onUnhandledRequest.d.ts +1 -4
- package/lib/core/utils/request/onUnhandledRequest.js +9 -114
- package/lib/core/utils/request/onUnhandledRequest.js.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.mjs +9 -106
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -1
- package/lib/iife/index.js +10 -213
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +1 -4
- package/src/core/utils/handleRequest.ts +1 -1
- package/src/core/utils/request/onUnhandledRequest.test.ts +5 -101
- package/src/core/utils/request/onUnhandledRequest.ts +3 -184
package/lib/iife/index.js
CHANGED
|
@@ -5633,222 +5633,19 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5633
5633
|
return null;
|
|
5634
5634
|
};
|
|
5635
5635
|
|
|
5636
|
-
// node_modules/.pnpm/@bundled-es-modules+js-levenshtein@2.0.1/node_modules/@bundled-es-modules/js-levenshtein/index-esm.js
|
|
5637
|
-
var __create5 = Object.create;
|
|
5638
|
-
var __defProp7 = Object.defineProperty;
|
|
5639
|
-
var __getOwnPropDesc6 = Object.getOwnPropertyDescriptor;
|
|
5640
|
-
var __getOwnPropNames6 = Object.getOwnPropertyNames;
|
|
5641
|
-
var __getProtoOf5 = Object.getPrototypeOf;
|
|
5642
|
-
var __hasOwnProp6 = Object.prototype.hasOwnProperty;
|
|
5643
|
-
var __commonJS5 = (cb, mod) => function __require() {
|
|
5644
|
-
return mod || (0, cb[__getOwnPropNames6(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
5645
|
-
};
|
|
5646
|
-
var __copyProps6 = (to, from, except, desc) => {
|
|
5647
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
5648
|
-
for (let key of __getOwnPropNames6(from))
|
|
5649
|
-
if (!__hasOwnProp6.call(to, key) && key !== except)
|
|
5650
|
-
__defProp7(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc6(from, key)) || desc.enumerable });
|
|
5651
|
-
}
|
|
5652
|
-
return to;
|
|
5653
|
-
};
|
|
5654
|
-
var __toESM5 = (mod, isNodeMode, target) => (target = mod != null ? __create5(__getProtoOf5(mod)) : {}, __copyProps6(
|
|
5655
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
5656
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
5657
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
5658
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
5659
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp7(target, "default", { value: mod, enumerable: true }) : target,
|
|
5660
|
-
mod
|
|
5661
|
-
));
|
|
5662
|
-
var require_js_levenshtein = __commonJS5({
|
|
5663
|
-
"node_modules/js-levenshtein/index.js"(exports, module) {
|
|
5664
|
-
"use strict";
|
|
5665
|
-
module.exports = /* @__PURE__ */ function() {
|
|
5666
|
-
function _min(d0, d1, d2, bx, ay) {
|
|
5667
|
-
return d0 < d1 || d2 < d1 ? d0 > d2 ? d2 + 1 : d0 + 1 : bx === ay ? d1 : d1 + 1;
|
|
5668
|
-
}
|
|
5669
|
-
return function(a, b) {
|
|
5670
|
-
if (a === b) {
|
|
5671
|
-
return 0;
|
|
5672
|
-
}
|
|
5673
|
-
if (a.length > b.length) {
|
|
5674
|
-
var tmp = a;
|
|
5675
|
-
a = b;
|
|
5676
|
-
b = tmp;
|
|
5677
|
-
}
|
|
5678
|
-
var la = a.length;
|
|
5679
|
-
var lb = b.length;
|
|
5680
|
-
while (la > 0 && a.charCodeAt(la - 1) === b.charCodeAt(lb - 1)) {
|
|
5681
|
-
la--;
|
|
5682
|
-
lb--;
|
|
5683
|
-
}
|
|
5684
|
-
var offset = 0;
|
|
5685
|
-
while (offset < la && a.charCodeAt(offset) === b.charCodeAt(offset)) {
|
|
5686
|
-
offset++;
|
|
5687
|
-
}
|
|
5688
|
-
la -= offset;
|
|
5689
|
-
lb -= offset;
|
|
5690
|
-
if (la === 0 || lb < 3) {
|
|
5691
|
-
return lb;
|
|
5692
|
-
}
|
|
5693
|
-
var x = 0;
|
|
5694
|
-
var y;
|
|
5695
|
-
var d0;
|
|
5696
|
-
var d1;
|
|
5697
|
-
var d2;
|
|
5698
|
-
var d3;
|
|
5699
|
-
var dd;
|
|
5700
|
-
var dy;
|
|
5701
|
-
var ay;
|
|
5702
|
-
var bx0;
|
|
5703
|
-
var bx1;
|
|
5704
|
-
var bx2;
|
|
5705
|
-
var bx3;
|
|
5706
|
-
var vector = [];
|
|
5707
|
-
for (y = 0; y < la; y++) {
|
|
5708
|
-
vector.push(y + 1);
|
|
5709
|
-
vector.push(a.charCodeAt(offset + y));
|
|
5710
|
-
}
|
|
5711
|
-
var len = vector.length - 1;
|
|
5712
|
-
for (; x < lb - 3; ) {
|
|
5713
|
-
bx0 = b.charCodeAt(offset + (d0 = x));
|
|
5714
|
-
bx1 = b.charCodeAt(offset + (d1 = x + 1));
|
|
5715
|
-
bx2 = b.charCodeAt(offset + (d2 = x + 2));
|
|
5716
|
-
bx3 = b.charCodeAt(offset + (d3 = x + 3));
|
|
5717
|
-
dd = x += 4;
|
|
5718
|
-
for (y = 0; y < len; y += 2) {
|
|
5719
|
-
dy = vector[y];
|
|
5720
|
-
ay = vector[y + 1];
|
|
5721
|
-
d0 = _min(dy, d0, d1, bx0, ay);
|
|
5722
|
-
d1 = _min(d0, d1, d2, bx1, ay);
|
|
5723
|
-
d2 = _min(d1, d2, d3, bx2, ay);
|
|
5724
|
-
dd = _min(d2, d3, dd, bx3, ay);
|
|
5725
|
-
vector[y] = dd;
|
|
5726
|
-
d3 = d2;
|
|
5727
|
-
d2 = d1;
|
|
5728
|
-
d1 = d0;
|
|
5729
|
-
d0 = dy;
|
|
5730
|
-
}
|
|
5731
|
-
}
|
|
5732
|
-
for (; x < lb; ) {
|
|
5733
|
-
bx0 = b.charCodeAt(offset + (d0 = x));
|
|
5734
|
-
dd = ++x;
|
|
5735
|
-
for (y = 0; y < len; y += 2) {
|
|
5736
|
-
dy = vector[y];
|
|
5737
|
-
vector[y] = dd = _min(dy, d0, dd, bx0, vector[y + 1]);
|
|
5738
|
-
d0 = dy;
|
|
5739
|
-
}
|
|
5740
|
-
}
|
|
5741
|
-
return dd;
|
|
5742
|
-
};
|
|
5743
|
-
}();
|
|
5744
|
-
}
|
|
5745
|
-
});
|
|
5746
|
-
var import_js_levenshtein = __toESM5(require_js_levenshtein(), 1);
|
|
5747
|
-
var source_default3 = import_js_levenshtein.default;
|
|
5748
|
-
|
|
5749
5636
|
// src/core/utils/request/onUnhandledRequest.ts
|
|
5750
|
-
|
|
5751
|
-
var MAX_MATCH_SCORE = 3;
|
|
5752
|
-
var MAX_SUGGESTION_COUNT = 4;
|
|
5753
|
-
var TYPE_MATCH_DELTA = 0.5;
|
|
5754
|
-
function groupHandlersByType(handlers) {
|
|
5755
|
-
return handlers.reduce(
|
|
5756
|
-
(groups, handler) => {
|
|
5757
|
-
if (handler instanceof HttpHandler) {
|
|
5758
|
-
groups.http.push(handler);
|
|
5759
|
-
}
|
|
5760
|
-
if (handler instanceof GraphQLHandler) {
|
|
5761
|
-
groups.graphql.push(handler);
|
|
5762
|
-
}
|
|
5763
|
-
return groups;
|
|
5764
|
-
},
|
|
5765
|
-
{
|
|
5766
|
-
http: [],
|
|
5767
|
-
graphql: []
|
|
5768
|
-
}
|
|
5769
|
-
);
|
|
5770
|
-
}
|
|
5771
|
-
function getHttpHandlerScore() {
|
|
5772
|
-
return (request, handler) => {
|
|
5773
|
-
const { path, method } = handler.info;
|
|
5774
|
-
if (path instanceof RegExp || method instanceof RegExp) {
|
|
5775
|
-
return Infinity;
|
|
5776
|
-
}
|
|
5777
|
-
const hasSameMethod = isStringEqual(request.method, method);
|
|
5778
|
-
const methodScoreDelta = hasSameMethod ? TYPE_MATCH_DELTA : 0;
|
|
5779
|
-
const requestPublicUrl = getPublicUrlFromRequest(request);
|
|
5780
|
-
const score = getStringMatchScore(requestPublicUrl, path);
|
|
5781
|
-
return score - methodScoreDelta;
|
|
5782
|
-
};
|
|
5783
|
-
}
|
|
5784
|
-
function getGraphQLHandlerScore(parsedQuery) {
|
|
5785
|
-
return (_, handler) => {
|
|
5786
|
-
if (typeof parsedQuery.operationName === "undefined") {
|
|
5787
|
-
return Infinity;
|
|
5788
|
-
}
|
|
5789
|
-
const { operationType, operationName } = handler.info;
|
|
5790
|
-
if (typeof operationName !== "string") {
|
|
5791
|
-
return Infinity;
|
|
5792
|
-
}
|
|
5793
|
-
const hasSameOperationType = parsedQuery.operationType === operationType;
|
|
5794
|
-
const operationTypeScoreDelta = hasSameOperationType ? TYPE_MATCH_DELTA : 0;
|
|
5795
|
-
const score = getStringMatchScore(parsedQuery.operationName, operationName);
|
|
5796
|
-
return score - operationTypeScoreDelta;
|
|
5797
|
-
};
|
|
5798
|
-
}
|
|
5799
|
-
function getSuggestedHandler(request, handlers, getScore) {
|
|
5800
|
-
const suggestedHandlers = handlers.reduce((suggestions, handler) => {
|
|
5801
|
-
const score = getScore(request, handler);
|
|
5802
|
-
return suggestions.concat([[score, handler]]);
|
|
5803
|
-
}, []).sort(([leftScore], [rightScore]) => leftScore - rightScore).filter(([score]) => score <= MAX_MATCH_SCORE).slice(0, MAX_SUGGESTION_COUNT).map(([, handler]) => handler);
|
|
5804
|
-
return suggestedHandlers;
|
|
5805
|
-
}
|
|
5806
|
-
function getSuggestedHandlersMessage(handlers) {
|
|
5807
|
-
if (handlers.length > 1) {
|
|
5808
|
-
return `Did you mean to request one of the following resources instead?
|
|
5809
|
-
|
|
5810
|
-
${handlers.map((handler) => ` \u2022 ${handler.info.header}`).join("\n")}`;
|
|
5811
|
-
}
|
|
5812
|
-
return `Did you mean to request "${handlers[0].info.header}" instead?`;
|
|
5813
|
-
}
|
|
5814
|
-
async function onUnhandledRequest(request, handlers, strategy = "warn") {
|
|
5815
|
-
const parsedGraphQLQuery = await parseGraphQLRequest(request).catch(
|
|
5816
|
-
() => null
|
|
5817
|
-
);
|
|
5637
|
+
async function onUnhandledRequest(request, strategy = "warn") {
|
|
5818
5638
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
parsedGraphQLQuery ? getGraphQLHandlerScore(parsedGraphQLQuery) : getHttpHandlerScore()
|
|
5826
|
-
);
|
|
5827
|
-
return suggestedHandlers.length > 0 ? getSuggestedHandlersMessage(suggestedHandlers) : "";
|
|
5828
|
-
}
|
|
5829
|
-
function getGraphQLRequestHeader(parsedGraphQLRequest) {
|
|
5830
|
-
if (!parsedGraphQLRequest?.operationName) {
|
|
5831
|
-
return `anonymous ${parsedGraphQLRequest?.operationType} (${request.method} ${publicUrl})`;
|
|
5832
|
-
}
|
|
5833
|
-
return `${parsedGraphQLRequest.operationType} ${parsedGraphQLRequest.operationName} (${request.method} ${publicUrl})`;
|
|
5834
|
-
}
|
|
5835
|
-
function generateUnhandledRequestMessage() {
|
|
5836
|
-
const requestHeader = parsedGraphQLQuery ? getGraphQLRequestHeader(parsedGraphQLQuery) : `${request.method} ${publicUrl}`;
|
|
5837
|
-
const handlerSuggestion = generateHandlerSuggestion();
|
|
5838
|
-
const messageTemplate = [
|
|
5839
|
-
`intercepted a request without a matching request handler:`,
|
|
5840
|
-
` \u2022 ${requestHeader}`,
|
|
5841
|
-
handlerSuggestion,
|
|
5842
|
-
`If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
5843
|
-
Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
5844
|
-
].filter(Boolean);
|
|
5845
|
-
return messageTemplate.join("\n\n");
|
|
5846
|
-
}
|
|
5639
|
+
const unhandledRequestMessage = `intercepted a request without a matching request handler:
|
|
5640
|
+
|
|
5641
|
+
\u2022 ${request.method} ${publicUrl}
|
|
5642
|
+
|
|
5643
|
+
If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
5644
|
+
Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
5847
5645
|
function applyStrategy(strategy2) {
|
|
5848
|
-
const message3 = generateUnhandledRequestMessage();
|
|
5849
5646
|
switch (strategy2) {
|
|
5850
5647
|
case "error": {
|
|
5851
|
-
devUtils.error("Error: %s",
|
|
5648
|
+
devUtils.error("Error: %s", unhandledRequestMessage);
|
|
5852
5649
|
throw new Error(
|
|
5853
5650
|
devUtils.formatMessage(
|
|
5854
5651
|
'Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'
|
|
@@ -5856,7 +5653,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
5856
5653
|
);
|
|
5857
5654
|
}
|
|
5858
5655
|
case "warn": {
|
|
5859
|
-
devUtils.warn("Warning: %s",
|
|
5656
|
+
devUtils.warn("Warning: %s", unhandledRequestMessage);
|
|
5860
5657
|
break;
|
|
5861
5658
|
}
|
|
5862
5659
|
case "bypass":
|
|
@@ -5911,7 +5708,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
5911
5708
|
throw lookupResult.error;
|
|
5912
5709
|
}
|
|
5913
5710
|
if (!lookupResult.data) {
|
|
5914
|
-
await onUnhandledRequest(request,
|
|
5711
|
+
await onUnhandledRequest(request, options.onUnhandledRequest);
|
|
5915
5712
|
emitter.emit("request:unhandled", { request, requestId });
|
|
5916
5713
|
emitter.emit("request:end", { request, requestId });
|
|
5917
5714
|
handleRequestOptions?.onPassthroughResponse?.(request);
|