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/lib/esm/graphql-deps.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { j as jsonParse, b as set, s as status, e as delay, f as fetch, d as cookie } from './fetch-deps.js';
|
|
2
|
-
import { d as data, e as errors } from './errors-deps.js';
|
|
3
|
-
import { g as getPublicUrlFromRequest, d as devUtils,
|
|
2
|
+
import { d as data, e as extensions, a as errors } from './errors-deps.js';
|
|
3
|
+
import { g as getPublicUrlFromRequest, d as devUtils, n as __rest, R as RequestHandler, m as matchRequestUrl, i as prepareRequest, j as prepareResponse, k as getStatusCodeColor, l as getTimestamp } from './RequestHandler-deps.js';
|
|
4
4
|
|
|
5
5
|
function _typeof$3(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$3 = function _typeof(obj) { return typeof obj; }; } else { _typeof$3 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$3(obj); }
|
|
6
6
|
|
|
@@ -457,6 +457,7 @@ function invariant(condition, message) {
|
|
|
457
457
|
|
|
458
458
|
// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
459
459
|
var nodejsCustomInspectSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined;
|
|
460
|
+
var nodejsCustomInspectSymbol$1 = nodejsCustomInspectSymbol;
|
|
460
461
|
|
|
461
462
|
/**
|
|
462
463
|
* The `defineInspect()` function defines `inspect()` prototype method as alias of `toJSON`
|
|
@@ -467,8 +468,8 @@ function defineInspect(classObject) {
|
|
|
467
468
|
typeof fn === 'function' || invariant(0);
|
|
468
469
|
classObject.prototype.inspect = fn; // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
469
470
|
|
|
470
|
-
if (nodejsCustomInspectSymbol) {
|
|
471
|
-
classObject.prototype[nodejsCustomInspectSymbol] = fn;
|
|
471
|
+
if (nodejsCustomInspectSymbol$1) {
|
|
472
|
+
classObject.prototype[nodejsCustomInspectSymbol$1] = fn;
|
|
472
473
|
}
|
|
473
474
|
}
|
|
474
475
|
|
|
@@ -711,7 +712,7 @@ function formatArray(array, seenValues) {
|
|
|
711
712
|
}
|
|
712
713
|
|
|
713
714
|
function getCustomFn(object) {
|
|
714
|
-
var customInspectFn = object[String(nodejsCustomInspectSymbol)];
|
|
715
|
+
var customInspectFn = object[String(nodejsCustomInspectSymbol$1)];
|
|
715
716
|
|
|
716
717
|
if (typeof customInspectFn === 'function') {
|
|
717
718
|
return customInspectFn;
|
|
@@ -3217,7 +3218,7 @@ function parseGraphQLRequest(request) {
|
|
|
3217
3218
|
const parsedResult = parseQuery(query);
|
|
3218
3219
|
if (parsedResult instanceof Error) {
|
|
3219
3220
|
const requestPublicUrl = getPublicUrlFromRequest(request);
|
|
3220
|
-
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%
|
|
3221
|
+
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));
|
|
3221
3222
|
}
|
|
3222
3223
|
return {
|
|
3223
3224
|
operationType: parsedResult.operationType,
|
|
@@ -3242,6 +3243,7 @@ const graphqlContext = {
|
|
|
3242
3243
|
delay,
|
|
3243
3244
|
fetch,
|
|
3244
3245
|
data,
|
|
3246
|
+
extensions,
|
|
3245
3247
|
errors,
|
|
3246
3248
|
cookie,
|
|
3247
3249
|
};
|
|
@@ -3288,10 +3290,10 @@ class GraphQLHandler extends RequestHandler {
|
|
|
3288
3290
|
if (!parsedResult) {
|
|
3289
3291
|
return false;
|
|
3290
3292
|
}
|
|
3291
|
-
if (!parsedResult.operationName) {
|
|
3293
|
+
if (!parsedResult.operationName && this.info.operationType !== 'all') {
|
|
3292
3294
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
3293
3295
|
devUtils.warn(`\
|
|
3294
|
-
Failed to intercept a GraphQL request at "${request.method} ${publicUrl}":
|
|
3296
|
+
Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
3295
3297
|
|
|
3296
3298
|
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\
|
|
3297
3299
|
`);
|
|
@@ -3301,7 +3303,7 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
3301
3303
|
const hasMatchingOperationType = this.info.operationType === 'all' ||
|
|
3302
3304
|
parsedResult.operationType === this.info.operationType;
|
|
3303
3305
|
const hasMatchingOperationName = this.info.operationName instanceof RegExp
|
|
3304
|
-
? this.info.operationName.test(parsedResult.operationName)
|
|
3306
|
+
? this.info.operationName.test(parsedResult.operationName || '')
|
|
3305
3307
|
: parsedResult.operationName === this.info.operationName;
|
|
3306
3308
|
return (hasMatchingUrl.matches &&
|
|
3307
3309
|
hasMatchingOperationType &&
|
|
@@ -3311,7 +3313,10 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
3311
3313
|
const loggedRequest = prepareRequest(request);
|
|
3312
3314
|
const loggedResponse = prepareResponse(response);
|
|
3313
3315
|
const statusColor = getStatusCodeColor(response.status);
|
|
3314
|
-
|
|
3316
|
+
const requestInfo = (parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationName)
|
|
3317
|
+
? `${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationType} ${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationName}`
|
|
3318
|
+
: `anonymous ${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationType}`;
|
|
3319
|
+
console.groupCollapsed(devUtils.formatMessage('%s %s (%c%s%c)'), getTimestamp(), `${requestInfo}`, `color:${statusColor}`, `${response.status} ${response.statusText}`, 'color:inherit');
|
|
3315
3320
|
console.log('Request:', loggedRequest);
|
|
3316
3321
|
console.log('Handler:', this);
|
|
3317
3322
|
console.log('Response:', loggedResponse);
|
package/lib/esm/graphql.js
CHANGED
package/lib/esm/index-deps.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { s as status, b as set, d as cookie, e as delay, f as fetch, g as json } from './fetch-deps.js';
|
|
2
2
|
import { b as body, t as text, x as xml } from './xml-deps.js';
|
|
3
|
-
import { d as data, e as errors } from './errors-deps.js';
|
|
3
|
+
import { d as data, e as extensions, a as errors } from './errors-deps.js';
|
|
4
4
|
|
|
5
5
|
var index = /*#__PURE__*/Object.freeze({
|
|
6
6
|
__proto__: null,
|
|
@@ -9,6 +9,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
9
9
|
cookie: cookie,
|
|
10
10
|
body: body,
|
|
11
11
|
data: data,
|
|
12
|
+
extensions: extensions,
|
|
12
13
|
delay: delay,
|
|
13
14
|
errors: errors,
|
|
14
15
|
fetch: fetch,
|