msw 0.33.2 → 0.36.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/lib/esm/RequestHandler-deps.js +447 -82
- package/lib/esm/errors-deps.js +15 -1
- package/lib/esm/fetch-deps.js +9 -5
- package/lib/esm/graphql-deps.js +15 -10
- package/lib/esm/graphql.js +1 -0
- package/lib/esm/index-deps.js +2 -1
- package/lib/esm/index.js +90 -3880
- package/lib/esm/index2.js +1 -1
- package/lib/esm/mockServiceWorker.js +21 -12
- package/lib/esm/rest-deps.js +8 -15
- package/lib/esm/rest.js +1 -0
- package/lib/iife/index.js +3 -3
- package/lib/iife/mockServiceWorker.js +21 -12
- package/lib/types/context/data.d.ts +2 -3
- package/lib/types/context/extensions.d.ts +8 -0
- package/lib/types/context/index.d.ts +1 -0
- package/lib/types/graphql.d.ts +2 -1
- package/lib/types/handlers/GraphQLHandler.d.ts +5 -4
- package/lib/types/handlers/RequestHandler.d.ts +1 -1
- package/lib/types/handlers/RestHandler.d.ts +8 -10
- package/lib/types/index.d.ts +17 -7
- package/lib/types/node/glossary.d.ts +4 -14
- package/lib/types/node/index.d.ts +1 -1
- package/lib/types/rest.d.ts +10 -9
- package/lib/types/setupWorker/glossary.d.ts +16 -26
- package/lib/types/setupWorker/start/utils/prepareStartHandler.d.ts +3 -3
- package/lib/types/sharedOptions.d.ts +12 -1
- package/lib/types/typeUtils.d.ts +5 -3
- package/lib/types/utils/handleRequest.d.ts +4 -4
- package/lib/types/utils/internal/getCallFrame.d.ts +1 -1
- package/lib/types/utils/internal/jsonParse.d.ts +2 -2
- package/lib/types/utils/internal/pipeEvents.d.ts +6 -0
- package/lib/types/utils/logging/prepareResponse.d.ts +1 -1
- package/lib/types/utils/matching/matchRequestUrl.d.ts +12 -2
- package/lib/types/utils/matching/normalizePath.d.ts +1 -1
- package/lib/types/utils/request/parseBody.d.ts +2 -2
- package/lib/types/utils/request/parseWorkerRequest.d.ts +2 -2
- package/lib/types/utils/worker/createFallbackRequestListener.d.ts +2 -1
- package/lib/types/utils/worker/createRequestListener.d.ts +2 -1
- package/lib/umd/index.js +1131 -249
- package/lib/umd/mockServiceWorker.js +21 -12
- package/native/lib/index.js +551 -508
- package/node/lib/index.js +553 -510
- package/package.json +19 -19
package/node/lib/index.js
CHANGED
|
@@ -8,7 +8,9 @@ var require$$0 = require('os');
|
|
|
8
8
|
var require$$1 = require('tty');
|
|
9
9
|
var require$$0$1 = require('events');
|
|
10
10
|
var interceptors = require('@mswjs/interceptors');
|
|
11
|
+
var cookies = require('@mswjs/cookies');
|
|
11
12
|
var timers = require('timers');
|
|
13
|
+
var getCleanUrl = require('@mswjs/interceptors/lib/utils/getCleanUrl');
|
|
12
14
|
|
|
13
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
16
|
|
|
@@ -1400,8 +1402,8 @@ var hasFlag$1 = (flag, argv = process.argv) => {
|
|
|
1400
1402
|
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
1401
1403
|
};
|
|
1402
1404
|
|
|
1403
|
-
const os = require$$0__default[
|
|
1404
|
-
const tty = require$$1__default[
|
|
1405
|
+
const os = require$$0__default["default"];
|
|
1406
|
+
const tty = require$$1__default["default"];
|
|
1405
1407
|
const hasFlag = hasFlag$1;
|
|
1406
1408
|
|
|
1407
1409
|
const {env} = process;
|
|
@@ -1936,7 +1938,7 @@ chalk.stderr.supportsColor = stderrColor;
|
|
|
1936
1938
|
|
|
1937
1939
|
var source = chalk;
|
|
1938
1940
|
|
|
1939
|
-
var lib$
|
|
1941
|
+
var lib$3 = {exports: {}};
|
|
1940
1942
|
|
|
1941
1943
|
(function (module, exports) {
|
|
1942
1944
|
(function (global, factory) {
|
|
@@ -1959,9 +1961,9 @@ var lib$4 = {exports: {}};
|
|
|
1959
1961
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1960
1962
|
|
|
1961
1963
|
})));
|
|
1962
|
-
}(lib$
|
|
1964
|
+
}(lib$3, lib$3.exports));
|
|
1963
1965
|
|
|
1964
|
-
var lib$
|
|
1966
|
+
var lib$2 = {};
|
|
1965
1967
|
|
|
1966
1968
|
var StrictEventEmitter$1 = {};
|
|
1967
1969
|
|
|
@@ -1987,7 +1989,7 @@ var __spreadArrays = (commonjsGlobal && commonjsGlobal.__spreadArrays) || functi
|
|
|
1987
1989
|
};
|
|
1988
1990
|
StrictEventEmitter$1.__esModule = true;
|
|
1989
1991
|
StrictEventEmitter$1.StrictEventEmitter = void 0;
|
|
1990
|
-
var events_1 = require$$0__default$1[
|
|
1992
|
+
var events_1 = require$$0__default$1["default"];
|
|
1991
1993
|
var StrictEventEmitter = /** @class */ (function (_super) {
|
|
1992
1994
|
__extends$1(StrictEventEmitter, _super);
|
|
1993
1995
|
function StrictEventEmitter() {
|
|
@@ -2031,7 +2033,7 @@ exports.__esModule = true;
|
|
|
2031
2033
|
exports.StrictEventEmitter = void 0;
|
|
2032
2034
|
var StrictEventEmitter_1 = StrictEventEmitter$1;
|
|
2033
2035
|
__createBinding(exports, StrictEventEmitter_1, "StrictEventEmitter");
|
|
2034
|
-
}(lib$
|
|
2036
|
+
}(lib$2));
|
|
2035
2037
|
|
|
2036
2038
|
function use(currentHandlers, ...handlers) {
|
|
2037
2039
|
currentHandlers.unshift(...handlers);
|
|
@@ -2255,19 +2257,19 @@ function uuidv4() {
|
|
|
2255
2257
|
}
|
|
2256
2258
|
|
|
2257
2259
|
/**
|
|
2258
|
-
* Parses a given
|
|
2260
|
+
* Parses a given value into a JSON.
|
|
2259
2261
|
* Does not throw an exception on an invalid JSON string.
|
|
2260
2262
|
*/
|
|
2261
|
-
function jsonParse(
|
|
2263
|
+
function jsonParse(value) {
|
|
2262
2264
|
try {
|
|
2263
|
-
return JSON.parse(
|
|
2265
|
+
return JSON.parse(value);
|
|
2264
2266
|
}
|
|
2265
2267
|
catch (error) {
|
|
2266
2268
|
return undefined;
|
|
2267
2269
|
}
|
|
2268
2270
|
}
|
|
2269
2271
|
|
|
2270
|
-
var lib$
|
|
2272
|
+
var lib$1 = {};
|
|
2271
2273
|
|
|
2272
2274
|
var Headers = {};
|
|
2273
2275
|
|
|
@@ -2791,11 +2793,11 @@ var flattenHeadersList_1 = flattenHeadersList$1;
|
|
|
2791
2793
|
Object.defineProperty(exports, "flattenHeadersList", { enumerable: true, get: function () { return flattenHeadersList_1.flattenHeadersList; } });
|
|
2792
2794
|
var flattenHeadersObject_1 = flattenHeadersObject$1;
|
|
2793
2795
|
Object.defineProperty(exports, "flattenHeadersObject", { enumerable: true, get: function () { return flattenHeadersObject_1.flattenHeadersObject; } });
|
|
2794
|
-
}(lib$
|
|
2796
|
+
}(lib$1));
|
|
2795
2797
|
|
|
2796
2798
|
function parseContentHeaders(headersString) {
|
|
2797
2799
|
var _a, _b;
|
|
2798
|
-
const headers = lib$
|
|
2800
|
+
const headers = lib$1.stringToHeaders(headersString);
|
|
2799
2801
|
const contentType = headers.get('content-type') || 'text/plain';
|
|
2800
2802
|
const disposition = headers.get('content-disposition');
|
|
2801
2803
|
if (!disposition) {
|
|
@@ -2866,403 +2868,30 @@ function parseMultipartData(data, headers) {
|
|
|
2866
2868
|
}
|
|
2867
2869
|
|
|
2868
2870
|
/**
|
|
2869
|
-
* Parses a given request/response body based on the
|
|
2871
|
+
* Parses a given request/response body based on the "Content-Type" header.
|
|
2870
2872
|
*/
|
|
2871
2873
|
function parseBody(body, headers) {
|
|
2872
2874
|
// Return whatever falsey body value is given.
|
|
2873
2875
|
if (!body) {
|
|
2874
2876
|
return body;
|
|
2875
2877
|
}
|
|
2876
|
-
const contentType = headers === null || headers === void 0 ? void 0 : headers.get('content-type');
|
|
2878
|
+
const contentType = (headers === null || headers === void 0 ? void 0 : headers.get('content-type')) || '';
|
|
2877
2879
|
// If the body has a Multipart Content-Type
|
|
2878
2880
|
// parse it into an object.
|
|
2879
|
-
const hasMultipartContent = contentType
|
|
2881
|
+
const hasMultipartContent = contentType.startsWith('multipart/form-data');
|
|
2880
2882
|
if (hasMultipartContent && typeof body !== 'object') {
|
|
2881
|
-
return parseMultipartData(body, headers) || body;
|
|
2883
|
+
return parseMultipartData(body.toString(), headers) || body;
|
|
2882
2884
|
}
|
|
2883
2885
|
// If the intercepted request's body has a JSON Content-Type
|
|
2884
2886
|
// parse it into an object.
|
|
2885
|
-
const hasJsonContent = contentType
|
|
2887
|
+
const hasJsonContent = contentType.includes('json');
|
|
2886
2888
|
if (hasJsonContent && typeof body !== 'object') {
|
|
2887
|
-
return jsonParse(body) || body;
|
|
2889
|
+
return jsonParse(body.toString()) || body;
|
|
2888
2890
|
}
|
|
2889
2891
|
// Otherwise leave as-is.
|
|
2890
2892
|
return body;
|
|
2891
2893
|
}
|
|
2892
2894
|
|
|
2893
|
-
var lib$1 = {};
|
|
2894
|
-
|
|
2895
|
-
var CookieStore = {};
|
|
2896
|
-
|
|
2897
|
-
var setCookie = {exports: {}};
|
|
2898
|
-
|
|
2899
|
-
var defaultParseOptions = {
|
|
2900
|
-
decodeValues: true,
|
|
2901
|
-
map: false,
|
|
2902
|
-
silent: false,
|
|
2903
|
-
};
|
|
2904
|
-
|
|
2905
|
-
function isNonEmptyString(str) {
|
|
2906
|
-
return typeof str === "string" && !!str.trim();
|
|
2907
|
-
}
|
|
2908
|
-
|
|
2909
|
-
function parseString(setCookieValue, options) {
|
|
2910
|
-
var parts = setCookieValue.split(";").filter(isNonEmptyString);
|
|
2911
|
-
var nameValue = parts.shift().split("=");
|
|
2912
|
-
var name = nameValue.shift();
|
|
2913
|
-
var value = nameValue.join("="); // everything after the first =, joined by a "=" if there was more than one part
|
|
2914
|
-
|
|
2915
|
-
options = options
|
|
2916
|
-
? Object.assign({}, defaultParseOptions, options)
|
|
2917
|
-
: defaultParseOptions;
|
|
2918
|
-
|
|
2919
|
-
try {
|
|
2920
|
-
value = options.decodeValues ? decodeURIComponent(value) : value; // decode cookie value
|
|
2921
|
-
} catch (e) {
|
|
2922
|
-
console.error(
|
|
2923
|
-
"set-cookie-parser encountered an error while decoding a cookie with value '" +
|
|
2924
|
-
value +
|
|
2925
|
-
"'. Set options.decodeValues to false to disable this feature.",
|
|
2926
|
-
e
|
|
2927
|
-
);
|
|
2928
|
-
}
|
|
2929
|
-
|
|
2930
|
-
var cookie = {
|
|
2931
|
-
name: name, // grab everything before the first =
|
|
2932
|
-
value: value,
|
|
2933
|
-
};
|
|
2934
|
-
|
|
2935
|
-
parts.forEach(function (part) {
|
|
2936
|
-
var sides = part.split("=");
|
|
2937
|
-
var key = sides.shift().trimLeft().toLowerCase();
|
|
2938
|
-
var value = sides.join("=");
|
|
2939
|
-
if (key === "expires") {
|
|
2940
|
-
cookie.expires = new Date(value);
|
|
2941
|
-
} else if (key === "max-age") {
|
|
2942
|
-
cookie.maxAge = parseInt(value, 10);
|
|
2943
|
-
} else if (key === "secure") {
|
|
2944
|
-
cookie.secure = true;
|
|
2945
|
-
} else if (key === "httponly") {
|
|
2946
|
-
cookie.httpOnly = true;
|
|
2947
|
-
} else if (key === "samesite") {
|
|
2948
|
-
cookie.sameSite = value;
|
|
2949
|
-
} else {
|
|
2950
|
-
cookie[key] = value;
|
|
2951
|
-
}
|
|
2952
|
-
});
|
|
2953
|
-
|
|
2954
|
-
return cookie;
|
|
2955
|
-
}
|
|
2956
|
-
|
|
2957
|
-
function parse$1(input, options) {
|
|
2958
|
-
options = options
|
|
2959
|
-
? Object.assign({}, defaultParseOptions, options)
|
|
2960
|
-
: defaultParseOptions;
|
|
2961
|
-
|
|
2962
|
-
if (!input) {
|
|
2963
|
-
if (!options.map) {
|
|
2964
|
-
return [];
|
|
2965
|
-
} else {
|
|
2966
|
-
return {};
|
|
2967
|
-
}
|
|
2968
|
-
}
|
|
2969
|
-
|
|
2970
|
-
if (input.headers && input.headers["set-cookie"]) {
|
|
2971
|
-
// fast-path for node.js (which automatically normalizes header names to lower-case
|
|
2972
|
-
input = input.headers["set-cookie"];
|
|
2973
|
-
} else if (input.headers) {
|
|
2974
|
-
// slow-path for other environments - see #25
|
|
2975
|
-
var sch =
|
|
2976
|
-
input.headers[
|
|
2977
|
-
Object.keys(input.headers).find(function (key) {
|
|
2978
|
-
return key.toLowerCase() === "set-cookie";
|
|
2979
|
-
})
|
|
2980
|
-
];
|
|
2981
|
-
// warn if called on a request-like object with a cookie header rather than a set-cookie header - see #34, 36
|
|
2982
|
-
if (!sch && input.headers.cookie && !options.silent) {
|
|
2983
|
-
console.warn(
|
|
2984
|
-
"Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
|
|
2985
|
-
);
|
|
2986
|
-
}
|
|
2987
|
-
input = sch;
|
|
2988
|
-
}
|
|
2989
|
-
if (!Array.isArray(input)) {
|
|
2990
|
-
input = [input];
|
|
2991
|
-
}
|
|
2992
|
-
|
|
2993
|
-
options = options
|
|
2994
|
-
? Object.assign({}, defaultParseOptions, options)
|
|
2995
|
-
: defaultParseOptions;
|
|
2996
|
-
|
|
2997
|
-
if (!options.map) {
|
|
2998
|
-
return input.filter(isNonEmptyString).map(function (str) {
|
|
2999
|
-
return parseString(str, options);
|
|
3000
|
-
});
|
|
3001
|
-
} else {
|
|
3002
|
-
var cookies = {};
|
|
3003
|
-
return input.filter(isNonEmptyString).reduce(function (cookies, str) {
|
|
3004
|
-
var cookie = parseString(str, options);
|
|
3005
|
-
cookies[cookie.name] = cookie;
|
|
3006
|
-
return cookies;
|
|
3007
|
-
}, cookies);
|
|
3008
|
-
}
|
|
3009
|
-
}
|
|
3010
|
-
|
|
3011
|
-
/*
|
|
3012
|
-
Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
3013
|
-
that are within a single set-cookie field-value, such as in the Expires portion.
|
|
3014
|
-
|
|
3015
|
-
This is uncommon, but explicitly allowed - see https://tools.ietf.org/html/rfc2616#section-4.2
|
|
3016
|
-
Node.js does this for every header *except* set-cookie - see https://github.com/nodejs/node/blob/d5e363b77ebaf1caf67cd7528224b651c86815c1/lib/_http_incoming.js#L128
|
|
3017
|
-
React Native's fetch does this for *every* header, including set-cookie.
|
|
3018
|
-
|
|
3019
|
-
Based on: https://github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
|
|
3020
|
-
Credits to: https://github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
|
|
3021
|
-
*/
|
|
3022
|
-
function splitCookiesString(cookiesString) {
|
|
3023
|
-
if (Array.isArray(cookiesString)) {
|
|
3024
|
-
return cookiesString;
|
|
3025
|
-
}
|
|
3026
|
-
if (typeof cookiesString !== "string") {
|
|
3027
|
-
return [];
|
|
3028
|
-
}
|
|
3029
|
-
|
|
3030
|
-
var cookiesStrings = [];
|
|
3031
|
-
var pos = 0;
|
|
3032
|
-
var start;
|
|
3033
|
-
var ch;
|
|
3034
|
-
var lastComma;
|
|
3035
|
-
var nextStart;
|
|
3036
|
-
var cookiesSeparatorFound;
|
|
3037
|
-
|
|
3038
|
-
function skipWhitespace() {
|
|
3039
|
-
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
|
|
3040
|
-
pos += 1;
|
|
3041
|
-
}
|
|
3042
|
-
return pos < cookiesString.length;
|
|
3043
|
-
}
|
|
3044
|
-
|
|
3045
|
-
function notSpecialChar() {
|
|
3046
|
-
ch = cookiesString.charAt(pos);
|
|
3047
|
-
|
|
3048
|
-
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
3049
|
-
}
|
|
3050
|
-
|
|
3051
|
-
while (pos < cookiesString.length) {
|
|
3052
|
-
start = pos;
|
|
3053
|
-
cookiesSeparatorFound = false;
|
|
3054
|
-
|
|
3055
|
-
while (skipWhitespace()) {
|
|
3056
|
-
ch = cookiesString.charAt(pos);
|
|
3057
|
-
if (ch === ",") {
|
|
3058
|
-
// ',' is a cookie separator if we have later first '=', not ';' or ','
|
|
3059
|
-
lastComma = pos;
|
|
3060
|
-
pos += 1;
|
|
3061
|
-
|
|
3062
|
-
skipWhitespace();
|
|
3063
|
-
nextStart = pos;
|
|
3064
|
-
|
|
3065
|
-
while (pos < cookiesString.length && notSpecialChar()) {
|
|
3066
|
-
pos += 1;
|
|
3067
|
-
}
|
|
3068
|
-
|
|
3069
|
-
// currently special character
|
|
3070
|
-
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
3071
|
-
// we found cookies separator
|
|
3072
|
-
cookiesSeparatorFound = true;
|
|
3073
|
-
// pos is inside the next cookie, so back up and return it.
|
|
3074
|
-
pos = nextStart;
|
|
3075
|
-
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
|
3076
|
-
start = pos;
|
|
3077
|
-
} else {
|
|
3078
|
-
// in param ',' or param separator ';',
|
|
3079
|
-
// we continue from that comma
|
|
3080
|
-
pos = lastComma + 1;
|
|
3081
|
-
}
|
|
3082
|
-
} else {
|
|
3083
|
-
pos += 1;
|
|
3084
|
-
}
|
|
3085
|
-
}
|
|
3086
|
-
|
|
3087
|
-
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
|
3088
|
-
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
|
3089
|
-
}
|
|
3090
|
-
}
|
|
3091
|
-
|
|
3092
|
-
return cookiesStrings;
|
|
3093
|
-
}
|
|
3094
|
-
|
|
3095
|
-
setCookie.exports = parse$1;
|
|
3096
|
-
setCookie.exports.parse = parse$1;
|
|
3097
|
-
setCookie.exports.parseString = parseString;
|
|
3098
|
-
setCookie.exports.splitCookiesString = splitCookiesString;
|
|
3099
|
-
|
|
3100
|
-
(function (exports) {
|
|
3101
|
-
var __rest = (commonjsGlobal && commonjsGlobal.__rest) || function (s, e) {
|
|
3102
|
-
var t = {};
|
|
3103
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
3104
|
-
t[p] = s[p];
|
|
3105
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
3106
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
3107
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
3108
|
-
t[p[i]] = s[p[i]];
|
|
3109
|
-
}
|
|
3110
|
-
return t;
|
|
3111
|
-
};
|
|
3112
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3113
|
-
exports.PERSISTENCY_KEY = void 0;
|
|
3114
|
-
const set_cookie_parser_1 = setCookie.exports;
|
|
3115
|
-
exports.PERSISTENCY_KEY = 'MSW_COOKIE_STORE';
|
|
3116
|
-
const SUPPORTS_LOCAL_STORAGE = typeof localStorage !== 'undefined';
|
|
3117
|
-
class CookieStore {
|
|
3118
|
-
constructor() {
|
|
3119
|
-
this.store = new Map();
|
|
3120
|
-
}
|
|
3121
|
-
/**
|
|
3122
|
-
* Sets the given request cookies into the store.
|
|
3123
|
-
* Respects the `request.credentials` policy.
|
|
3124
|
-
*/
|
|
3125
|
-
add(request, response) {
|
|
3126
|
-
if (request.credentials === 'omit') {
|
|
3127
|
-
return;
|
|
3128
|
-
}
|
|
3129
|
-
const requestUrl = new URL(request.url);
|
|
3130
|
-
const responseCookies = response.headers.get('set-cookie');
|
|
3131
|
-
if (!responseCookies) {
|
|
3132
|
-
return;
|
|
3133
|
-
}
|
|
3134
|
-
const now = Date.now();
|
|
3135
|
-
const parsedResponseCookies = set_cookie_parser_1.parse(responseCookies).map((_a) => {
|
|
3136
|
-
var { maxAge } = _a, cookie = __rest(_a, ["maxAge"]);
|
|
3137
|
-
return (Object.assign(Object.assign({}, cookie), { expires: maxAge === undefined ? cookie.expires : new Date(now + maxAge * 1000), maxAge }));
|
|
3138
|
-
});
|
|
3139
|
-
const prevCookies = this.store.get(requestUrl.origin) || new Map();
|
|
3140
|
-
parsedResponseCookies.forEach((cookie) => {
|
|
3141
|
-
this.store.set(requestUrl.origin, prevCookies.set(cookie.name, cookie));
|
|
3142
|
-
});
|
|
3143
|
-
}
|
|
3144
|
-
/**
|
|
3145
|
-
* Returns cookies relevant to the given request
|
|
3146
|
-
* and its `request.credentials` policy.
|
|
3147
|
-
*/
|
|
3148
|
-
get(request) {
|
|
3149
|
-
this.deleteExpiredCookies();
|
|
3150
|
-
const requestUrl = new URL(request.url);
|
|
3151
|
-
const originCookies = this.store.get(requestUrl.origin) || new Map();
|
|
3152
|
-
switch (request.credentials) {
|
|
3153
|
-
case 'include': {
|
|
3154
|
-
const documentCookies = set_cookie_parser_1.parse(document.cookie);
|
|
3155
|
-
documentCookies.forEach((cookie) => {
|
|
3156
|
-
originCookies.set(cookie.name, cookie);
|
|
3157
|
-
});
|
|
3158
|
-
return originCookies;
|
|
3159
|
-
}
|
|
3160
|
-
case 'same-origin': {
|
|
3161
|
-
return originCookies;
|
|
3162
|
-
}
|
|
3163
|
-
default:
|
|
3164
|
-
return new Map();
|
|
3165
|
-
}
|
|
3166
|
-
}
|
|
3167
|
-
/**
|
|
3168
|
-
* Returns a collection of all stored cookies.
|
|
3169
|
-
*/
|
|
3170
|
-
getAll() {
|
|
3171
|
-
this.deleteExpiredCookies();
|
|
3172
|
-
return this.store;
|
|
3173
|
-
}
|
|
3174
|
-
/**
|
|
3175
|
-
* Deletes all cookies associated with the given request.
|
|
3176
|
-
*/
|
|
3177
|
-
deleteAll(request) {
|
|
3178
|
-
const requestUrl = new URL(request.url);
|
|
3179
|
-
this.store.delete(requestUrl.origin);
|
|
3180
|
-
}
|
|
3181
|
-
/**
|
|
3182
|
-
* Clears the entire cookie store.
|
|
3183
|
-
*/
|
|
3184
|
-
clear() {
|
|
3185
|
-
this.store.clear();
|
|
3186
|
-
}
|
|
3187
|
-
/**
|
|
3188
|
-
* Hydrates the virtual cookie store from the `localStorage` if defined.
|
|
3189
|
-
*/
|
|
3190
|
-
hydrate() {
|
|
3191
|
-
if (!SUPPORTS_LOCAL_STORAGE) {
|
|
3192
|
-
return;
|
|
3193
|
-
}
|
|
3194
|
-
const persistedCookies = localStorage.getItem(exports.PERSISTENCY_KEY);
|
|
3195
|
-
if (persistedCookies) {
|
|
3196
|
-
try {
|
|
3197
|
-
const parsedCookies = JSON.parse(persistedCookies);
|
|
3198
|
-
parsedCookies.forEach(([origin, cookies]) => {
|
|
3199
|
-
this.store.set(origin, new Map(cookies.map((_a) => {
|
|
3200
|
-
var [token, _b] = _a, { expires } = _b, cookie = __rest(_b, ["expires"]);
|
|
3201
|
-
return [
|
|
3202
|
-
token,
|
|
3203
|
-
expires === undefined
|
|
3204
|
-
? cookie
|
|
3205
|
-
: Object.assign(Object.assign({}, cookie), { expires: new Date(expires) }),
|
|
3206
|
-
];
|
|
3207
|
-
})));
|
|
3208
|
-
});
|
|
3209
|
-
}
|
|
3210
|
-
catch (error) {
|
|
3211
|
-
console.warn(`
|
|
3212
|
-
[virtual-cookie] Failed to parse a stored cookie from the localStorage (key "${exports.PERSISTENCY_KEY}").
|
|
3213
|
-
|
|
3214
|
-
Stored value:
|
|
3215
|
-
${localStorage.getItem(exports.PERSISTENCY_KEY)}
|
|
3216
|
-
|
|
3217
|
-
Thrown exception:
|
|
3218
|
-
${error}
|
|
3219
|
-
|
|
3220
|
-
Invalid value has been removed from localStorage to prevent subsequent failed parsing attempts.`);
|
|
3221
|
-
localStorage.removeItem(exports.PERSISTENCY_KEY);
|
|
3222
|
-
}
|
|
3223
|
-
}
|
|
3224
|
-
}
|
|
3225
|
-
/**
|
|
3226
|
-
* Persists the current virtual cookies into the `localStorage` if defined,
|
|
3227
|
-
* so they are available on the next page load.
|
|
3228
|
-
*/
|
|
3229
|
-
persist() {
|
|
3230
|
-
if (!SUPPORTS_LOCAL_STORAGE) {
|
|
3231
|
-
return;
|
|
3232
|
-
}
|
|
3233
|
-
const serializedCookies = Array.from(this.store.entries()).map(([origin, cookies]) => {
|
|
3234
|
-
return [origin, Array.from(cookies.entries())];
|
|
3235
|
-
});
|
|
3236
|
-
localStorage.setItem(exports.PERSISTENCY_KEY, JSON.stringify(serializedCookies));
|
|
3237
|
-
}
|
|
3238
|
-
deleteExpiredCookies() {
|
|
3239
|
-
const now = Date.now();
|
|
3240
|
-
this.store.forEach((originCookies, origin) => {
|
|
3241
|
-
originCookies.forEach(({ expires, name }) => {
|
|
3242
|
-
if (expires !== undefined && expires.getTime() <= now) {
|
|
3243
|
-
originCookies.delete(name);
|
|
3244
|
-
}
|
|
3245
|
-
});
|
|
3246
|
-
if (originCookies.size === 0) {
|
|
3247
|
-
this.store.delete(origin);
|
|
3248
|
-
}
|
|
3249
|
-
});
|
|
3250
|
-
}
|
|
3251
|
-
}
|
|
3252
|
-
exports.default = new CookieStore();
|
|
3253
|
-
}(CookieStore));
|
|
3254
|
-
|
|
3255
|
-
(function (exports) {
|
|
3256
|
-
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
3257
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
3258
|
-
};
|
|
3259
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3260
|
-
exports.PERSISTENCY_KEY = exports.store = void 0;
|
|
3261
|
-
var CookieStore_1 = CookieStore;
|
|
3262
|
-
Object.defineProperty(exports, "store", { enumerable: true, get: function () { return __importDefault(CookieStore_1).default; } });
|
|
3263
|
-
Object.defineProperty(exports, "PERSISTENCY_KEY", { enumerable: true, get: function () { return CookieStore_1.PERSISTENCY_KEY; } });
|
|
3264
|
-
}(lib$1));
|
|
3265
|
-
|
|
3266
2895
|
function getAllCookies() {
|
|
3267
2896
|
return parse_1(document.cookie);
|
|
3268
2897
|
}
|
|
@@ -3273,7 +2902,7 @@ function getRequestCookies(request) {
|
|
|
3273
2902
|
/**
|
|
3274
2903
|
* @note No cookies persist on the document in Node.js: no document.
|
|
3275
2904
|
*/
|
|
3276
|
-
if (typeof location === 'undefined') {
|
|
2905
|
+
if (typeof document === 'undefined' || typeof location === 'undefined') {
|
|
3277
2906
|
return {};
|
|
3278
2907
|
}
|
|
3279
2908
|
switch (request.credentials) {
|
|
@@ -3294,8 +2923,8 @@ function getRequestCookies(request) {
|
|
|
3294
2923
|
|
|
3295
2924
|
function setRequestCookies(request) {
|
|
3296
2925
|
var _a;
|
|
3297
|
-
|
|
3298
|
-
request.cookies = Object.assign(Object.assign({}, getRequestCookies(request)), Array.from((_a =
|
|
2926
|
+
cookies.store.hydrate();
|
|
2927
|
+
request.cookies = Object.assign(Object.assign({}, getRequestCookies(request)), Array.from((_a = cookies.store.get(Object.assign(Object.assign({}, request), { url: request.url.toString() }))) === null || _a === void 0 ? void 0 : _a.entries()).reduce((cookies, [name, { value }]) => Object.assign(cookies, { [name]: value }), {}));
|
|
3299
2928
|
request.headers.set('cookie', Object.entries(request.cookies)
|
|
3300
2929
|
.map(([name, value]) => `${name}=${value}`)
|
|
3301
2930
|
.join('; '));
|
|
@@ -3397,6 +3026,65 @@ var lib = {};
|
|
|
3397
3026
|
|
|
3398
3027
|
var invariant$2 = {};
|
|
3399
3028
|
|
|
3029
|
+
var format$1 = {};
|
|
3030
|
+
|
|
3031
|
+
Object.defineProperty(format$1, "__esModule", { value: true });
|
|
3032
|
+
format$1.format = void 0;
|
|
3033
|
+
var POSITIONALS_EXP = /(%?)(%([sdjo]))/g;
|
|
3034
|
+
function serializePositional(positional, flag) {
|
|
3035
|
+
switch (flag) {
|
|
3036
|
+
// Strings.
|
|
3037
|
+
case 's':
|
|
3038
|
+
return positional;
|
|
3039
|
+
// Digits.
|
|
3040
|
+
case 'd':
|
|
3041
|
+
case 'i':
|
|
3042
|
+
return Number(positional);
|
|
3043
|
+
// JSON.
|
|
3044
|
+
case 'j':
|
|
3045
|
+
return JSON.stringify(positional);
|
|
3046
|
+
// Objects.
|
|
3047
|
+
case 'o': {
|
|
3048
|
+
// Preserve stings to prevent extra quotes around them.
|
|
3049
|
+
if (typeof positional === 'string') {
|
|
3050
|
+
return positional;
|
|
3051
|
+
}
|
|
3052
|
+
var json = JSON.stringify(positional);
|
|
3053
|
+
// If the positional isn't serializable, return it as-is.
|
|
3054
|
+
if (json === '{}' || json === '[]' || /^\[object .+?\]$/.test(json)) {
|
|
3055
|
+
return positional;
|
|
3056
|
+
}
|
|
3057
|
+
return json;
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
function format(message) {
|
|
3062
|
+
var positionals = [];
|
|
3063
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
3064
|
+
positionals[_i - 1] = arguments[_i];
|
|
3065
|
+
}
|
|
3066
|
+
if (positionals.length === 0) {
|
|
3067
|
+
return message;
|
|
3068
|
+
}
|
|
3069
|
+
var positionalIndex = 0;
|
|
3070
|
+
var formattedMessage = message.replace(POSITIONALS_EXP, function (match, isEscaped, _, flag) {
|
|
3071
|
+
var positional = positionals[positionalIndex];
|
|
3072
|
+
var value = serializePositional(positional, flag);
|
|
3073
|
+
if (!isEscaped) {
|
|
3074
|
+
positionalIndex++;
|
|
3075
|
+
return value;
|
|
3076
|
+
}
|
|
3077
|
+
return match;
|
|
3078
|
+
});
|
|
3079
|
+
// Append unresolved positionals to string as-is.
|
|
3080
|
+
if (positionalIndex < positionals.length) {
|
|
3081
|
+
formattedMessage += " " + positionals.slice(positionalIndex).join(' ');
|
|
3082
|
+
}
|
|
3083
|
+
formattedMessage = formattedMessage.replace(/%{2,2}/g, '%');
|
|
3084
|
+
return formattedMessage;
|
|
3085
|
+
}
|
|
3086
|
+
format$1.format = format;
|
|
3087
|
+
|
|
3400
3088
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
3401
3089
|
var extendStatics = function (d, b) {
|
|
3402
3090
|
extendStatics = Object.setPrototypeOf ||
|
|
@@ -3418,21 +3106,9 @@ var __spreadArray = (commonjsGlobal && commonjsGlobal.__spreadArray) || function
|
|
|
3418
3106
|
return to;
|
|
3419
3107
|
};
|
|
3420
3108
|
Object.defineProperty(invariant$2, "__esModule", { value: true });
|
|
3421
|
-
invariant$2.invariant = invariant$2.InvariantError =
|
|
3109
|
+
invariant$2.invariant = invariant$2.InvariantError = void 0;
|
|
3110
|
+
var format_1 = format$1;
|
|
3422
3111
|
var STACK_FRAMES_TO_IGNORE = 2;
|
|
3423
|
-
function interpolate(message) {
|
|
3424
|
-
var positionals = [];
|
|
3425
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
3426
|
-
positionals[_i - 1] = arguments[_i];
|
|
3427
|
-
}
|
|
3428
|
-
var index = 0;
|
|
3429
|
-
return message.replace(/%[s|d|o]/g, function (match) {
|
|
3430
|
-
var _a;
|
|
3431
|
-
var value = (_a = positionals[index++]) !== null && _a !== void 0 ? _a : match;
|
|
3432
|
-
return typeof value === 'object' ? JSON.stringify(value) : value;
|
|
3433
|
-
});
|
|
3434
|
-
}
|
|
3435
|
-
invariant$2.interpolate = interpolate;
|
|
3436
3112
|
var InvariantError = /** @class */ (function (_super) {
|
|
3437
3113
|
__extends(InvariantError, _super);
|
|
3438
3114
|
function InvariantError(message) {
|
|
@@ -3442,7 +3118,7 @@ var InvariantError = /** @class */ (function (_super) {
|
|
|
3442
3118
|
}
|
|
3443
3119
|
var _this = _super.call(this, message) || this;
|
|
3444
3120
|
_this.name = 'Invariant Violation';
|
|
3445
|
-
_this.message =
|
|
3121
|
+
_this.message = format_1.format.apply(void 0, __spreadArray([message], positionals));
|
|
3446
3122
|
if (_this.stack) {
|
|
3447
3123
|
var prevStack = _this.stack;
|
|
3448
3124
|
_this.stack = prevStack
|
|
@@ -3479,6 +3155,7 @@ var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m
|
|
|
3479
3155
|
};
|
|
3480
3156
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3481
3157
|
__exportStar(invariant$2, exports);
|
|
3158
|
+
__exportStar(format$1, exports);
|
|
3482
3159
|
}(lib));
|
|
3483
3160
|
|
|
3484
3161
|
const LIBRARY_PREFIX = '[MSW]';
|
|
@@ -3486,7 +3163,7 @@ const LIBRARY_PREFIX = '[MSW]';
|
|
|
3486
3163
|
* Formats a given message by appending the library's prefix string.
|
|
3487
3164
|
*/
|
|
3488
3165
|
function formatMessage(message, ...positionals) {
|
|
3489
|
-
const interpolatedMessage = lib.
|
|
3166
|
+
const interpolatedMessage = lib.format(message, ...positionals);
|
|
3490
3167
|
return `${LIBRARY_PREFIX} ${interpolatedMessage}`;
|
|
3491
3168
|
}
|
|
3492
3169
|
/**
|
|
@@ -4066,6 +3743,7 @@ function invariant(condition, message) {
|
|
|
4066
3743
|
|
|
4067
3744
|
// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
4068
3745
|
var nodejsCustomInspectSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined;
|
|
3746
|
+
var nodejsCustomInspectSymbol$1 = nodejsCustomInspectSymbol;
|
|
4069
3747
|
|
|
4070
3748
|
/**
|
|
4071
3749
|
* The `defineInspect()` function defines `inspect()` prototype method as alias of `toJSON`
|
|
@@ -4076,8 +3754,8 @@ function defineInspect(classObject) {
|
|
|
4076
3754
|
typeof fn === 'function' || invariant(0);
|
|
4077
3755
|
classObject.prototype.inspect = fn; // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
4078
3756
|
|
|
4079
|
-
if (nodejsCustomInspectSymbol) {
|
|
4080
|
-
classObject.prototype[nodejsCustomInspectSymbol] = fn;
|
|
3757
|
+
if (nodejsCustomInspectSymbol$1) {
|
|
3758
|
+
classObject.prototype[nodejsCustomInspectSymbol$1] = fn;
|
|
4081
3759
|
}
|
|
4082
3760
|
}
|
|
4083
3761
|
|
|
@@ -4320,7 +3998,7 @@ function formatArray(array, seenValues) {
|
|
|
4320
3998
|
}
|
|
4321
3999
|
|
|
4322
4000
|
function getCustomFn(object) {
|
|
4323
|
-
var customInspectFn = object[String(nodejsCustomInspectSymbol)];
|
|
4001
|
+
var customInspectFn = object[String(nodejsCustomInspectSymbol$1)];
|
|
4324
4002
|
|
|
4325
4003
|
if (typeof customInspectFn === 'function') {
|
|
4326
4004
|
return customInspectFn;
|
|
@@ -5240,7 +4918,7 @@ function isNameStart(code) {
|
|
|
5240
4918
|
* Given a GraphQL source, parses it into a Document.
|
|
5241
4919
|
* Throws GraphQLError if a syntax error is encountered.
|
|
5242
4920
|
*/
|
|
5243
|
-
function parse(source, options) {
|
|
4921
|
+
function parse$1(source, options) {
|
|
5244
4922
|
var parser = new Parser(source, options);
|
|
5245
4923
|
return parser.parseDocument();
|
|
5246
4924
|
}
|
|
@@ -6759,7 +6437,7 @@ function parseDocumentNode(node) {
|
|
|
6759
6437
|
}
|
|
6760
6438
|
function parseQuery(query) {
|
|
6761
6439
|
try {
|
|
6762
|
-
const ast = parse(query);
|
|
6440
|
+
const ast = parse$1(query);
|
|
6763
6441
|
return parseDocumentNode(ast);
|
|
6764
6442
|
}
|
|
6765
6443
|
catch (error) {
|
|
@@ -6840,7 +6518,7 @@ function parseGraphQLRequest(request) {
|
|
|
6840
6518
|
const parsedResult = parseQuery(query);
|
|
6841
6519
|
if (parsedResult instanceof Error) {
|
|
6842
6520
|
const requestPublicUrl = getPublicUrlFromRequest(request);
|
|
6843
|
-
throw new Error(devUtils.formatMessage('Failed to intercept a GraphQL request to "%s %s": cannot parse query. See the error message from the parser below.\n\n%
|
|
6521
|
+
throw new Error(devUtils.formatMessage('Failed to intercept a GraphQL request to "%s %s": cannot parse query. See the error message from the parser below.\n\n%s', request.method, requestPublicUrl, parsedResult.message));
|
|
6844
6522
|
}
|
|
6845
6523
|
return {
|
|
6846
6524
|
operationType: parsedResult.operationType,
|
|
@@ -6955,7 +6633,7 @@ function set(...args) {
|
|
|
6955
6633
|
res.headers.append(name, value);
|
|
6956
6634
|
}
|
|
6957
6635
|
else {
|
|
6958
|
-
const headers = lib$
|
|
6636
|
+
const headers = lib$1.objectToHeaders(name);
|
|
6959
6637
|
headers.forEach((value, name) => {
|
|
6960
6638
|
res.headers.append(name, value);
|
|
6961
6639
|
});
|
|
@@ -7052,12 +6730,26 @@ const data = (payload) => {
|
|
|
7052
6730
|
};
|
|
7053
6731
|
};
|
|
7054
6732
|
|
|
6733
|
+
/**
|
|
6734
|
+
* Sets the GraphQL extensions on a given response.
|
|
6735
|
+
* @example
|
|
6736
|
+
* res(ctx.extensions({ tracing: { version: 1 }}))
|
|
6737
|
+
* @see {@link https://mswjs.io/docs/api/context/extensions `ctx.extensions()`}
|
|
6738
|
+
*/
|
|
6739
|
+
const extensions = (payload) => {
|
|
6740
|
+
return (res) => {
|
|
6741
|
+
const prevBody = jsonParse(res.body) || {};
|
|
6742
|
+
const nextBody = mergeRight(prevBody, { extensions: payload });
|
|
6743
|
+
return json(nextBody)(res);
|
|
6744
|
+
};
|
|
6745
|
+
};
|
|
6746
|
+
|
|
7055
6747
|
const SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647;
|
|
7056
6748
|
const MIN_SERVER_RESPONSE_TIME = 100;
|
|
7057
6749
|
const MAX_SERVER_RESPONSE_TIME = 400;
|
|
7058
6750
|
const NODE_SERVER_RESPONSE_TIME = 5;
|
|
7059
6751
|
const getRandomServerResponseTime = () => {
|
|
7060
|
-
if (lib$
|
|
6752
|
+
if (lib$3.exports.isNodeProcess()) {
|
|
7061
6753
|
return NODE_SERVER_RESPONSE_TIME;
|
|
7062
6754
|
}
|
|
7063
6755
|
return Math.floor(Math.random() * (MAX_SERVER_RESPONSE_TIME - MIN_SERVER_RESPONSE_TIME) +
|
|
@@ -7124,9 +6816,9 @@ const errors = (errorsList) => {
|
|
|
7124
6816
|
};
|
|
7125
6817
|
};
|
|
7126
6818
|
|
|
7127
|
-
const useFetch = lib$
|
|
6819
|
+
const useFetch = lib$3.exports.isNodeProcess() ? require('node-fetch') : window.fetch;
|
|
7128
6820
|
const augmentRequestInit = (requestInit) => {
|
|
7129
|
-
const headers = new lib$
|
|
6821
|
+
const headers = new lib$1.Headers(requestInit.headers);
|
|
7130
6822
|
headers.set('x-msw-bypass', 'true');
|
|
7131
6823
|
return Object.assign(Object.assign({}, requestInit), { headers: headers.all() });
|
|
7132
6824
|
};
|
|
@@ -7136,8 +6828,12 @@ const createFetchRequestParameters = (input) => {
|
|
|
7136
6828
|
if (['GET', 'HEAD'].includes(method)) {
|
|
7137
6829
|
return requestParameters;
|
|
7138
6830
|
}
|
|
7139
|
-
|
|
7140
|
-
|
|
6831
|
+
if (typeof body === 'object' || typeof body === 'number') {
|
|
6832
|
+
requestParameters.body = JSON.stringify(body);
|
|
6833
|
+
}
|
|
6834
|
+
else {
|
|
6835
|
+
requestParameters.body = body;
|
|
6836
|
+
}
|
|
7141
6837
|
return requestParameters;
|
|
7142
6838
|
};
|
|
7143
6839
|
/**
|
|
@@ -7226,63 +6922,345 @@ function prepareRequest(request) {
|
|
|
7226
6922
|
* Formats a mocked response for introspection in the browser's console.
|
|
7227
6923
|
*/
|
|
7228
6924
|
function prepareResponse(res) {
|
|
7229
|
-
const responseHeaders = lib$
|
|
6925
|
+
const responseHeaders = lib$1.objectToHeaders(res.headers);
|
|
7230
6926
|
return Object.assign(Object.assign({}, res), {
|
|
7231
6927
|
// Parse a response JSON body for preview in the logs
|
|
7232
6928
|
body: parseBody(res.body, responseHeaders) });
|
|
7233
6929
|
}
|
|
7234
6930
|
|
|
7235
|
-
/**
|
|
7236
|
-
* Converts a string path to a Regular Expression.
|
|
7237
|
-
* Transforms path parameters into named RegExp groups.
|
|
7238
|
-
*/
|
|
7239
|
-
const pathToRegExp = (path) => {
|
|
7240
|
-
const pattern = path
|
|
7241
|
-
// Escape literal dots
|
|
7242
|
-
.replace(/\./g, '\\.')
|
|
7243
|
-
// Escape literal slashes
|
|
7244
|
-
.replace(/\//g, '/')
|
|
7245
|
-
// Escape literal question marks
|
|
7246
|
-
.replace(/\?/g, '\\?')
|
|
7247
|
-
// Ignore trailing slashes
|
|
7248
|
-
.replace(/\/+$/, '')
|
|
7249
|
-
// Replace wildcard with any zero-to-any character sequence
|
|
7250
|
-
.replace(/\*+/g, '.*')
|
|
7251
|
-
// Replace parameters with named capturing groups
|
|
7252
|
-
.replace(/:([^\d|^\/][a-zA-Z0-9_]*(?=(?:\/|\\.)|$))/g, (_, paramName) => `(?<${paramName}>[^\/]+?)`)
|
|
7253
|
-
// Allow optional trailing slash
|
|
7254
|
-
.concat('(\\/|$)');
|
|
7255
|
-
return new RegExp(pattern, 'gi');
|
|
7256
|
-
};
|
|
7257
|
-
|
|
7258
|
-
/**
|
|
7259
|
-
* Matches a given url against a path.
|
|
7260
|
-
*/
|
|
7261
|
-
const match = (path, url) => {
|
|
7262
|
-
const expression = path instanceof RegExp ? path : pathToRegExp(path);
|
|
7263
|
-
const match = expression.exec(url) || false;
|
|
7264
|
-
// Matches in strict mode: match string should equal to input (url)
|
|
7265
|
-
// Otherwise loose matches will be considered truthy:
|
|
7266
|
-
// match('/messages/:id', '/messages/123/users') // true
|
|
7267
|
-
const matches = path instanceof RegExp ? !!match : !!match && match[0] === match.input;
|
|
7268
|
-
return {
|
|
7269
|
-
matches,
|
|
7270
|
-
params: match && matches ? match.groups || null : null,
|
|
7271
|
-
};
|
|
7272
|
-
};
|
|
7273
|
-
|
|
7274
|
-
var getCleanUrl$1 = {};
|
|
7275
|
-
|
|
7276
|
-
Object.defineProperty(getCleanUrl$1, "__esModule", { value: true });
|
|
7277
|
-
var getCleanUrl_2 = getCleanUrl$1.getCleanUrl = void 0;
|
|
7278
6931
|
/**
|
|
7279
|
-
*
|
|
6932
|
+
* Tokenize input string.
|
|
7280
6933
|
*/
|
|
7281
|
-
function
|
|
7282
|
-
|
|
7283
|
-
|
|
6934
|
+
function lexer(str) {
|
|
6935
|
+
var tokens = [];
|
|
6936
|
+
var i = 0;
|
|
6937
|
+
while (i < str.length) {
|
|
6938
|
+
var char = str[i];
|
|
6939
|
+
if (char === "*" || char === "+" || char === "?") {
|
|
6940
|
+
tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
|
|
6941
|
+
continue;
|
|
6942
|
+
}
|
|
6943
|
+
if (char === "\\") {
|
|
6944
|
+
tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
|
|
6945
|
+
continue;
|
|
6946
|
+
}
|
|
6947
|
+
if (char === "{") {
|
|
6948
|
+
tokens.push({ type: "OPEN", index: i, value: str[i++] });
|
|
6949
|
+
continue;
|
|
6950
|
+
}
|
|
6951
|
+
if (char === "}") {
|
|
6952
|
+
tokens.push({ type: "CLOSE", index: i, value: str[i++] });
|
|
6953
|
+
continue;
|
|
6954
|
+
}
|
|
6955
|
+
if (char === ":") {
|
|
6956
|
+
var name = "";
|
|
6957
|
+
var j = i + 1;
|
|
6958
|
+
while (j < str.length) {
|
|
6959
|
+
var code = str.charCodeAt(j);
|
|
6960
|
+
if (
|
|
6961
|
+
// `0-9`
|
|
6962
|
+
(code >= 48 && code <= 57) ||
|
|
6963
|
+
// `A-Z`
|
|
6964
|
+
(code >= 65 && code <= 90) ||
|
|
6965
|
+
// `a-z`
|
|
6966
|
+
(code >= 97 && code <= 122) ||
|
|
6967
|
+
// `_`
|
|
6968
|
+
code === 95) {
|
|
6969
|
+
name += str[j++];
|
|
6970
|
+
continue;
|
|
6971
|
+
}
|
|
6972
|
+
break;
|
|
6973
|
+
}
|
|
6974
|
+
if (!name)
|
|
6975
|
+
throw new TypeError("Missing parameter name at " + i);
|
|
6976
|
+
tokens.push({ type: "NAME", index: i, value: name });
|
|
6977
|
+
i = j;
|
|
6978
|
+
continue;
|
|
6979
|
+
}
|
|
6980
|
+
if (char === "(") {
|
|
6981
|
+
var count = 1;
|
|
6982
|
+
var pattern = "";
|
|
6983
|
+
var j = i + 1;
|
|
6984
|
+
if (str[j] === "?") {
|
|
6985
|
+
throw new TypeError("Pattern cannot start with \"?\" at " + j);
|
|
6986
|
+
}
|
|
6987
|
+
while (j < str.length) {
|
|
6988
|
+
if (str[j] === "\\") {
|
|
6989
|
+
pattern += str[j++] + str[j++];
|
|
6990
|
+
continue;
|
|
6991
|
+
}
|
|
6992
|
+
if (str[j] === ")") {
|
|
6993
|
+
count--;
|
|
6994
|
+
if (count === 0) {
|
|
6995
|
+
j++;
|
|
6996
|
+
break;
|
|
6997
|
+
}
|
|
6998
|
+
}
|
|
6999
|
+
else if (str[j] === "(") {
|
|
7000
|
+
count++;
|
|
7001
|
+
if (str[j + 1] !== "?") {
|
|
7002
|
+
throw new TypeError("Capturing groups are not allowed at " + j);
|
|
7003
|
+
}
|
|
7004
|
+
}
|
|
7005
|
+
pattern += str[j++];
|
|
7006
|
+
}
|
|
7007
|
+
if (count)
|
|
7008
|
+
throw new TypeError("Unbalanced pattern at " + i);
|
|
7009
|
+
if (!pattern)
|
|
7010
|
+
throw new TypeError("Missing pattern at " + i);
|
|
7011
|
+
tokens.push({ type: "PATTERN", index: i, value: pattern });
|
|
7012
|
+
i = j;
|
|
7013
|
+
continue;
|
|
7014
|
+
}
|
|
7015
|
+
tokens.push({ type: "CHAR", index: i, value: str[i++] });
|
|
7016
|
+
}
|
|
7017
|
+
tokens.push({ type: "END", index: i, value: "" });
|
|
7018
|
+
return tokens;
|
|
7019
|
+
}
|
|
7020
|
+
/**
|
|
7021
|
+
* Parse a string for the raw tokens.
|
|
7022
|
+
*/
|
|
7023
|
+
function parse(str, options) {
|
|
7024
|
+
if (options === void 0) { options = {}; }
|
|
7025
|
+
var tokens = lexer(str);
|
|
7026
|
+
var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a;
|
|
7027
|
+
var defaultPattern = "[^" + escapeString(options.delimiter || "/#?") + "]+?";
|
|
7028
|
+
var result = [];
|
|
7029
|
+
var key = 0;
|
|
7030
|
+
var i = 0;
|
|
7031
|
+
var path = "";
|
|
7032
|
+
var tryConsume = function (type) {
|
|
7033
|
+
if (i < tokens.length && tokens[i].type === type)
|
|
7034
|
+
return tokens[i++].value;
|
|
7035
|
+
};
|
|
7036
|
+
var mustConsume = function (type) {
|
|
7037
|
+
var value = tryConsume(type);
|
|
7038
|
+
if (value !== undefined)
|
|
7039
|
+
return value;
|
|
7040
|
+
var _a = tokens[i], nextType = _a.type, index = _a.index;
|
|
7041
|
+
throw new TypeError("Unexpected " + nextType + " at " + index + ", expected " + type);
|
|
7042
|
+
};
|
|
7043
|
+
var consumeText = function () {
|
|
7044
|
+
var result = "";
|
|
7045
|
+
var value;
|
|
7046
|
+
// tslint:disable-next-line
|
|
7047
|
+
while ((value = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR"))) {
|
|
7048
|
+
result += value;
|
|
7049
|
+
}
|
|
7050
|
+
return result;
|
|
7051
|
+
};
|
|
7052
|
+
while (i < tokens.length) {
|
|
7053
|
+
var char = tryConsume("CHAR");
|
|
7054
|
+
var name = tryConsume("NAME");
|
|
7055
|
+
var pattern = tryConsume("PATTERN");
|
|
7056
|
+
if (name || pattern) {
|
|
7057
|
+
var prefix = char || "";
|
|
7058
|
+
if (prefixes.indexOf(prefix) === -1) {
|
|
7059
|
+
path += prefix;
|
|
7060
|
+
prefix = "";
|
|
7061
|
+
}
|
|
7062
|
+
if (path) {
|
|
7063
|
+
result.push(path);
|
|
7064
|
+
path = "";
|
|
7065
|
+
}
|
|
7066
|
+
result.push({
|
|
7067
|
+
name: name || key++,
|
|
7068
|
+
prefix: prefix,
|
|
7069
|
+
suffix: "",
|
|
7070
|
+
pattern: pattern || defaultPattern,
|
|
7071
|
+
modifier: tryConsume("MODIFIER") || ""
|
|
7072
|
+
});
|
|
7073
|
+
continue;
|
|
7074
|
+
}
|
|
7075
|
+
var value = char || tryConsume("ESCAPED_CHAR");
|
|
7076
|
+
if (value) {
|
|
7077
|
+
path += value;
|
|
7078
|
+
continue;
|
|
7079
|
+
}
|
|
7080
|
+
if (path) {
|
|
7081
|
+
result.push(path);
|
|
7082
|
+
path = "";
|
|
7083
|
+
}
|
|
7084
|
+
var open = tryConsume("OPEN");
|
|
7085
|
+
if (open) {
|
|
7086
|
+
var prefix = consumeText();
|
|
7087
|
+
var name_1 = tryConsume("NAME") || "";
|
|
7088
|
+
var pattern_1 = tryConsume("PATTERN") || "";
|
|
7089
|
+
var suffix = consumeText();
|
|
7090
|
+
mustConsume("CLOSE");
|
|
7091
|
+
result.push({
|
|
7092
|
+
name: name_1 || (pattern_1 ? key++ : ""),
|
|
7093
|
+
pattern: name_1 && !pattern_1 ? defaultPattern : pattern_1,
|
|
7094
|
+
prefix: prefix,
|
|
7095
|
+
suffix: suffix,
|
|
7096
|
+
modifier: tryConsume("MODIFIER") || ""
|
|
7097
|
+
});
|
|
7098
|
+
continue;
|
|
7099
|
+
}
|
|
7100
|
+
mustConsume("END");
|
|
7101
|
+
}
|
|
7102
|
+
return result;
|
|
7103
|
+
}
|
|
7104
|
+
/**
|
|
7105
|
+
* Create path match function from `path-to-regexp` spec.
|
|
7106
|
+
*/
|
|
7107
|
+
function match(str, options) {
|
|
7108
|
+
var keys = [];
|
|
7109
|
+
var re = pathToRegexp(str, keys, options);
|
|
7110
|
+
return regexpToFunction(re, keys, options);
|
|
7111
|
+
}
|
|
7112
|
+
/**
|
|
7113
|
+
* Create a path match function from `path-to-regexp` output.
|
|
7114
|
+
*/
|
|
7115
|
+
function regexpToFunction(re, keys, options) {
|
|
7116
|
+
if (options === void 0) { options = {}; }
|
|
7117
|
+
var _a = options.decode, decode = _a === void 0 ? function (x) { return x; } : _a;
|
|
7118
|
+
return function (pathname) {
|
|
7119
|
+
var m = re.exec(pathname);
|
|
7120
|
+
if (!m)
|
|
7121
|
+
return false;
|
|
7122
|
+
var path = m[0], index = m.index;
|
|
7123
|
+
var params = Object.create(null);
|
|
7124
|
+
var _loop_1 = function (i) {
|
|
7125
|
+
// tslint:disable-next-line
|
|
7126
|
+
if (m[i] === undefined)
|
|
7127
|
+
return "continue";
|
|
7128
|
+
var key = keys[i - 1];
|
|
7129
|
+
if (key.modifier === "*" || key.modifier === "+") {
|
|
7130
|
+
params[key.name] = m[i].split(key.prefix + key.suffix).map(function (value) {
|
|
7131
|
+
return decode(value, key);
|
|
7132
|
+
});
|
|
7133
|
+
}
|
|
7134
|
+
else {
|
|
7135
|
+
params[key.name] = decode(m[i], key);
|
|
7136
|
+
}
|
|
7137
|
+
};
|
|
7138
|
+
for (var i = 1; i < m.length; i++) {
|
|
7139
|
+
_loop_1(i);
|
|
7140
|
+
}
|
|
7141
|
+
return { path: path, index: index, params: params };
|
|
7142
|
+
};
|
|
7143
|
+
}
|
|
7144
|
+
/**
|
|
7145
|
+
* Escape a regular expression string.
|
|
7146
|
+
*/
|
|
7147
|
+
function escapeString(str) {
|
|
7148
|
+
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
|
|
7149
|
+
}
|
|
7150
|
+
/**
|
|
7151
|
+
* Get the flags for a regexp from the options.
|
|
7152
|
+
*/
|
|
7153
|
+
function flags(options) {
|
|
7154
|
+
return options && options.sensitive ? "" : "i";
|
|
7155
|
+
}
|
|
7156
|
+
/**
|
|
7157
|
+
* Pull out keys from a regexp.
|
|
7158
|
+
*/
|
|
7159
|
+
function regexpToRegexp(path, keys) {
|
|
7160
|
+
if (!keys)
|
|
7161
|
+
return path;
|
|
7162
|
+
var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g;
|
|
7163
|
+
var index = 0;
|
|
7164
|
+
var execResult = groupsRegex.exec(path.source);
|
|
7165
|
+
while (execResult) {
|
|
7166
|
+
keys.push({
|
|
7167
|
+
// Use parenthesized substring match if available, index otherwise
|
|
7168
|
+
name: execResult[1] || index++,
|
|
7169
|
+
prefix: "",
|
|
7170
|
+
suffix: "",
|
|
7171
|
+
modifier: "",
|
|
7172
|
+
pattern: ""
|
|
7173
|
+
});
|
|
7174
|
+
execResult = groupsRegex.exec(path.source);
|
|
7175
|
+
}
|
|
7176
|
+
return path;
|
|
7177
|
+
}
|
|
7178
|
+
/**
|
|
7179
|
+
* Transform an array into a regexp.
|
|
7180
|
+
*/
|
|
7181
|
+
function arrayToRegexp(paths, keys, options) {
|
|
7182
|
+
var parts = paths.map(function (path) { return pathToRegexp(path, keys, options).source; });
|
|
7183
|
+
return new RegExp("(?:" + parts.join("|") + ")", flags(options));
|
|
7184
|
+
}
|
|
7185
|
+
/**
|
|
7186
|
+
* Create a path regexp from string input.
|
|
7187
|
+
*/
|
|
7188
|
+
function stringToRegexp(path, keys, options) {
|
|
7189
|
+
return tokensToRegexp(parse(path, options), keys, options);
|
|
7190
|
+
}
|
|
7191
|
+
/**
|
|
7192
|
+
* Expose a function for taking tokens and returning a RegExp.
|
|
7193
|
+
*/
|
|
7194
|
+
function tokensToRegexp(tokens, keys, options) {
|
|
7195
|
+
if (options === void 0) { options = {}; }
|
|
7196
|
+
var _a = options.strict, strict = _a === void 0 ? false : _a, _b = options.start, start = _b === void 0 ? true : _b, _c = options.end, end = _c === void 0 ? true : _c, _d = options.encode, encode = _d === void 0 ? function (x) { return x; } : _d;
|
|
7197
|
+
var endsWith = "[" + escapeString(options.endsWith || "") + "]|$";
|
|
7198
|
+
var delimiter = "[" + escapeString(options.delimiter || "/#?") + "]";
|
|
7199
|
+
var route = start ? "^" : "";
|
|
7200
|
+
// Iterate over the tokens and create our regexp string.
|
|
7201
|
+
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
|
7202
|
+
var token = tokens_1[_i];
|
|
7203
|
+
if (typeof token === "string") {
|
|
7204
|
+
route += escapeString(encode(token));
|
|
7205
|
+
}
|
|
7206
|
+
else {
|
|
7207
|
+
var prefix = escapeString(encode(token.prefix));
|
|
7208
|
+
var suffix = escapeString(encode(token.suffix));
|
|
7209
|
+
if (token.pattern) {
|
|
7210
|
+
if (keys)
|
|
7211
|
+
keys.push(token);
|
|
7212
|
+
if (prefix || suffix) {
|
|
7213
|
+
if (token.modifier === "+" || token.modifier === "*") {
|
|
7214
|
+
var mod = token.modifier === "*" ? "?" : "";
|
|
7215
|
+
route += "(?:" + prefix + "((?:" + token.pattern + ")(?:" + suffix + prefix + "(?:" + token.pattern + "))*)" + suffix + ")" + mod;
|
|
7216
|
+
}
|
|
7217
|
+
else {
|
|
7218
|
+
route += "(?:" + prefix + "(" + token.pattern + ")" + suffix + ")" + token.modifier;
|
|
7219
|
+
}
|
|
7220
|
+
}
|
|
7221
|
+
else {
|
|
7222
|
+
route += "(" + token.pattern + ")" + token.modifier;
|
|
7223
|
+
}
|
|
7224
|
+
}
|
|
7225
|
+
else {
|
|
7226
|
+
route += "(?:" + prefix + suffix + ")" + token.modifier;
|
|
7227
|
+
}
|
|
7228
|
+
}
|
|
7229
|
+
}
|
|
7230
|
+
if (end) {
|
|
7231
|
+
if (!strict)
|
|
7232
|
+
route += delimiter + "?";
|
|
7233
|
+
route += !options.endsWith ? "$" : "(?=" + endsWith + ")";
|
|
7234
|
+
}
|
|
7235
|
+
else {
|
|
7236
|
+
var endToken = tokens[tokens.length - 1];
|
|
7237
|
+
var isEndDelimited = typeof endToken === "string"
|
|
7238
|
+
? delimiter.indexOf(endToken[endToken.length - 1]) > -1
|
|
7239
|
+
: // tslint:disable-next-line
|
|
7240
|
+
endToken === undefined;
|
|
7241
|
+
if (!strict) {
|
|
7242
|
+
route += "(?:" + delimiter + "(?=" + endsWith + "))?";
|
|
7243
|
+
}
|
|
7244
|
+
if (!isEndDelimited) {
|
|
7245
|
+
route += "(?=" + delimiter + "|" + endsWith + ")";
|
|
7246
|
+
}
|
|
7247
|
+
}
|
|
7248
|
+
return new RegExp(route, flags(options));
|
|
7249
|
+
}
|
|
7250
|
+
/**
|
|
7251
|
+
* Normalize the given path string, returning a regular expression.
|
|
7252
|
+
*
|
|
7253
|
+
* An empty array can be passed in for the keys, which will hold the
|
|
7254
|
+
* placeholder key descriptions. For example, using `/user/:id`, `keys` will
|
|
7255
|
+
* contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
|
|
7256
|
+
*/
|
|
7257
|
+
function pathToRegexp(path, keys, options) {
|
|
7258
|
+
if (path instanceof RegExp)
|
|
7259
|
+
return regexpToRegexp(path, keys);
|
|
7260
|
+
if (Array.isArray(path))
|
|
7261
|
+
return arrayToRegexp(path, keys, options);
|
|
7262
|
+
return stringToRegexp(path, keys, options);
|
|
7284
7263
|
}
|
|
7285
|
-
getCleanUrl_2 = getCleanUrl$1.getCleanUrl = getCleanUrl;
|
|
7286
7264
|
|
|
7287
7265
|
const REDUNDANT_CHARACTERS_EXP = /[\?|#].*$/g;
|
|
7288
7266
|
function getSearchParams(path) {
|
|
@@ -7304,9 +7282,12 @@ function getAbsoluteUrl(path, baseUrl) {
|
|
|
7304
7282
|
return path;
|
|
7305
7283
|
}
|
|
7306
7284
|
// Resolve a relative request URL against a given custom "baseUrl"
|
|
7307
|
-
// or the
|
|
7308
|
-
const origin = baseUrl || (typeof
|
|
7309
|
-
return origin
|
|
7285
|
+
// or the document baseURI (in the case of browser/browser-like environments).
|
|
7286
|
+
const origin = baseUrl || (typeof document !== 'undefined' && document.baseURI);
|
|
7287
|
+
return origin
|
|
7288
|
+
? // Encode and decode the path to preserve escaped characters.
|
|
7289
|
+
decodeURI(new URL(encodeURI(path), origin).href)
|
|
7290
|
+
: path;
|
|
7310
7291
|
}
|
|
7311
7292
|
|
|
7312
7293
|
/**
|
|
@@ -7325,12 +7306,40 @@ function normalizePath(path, baseUrl) {
|
|
|
7325
7306
|
return cleanUrl(maybeAbsoluteUrl);
|
|
7326
7307
|
}
|
|
7327
7308
|
|
|
7309
|
+
/**
|
|
7310
|
+
* Coerce a path supported by MSW into a path
|
|
7311
|
+
* supported by "path-to-regexp".
|
|
7312
|
+
*/
|
|
7313
|
+
function coercePath(path) {
|
|
7314
|
+
return (path
|
|
7315
|
+
/**
|
|
7316
|
+
* Escape the protocol so that "path-to-regexp" could match
|
|
7317
|
+
* absolute URL.
|
|
7318
|
+
* @see https://github.com/pillarjs/path-to-regexp/issues/259
|
|
7319
|
+
*/
|
|
7320
|
+
.replace(/^([^\/]+)(:)(?=\/\/)/g, '$1\\$2')
|
|
7321
|
+
/**
|
|
7322
|
+
* Replace wildcards ("*") with unnamed capturing groups
|
|
7323
|
+
* because "path-to-regexp" doesn't support wildcards.
|
|
7324
|
+
* Ignore path parameter' modifiers (i.e. ":name*").
|
|
7325
|
+
*/
|
|
7326
|
+
.replace(/(?<!(^|\/|\*+):[\w]+)(\*{1,2})/g, '(.*)'));
|
|
7327
|
+
}
|
|
7328
7328
|
/**
|
|
7329
7329
|
* Returns the result of matching given request URL against a mask.
|
|
7330
7330
|
*/
|
|
7331
7331
|
function matchRequestUrl(url, path, baseUrl) {
|
|
7332
7332
|
const normalizedPath = normalizePath(path, baseUrl);
|
|
7333
|
-
|
|
7333
|
+
const cleanPath = typeof normalizedPath === 'string'
|
|
7334
|
+
? coercePath(normalizedPath)
|
|
7335
|
+
: normalizedPath;
|
|
7336
|
+
const cleanUrl = getCleanUrl.getCleanUrl(url);
|
|
7337
|
+
const result = match(cleanPath, { decode: decodeURIComponent })(cleanUrl);
|
|
7338
|
+
const params = (result && result.params) || {};
|
|
7339
|
+
return {
|
|
7340
|
+
matches: result !== false,
|
|
7341
|
+
params,
|
|
7342
|
+
};
|
|
7334
7343
|
}
|
|
7335
7344
|
|
|
7336
7345
|
/**
|
|
@@ -7365,7 +7374,7 @@ const defaultResponseTransformers = [];
|
|
|
7365
7374
|
function createResponseComposition(responseOverrides, defaultTransformers = defaultResponseTransformers) {
|
|
7366
7375
|
return (...transformers) => __awaiter(this, void 0, void 0, function* () {
|
|
7367
7376
|
const initialResponse = Object.assign({}, defaultResponse, {
|
|
7368
|
-
headers: new lib$
|
|
7377
|
+
headers: new lib$1.Headers({
|
|
7369
7378
|
'x-powered-by': 'msw',
|
|
7370
7379
|
}),
|
|
7371
7380
|
}, responseOverrides);
|
|
@@ -7386,18 +7395,21 @@ const response = Object.assign(createResponseComposition(), {
|
|
|
7386
7395
|
},
|
|
7387
7396
|
});
|
|
7388
7397
|
|
|
7398
|
+
const BUILD_FRAME = /(node_modules)?[\/\\]lib[\/\\](umd|esm|iief|cjs)[\/\\]|^[^\/\\]*$/;
|
|
7389
7399
|
/**
|
|
7390
7400
|
* Return the stack trace frame of a function's invocation.
|
|
7391
7401
|
*/
|
|
7392
|
-
function getCallFrame() {
|
|
7402
|
+
function getCallFrame(error) {
|
|
7393
7403
|
// In <IE11, new Error may return an undefined stack
|
|
7394
|
-
const stack =
|
|
7395
|
-
|
|
7404
|
+
const stack = error.stack;
|
|
7405
|
+
if (!stack) {
|
|
7406
|
+
return;
|
|
7407
|
+
}
|
|
7408
|
+
const frames = stack.split('\n').slice(1);
|
|
7396
7409
|
// Get the first frame that doesn't reference the library's internal trace.
|
|
7397
7410
|
// Assume that frame is the invocation frame.
|
|
7398
|
-
const
|
|
7399
|
-
|
|
7400
|
-
return !ignoreFrameRegExp.test(frame);
|
|
7411
|
+
const declarationFrame = frames.find((frame) => {
|
|
7412
|
+
return !BUILD_FRAME.test(frame);
|
|
7401
7413
|
});
|
|
7402
7414
|
if (!declarationFrame) {
|
|
7403
7415
|
return;
|
|
@@ -7430,7 +7442,7 @@ class RequestHandler {
|
|
|
7430
7442
|
this.shouldSkip = false;
|
|
7431
7443
|
this.ctx = options.ctx || defaultContext;
|
|
7432
7444
|
this.resolver = options.resolver;
|
|
7433
|
-
const callFrame = getCallFrame();
|
|
7445
|
+
const callFrame = getCallFrame(new Error());
|
|
7434
7446
|
this.info = Object.assign(Object.assign({}, options.info), { callFrame });
|
|
7435
7447
|
}
|
|
7436
7448
|
/**
|
|
@@ -7557,21 +7569,9 @@ class RestHandler extends RequestHandler {
|
|
|
7557
7569
|
return;
|
|
7558
7570
|
}
|
|
7559
7571
|
const searchParams = getSearchParams(path);
|
|
7560
|
-
const queryParams = [];
|
|
7561
7572
|
searchParams.forEach((_, paramName) => {
|
|
7562
|
-
queryParams.push(paramName);
|
|
7563
7573
|
});
|
|
7564
|
-
devUtils.warn(
|
|
7565
|
-
Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead, and access query parameters in the response resolver function:
|
|
7566
|
-
|
|
7567
|
-
rest.${method.toLowerCase()}("${url}", (req, res, ctx) => {
|
|
7568
|
-
const query = req.url.searchParams
|
|
7569
|
-
${queryParams
|
|
7570
|
-
.map((paramName) => `\
|
|
7571
|
-
const ${paramName} = query.get("${paramName}")`)
|
|
7572
|
-
.join('\n')}
|
|
7573
|
-
})\
|
|
7574
|
-
`);
|
|
7574
|
+
devUtils.warn(`Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead and access query parameters in the response resolver function using "req.url.searchParams".`);
|
|
7575
7575
|
}
|
|
7576
7576
|
parse(request, resolutionContext) {
|
|
7577
7577
|
return matchRequestUrl(request.url, this.info.path, resolutionContext === null || resolutionContext === void 0 ? void 0 : resolutionContext.baseUrl);
|
|
@@ -7580,7 +7580,11 @@ ${queryParams
|
|
|
7580
7580
|
return Object.assign(Object.assign({}, request), { params: parsedResult.params || {} });
|
|
7581
7581
|
}
|
|
7582
7582
|
predicate(request, parsedResult) {
|
|
7583
|
-
|
|
7583
|
+
const matchesMethod = this.info.method instanceof RegExp
|
|
7584
|
+
? this.info.method.test(request.method)
|
|
7585
|
+
: isStringEqual(this.info.method, request.method);
|
|
7586
|
+
// console.log({ request, matchesMethod, parsedResult })
|
|
7587
|
+
return matchesMethod && parsedResult.matches;
|
|
7584
7588
|
}
|
|
7585
7589
|
log(request, response) {
|
|
7586
7590
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
@@ -7614,6 +7618,7 @@ const graphqlContext = {
|
|
|
7614
7618
|
delay,
|
|
7615
7619
|
fetch,
|
|
7616
7620
|
data,
|
|
7621
|
+
extensions,
|
|
7617
7622
|
errors,
|
|
7618
7623
|
cookie,
|
|
7619
7624
|
};
|
|
@@ -7660,10 +7665,10 @@ class GraphQLHandler extends RequestHandler {
|
|
|
7660
7665
|
if (!parsedResult) {
|
|
7661
7666
|
return false;
|
|
7662
7667
|
}
|
|
7663
|
-
if (!parsedResult.operationName) {
|
|
7668
|
+
if (!parsedResult.operationName && this.info.operationType !== 'all') {
|
|
7664
7669
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
7665
7670
|
devUtils.warn(`\
|
|
7666
|
-
Failed to intercept a GraphQL request at "${request.method} ${publicUrl}":
|
|
7671
|
+
Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
7667
7672
|
|
|
7668
7673
|
Consider naming this operation or using "graphql.operation" request handler to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/operation\
|
|
7669
7674
|
`);
|
|
@@ -7673,7 +7678,7 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
7673
7678
|
const hasMatchingOperationType = this.info.operationType === 'all' ||
|
|
7674
7679
|
parsedResult.operationType === this.info.operationType;
|
|
7675
7680
|
const hasMatchingOperationName = this.info.operationName instanceof RegExp
|
|
7676
|
-
? this.info.operationName.test(parsedResult.operationName)
|
|
7681
|
+
? this.info.operationName.test(parsedResult.operationName || '')
|
|
7677
7682
|
: parsedResult.operationName === this.info.operationName;
|
|
7678
7683
|
return (hasMatchingUrl.matches &&
|
|
7679
7684
|
hasMatchingOperationType &&
|
|
@@ -7683,7 +7688,10 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
7683
7688
|
const loggedRequest = prepareRequest(request);
|
|
7684
7689
|
const loggedResponse = prepareResponse(response);
|
|
7685
7690
|
const statusColor = getStatusCodeColor(response.status);
|
|
7686
|
-
|
|
7691
|
+
const requestInfo = (parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationName)
|
|
7692
|
+
? `${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationType} ${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationName}`
|
|
7693
|
+
: `anonymous ${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationType}`;
|
|
7694
|
+
console.groupCollapsed(devUtils.formatMessage('%s %s (%c%s%c)'), getTimestamp(), `${requestInfo}`, `color:${statusColor}`, `${response.status} ${response.statusText}`, 'color:inherit');
|
|
7687
7695
|
console.log('Request:', loggedRequest);
|
|
7688
7696
|
console.log('Handler:', this);
|
|
7689
7697
|
console.log('Response:', loggedResponse);
|
|
@@ -7797,8 +7805,10 @@ Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
|
7797
7805
|
const message = messageTemplate.join('\n\n');
|
|
7798
7806
|
switch (strategy) {
|
|
7799
7807
|
case 'error': {
|
|
7808
|
+
// Print a developer-friendly error.
|
|
7800
7809
|
devUtils.error('Error: %s', message);
|
|
7801
|
-
|
|
7810
|
+
// Throw an exception to halt request processing and not perform the original request.
|
|
7811
|
+
throw new Error('Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.');
|
|
7802
7812
|
}
|
|
7803
7813
|
case 'warn': {
|
|
7804
7814
|
devUtils.warn('Warning: %s', message);
|
|
@@ -7812,8 +7822,8 @@ Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
|
7812
7822
|
}
|
|
7813
7823
|
|
|
7814
7824
|
function readResponseCookies(request, response) {
|
|
7815
|
-
|
|
7816
|
-
|
|
7825
|
+
cookies.store.add(Object.assign(Object.assign({}, request), { url: request.url.toString() }), response);
|
|
7826
|
+
cookies.store.persist();
|
|
7817
7827
|
}
|
|
7818
7828
|
|
|
7819
7829
|
function handleRequest(request, handlers, options, emitter, handleRequestOptions) {
|
|
@@ -7841,7 +7851,12 @@ function handleRequest(request, handlers, options, emitter, handleRequestOptions
|
|
|
7841
7851
|
// When the handled request returned no mocked response, warn the developer,
|
|
7842
7852
|
// as it may be an oversight on their part. Perform the request as-is.
|
|
7843
7853
|
if (!response) {
|
|
7844
|
-
devUtils.warn(
|
|
7854
|
+
devUtils.warn(`\
|
|
7855
|
+
Expected response resolver to return a mocked response Object, but got %s. The original response is going to be used instead.\
|
|
7856
|
+
\n
|
|
7857
|
+
\u2022 %s
|
|
7858
|
+
%s\
|
|
7859
|
+
`, response, handler.info.header, handler.info.callFrame);
|
|
7845
7860
|
emitter.emit('request:end', request);
|
|
7846
7861
|
(_c = handleRequestOptions === null || handleRequestOptions === void 0 ? void 0 : handleRequestOptions.onBypassResponse) === null || _c === void 0 ? void 0 : _c.call(handleRequestOptions, request);
|
|
7847
7862
|
return;
|
|
@@ -7865,6 +7880,23 @@ function handleRequest(request, handlers, options, emitter, handleRequestOptions
|
|
|
7865
7880
|
});
|
|
7866
7881
|
}
|
|
7867
7882
|
|
|
7883
|
+
/**
|
|
7884
|
+
* Pipes all emitted events from one emitter to another.
|
|
7885
|
+
*/
|
|
7886
|
+
function pipeEvents(source, destination) {
|
|
7887
|
+
const rawEmit = source.emit;
|
|
7888
|
+
// @ts-ignore
|
|
7889
|
+
if (rawEmit._isPiped) {
|
|
7890
|
+
return;
|
|
7891
|
+
}
|
|
7892
|
+
source.emit = function (event, ...data) {
|
|
7893
|
+
destination.emit(event, ...data);
|
|
7894
|
+
return rawEmit.call(this, event, ...data);
|
|
7895
|
+
};
|
|
7896
|
+
// @ts-ignore
|
|
7897
|
+
source.emit._isPiped = true;
|
|
7898
|
+
}
|
|
7899
|
+
|
|
7868
7900
|
const DEFAULT_LISTEN_OPTIONS = {
|
|
7869
7901
|
onUnhandledRequest: 'warn',
|
|
7870
7902
|
};
|
|
@@ -7873,7 +7905,9 @@ const DEFAULT_LISTEN_OPTIONS = {
|
|
|
7873
7905
|
* Useful to generate identical API using different patches to request issuing modules.
|
|
7874
7906
|
*/
|
|
7875
7907
|
function createSetupServer(...interceptors$1) {
|
|
7876
|
-
const emitter = new lib$
|
|
7908
|
+
const emitter = new lib$2.StrictEventEmitter();
|
|
7909
|
+
const publicEmitter = new lib$2.StrictEventEmitter();
|
|
7910
|
+
pipeEvents(emitter, publicEmitter);
|
|
7877
7911
|
return function setupServer(...requestHandlers) {
|
|
7878
7912
|
requestHandlers.forEach((handler) => {
|
|
7879
7913
|
if (Array.isArray(handler))
|
|
@@ -7883,7 +7917,7 @@ function createSetupServer(...interceptors$1) {
|
|
|
7883
7917
|
// so it could be modified at a runtime.
|
|
7884
7918
|
let currentHandlers = [...requestHandlers];
|
|
7885
7919
|
// Error when attempting to run this function in a browser environment.
|
|
7886
|
-
if (!lib$
|
|
7920
|
+
if (!lib$3.exports.isNodeProcess()) {
|
|
7887
7921
|
throw new Error(devUtils.formatMessage('Failed to execute `setupServer` in the environment that is not Node.js (i.e. a browser). Consider using `setupWorker` instead.'));
|
|
7888
7922
|
}
|
|
7889
7923
|
let resolvedOptions = {};
|
|
@@ -7943,11 +7977,20 @@ ${source.bold(`${pragma} ${header}`)}
|
|
|
7943
7977
|
`);
|
|
7944
7978
|
});
|
|
7945
7979
|
},
|
|
7946
|
-
|
|
7947
|
-
|
|
7980
|
+
events: {
|
|
7981
|
+
on(...args) {
|
|
7982
|
+
return publicEmitter.on(...args);
|
|
7983
|
+
},
|
|
7984
|
+
removeListener(...args) {
|
|
7985
|
+
return publicEmitter.removeListener(...args);
|
|
7986
|
+
},
|
|
7987
|
+
removeAllListeners(...args) {
|
|
7988
|
+
return publicEmitter.removeAllListeners(...args);
|
|
7989
|
+
},
|
|
7948
7990
|
},
|
|
7949
7991
|
close() {
|
|
7950
7992
|
emitter.removeAllListeners();
|
|
7993
|
+
publicEmitter.removeAllListeners();
|
|
7951
7994
|
interceptor.restore();
|
|
7952
7995
|
},
|
|
7953
7996
|
};
|