msw 0.34.0 → 0.35.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 +4 -1
- package/lib/esm/graphql-deps.js +3 -4
- package/lib/esm/index.js +523 -122
- package/lib/esm/mockServiceWorker.js +1 -1
- package/lib/iife/index.js +3 -3
- package/lib/iife/mockServiceWorker.js +1 -1
- package/lib/types/node/glossary.d.ts +4 -14
- package/lib/types/setupWorker/glossary.d.ts +4 -14
- package/lib/types/sharedOptions.d.ts +11 -0
- package/lib/types/utils/internal/pipeEvents.d.ts +6 -0
- package/lib/umd/index.js +527 -123
- package/lib/umd/mockServiceWorker.js +1 -1
- package/native/lib/index.js +40 -8
- package/node/lib/index.js +40 -8
- package/package.json +2 -2
package/native/lib/index.js
CHANGED
|
@@ -2228,7 +2228,6 @@ function invariant(condition, message) {
|
|
|
2228
2228
|
|
|
2229
2229
|
// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
2230
2230
|
var nodejsCustomInspectSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined;
|
|
2231
|
-
var nodejsCustomInspectSymbol$1 = nodejsCustomInspectSymbol;
|
|
2232
2231
|
|
|
2233
2232
|
/**
|
|
2234
2233
|
* The `defineInspect()` function defines `inspect()` prototype method as alias of `toJSON`
|
|
@@ -2239,8 +2238,8 @@ function defineInspect(classObject) {
|
|
|
2239
2238
|
typeof fn === 'function' || invariant(0);
|
|
2240
2239
|
classObject.prototype.inspect = fn; // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
2241
2240
|
|
|
2242
|
-
if (nodejsCustomInspectSymbol
|
|
2243
|
-
classObject.prototype[nodejsCustomInspectSymbol
|
|
2241
|
+
if (nodejsCustomInspectSymbol) {
|
|
2242
|
+
classObject.prototype[nodejsCustomInspectSymbol] = fn;
|
|
2244
2243
|
}
|
|
2245
2244
|
}
|
|
2246
2245
|
|
|
@@ -2483,7 +2482,7 @@ function formatArray(array, seenValues) {
|
|
|
2483
2482
|
}
|
|
2484
2483
|
|
|
2485
2484
|
function getCustomFn(object) {
|
|
2486
|
-
var customInspectFn = object[String(nodejsCustomInspectSymbol
|
|
2485
|
+
var customInspectFn = object[String(nodejsCustomInspectSymbol)];
|
|
2487
2486
|
|
|
2488
2487
|
if (typeof customInspectFn === 'function') {
|
|
2489
2488
|
return customInspectFn;
|
|
@@ -5469,7 +5468,10 @@ function getAbsoluteUrl(path, baseUrl) {
|
|
|
5469
5468
|
// Resolve a relative request URL against a given custom "baseUrl"
|
|
5470
5469
|
// or the current location (in the case of browser/browser-like environments).
|
|
5471
5470
|
const origin = baseUrl || (typeof location !== 'undefined' && location.origin);
|
|
5472
|
-
return origin
|
|
5471
|
+
return origin
|
|
5472
|
+
? // Encode and decode the path to preserve escaped characters.
|
|
5473
|
+
decodeURI(new URL(encodeURI(path), origin).href)
|
|
5474
|
+
: path;
|
|
5473
5475
|
}
|
|
5474
5476
|
|
|
5475
5477
|
/**
|
|
@@ -5960,8 +5962,10 @@ Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
|
5960
5962
|
const message = messageTemplate.join('\n\n');
|
|
5961
5963
|
switch (strategy) {
|
|
5962
5964
|
case 'error': {
|
|
5965
|
+
// Print a developer-friendly error.
|
|
5963
5966
|
devUtils.error('Error: %s', message);
|
|
5964
|
-
|
|
5967
|
+
// Throw an exception to halt request processing and not perform the original request.
|
|
5968
|
+
throw new Error('Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.');
|
|
5965
5969
|
}
|
|
5966
5970
|
case 'warn': {
|
|
5967
5971
|
devUtils.warn('Warning: %s', message);
|
|
@@ -6028,6 +6032,23 @@ function handleRequest(request, handlers, options, emitter, handleRequestOptions
|
|
|
6028
6032
|
});
|
|
6029
6033
|
}
|
|
6030
6034
|
|
|
6035
|
+
/**
|
|
6036
|
+
* Pipes all emitted events from one emitter to another.
|
|
6037
|
+
*/
|
|
6038
|
+
function pipeEvents(source, destination) {
|
|
6039
|
+
const rawEmit = source.emit;
|
|
6040
|
+
// @ts-ignore
|
|
6041
|
+
if (rawEmit._isPiped) {
|
|
6042
|
+
return;
|
|
6043
|
+
}
|
|
6044
|
+
source.emit = function (event, ...data) {
|
|
6045
|
+
destination.emit(event, ...data);
|
|
6046
|
+
return rawEmit.call(this, event, ...data);
|
|
6047
|
+
};
|
|
6048
|
+
// @ts-ignore
|
|
6049
|
+
source.emit._isPiped = true;
|
|
6050
|
+
}
|
|
6051
|
+
|
|
6031
6052
|
const DEFAULT_LISTEN_OPTIONS = {
|
|
6032
6053
|
onUnhandledRequest: 'warn',
|
|
6033
6054
|
};
|
|
@@ -6037,6 +6058,8 @@ const DEFAULT_LISTEN_OPTIONS = {
|
|
|
6037
6058
|
*/
|
|
6038
6059
|
function createSetupServer(...interceptors$1) {
|
|
6039
6060
|
const emitter = new lib$3.StrictEventEmitter();
|
|
6061
|
+
const publicEmitter = new lib$3.StrictEventEmitter();
|
|
6062
|
+
pipeEvents(emitter, publicEmitter);
|
|
6040
6063
|
return function setupServer(...requestHandlers) {
|
|
6041
6064
|
requestHandlers.forEach((handler) => {
|
|
6042
6065
|
if (Array.isArray(handler))
|
|
@@ -6106,11 +6129,20 @@ ${chalk.bold(`${pragma} ${header}`)}
|
|
|
6106
6129
|
`);
|
|
6107
6130
|
});
|
|
6108
6131
|
},
|
|
6109
|
-
|
|
6110
|
-
|
|
6132
|
+
events: {
|
|
6133
|
+
on(...args) {
|
|
6134
|
+
return publicEmitter.on(...args);
|
|
6135
|
+
},
|
|
6136
|
+
removeListener(...args) {
|
|
6137
|
+
return publicEmitter.removeListener(...args);
|
|
6138
|
+
},
|
|
6139
|
+
removeAllListeners(...args) {
|
|
6140
|
+
return publicEmitter.removeAllListeners(...args);
|
|
6141
|
+
},
|
|
6111
6142
|
},
|
|
6112
6143
|
close() {
|
|
6113
6144
|
emitter.removeAllListeners();
|
|
6145
|
+
publicEmitter.removeAllListeners();
|
|
6114
6146
|
interceptor.restore();
|
|
6115
6147
|
},
|
|
6116
6148
|
};
|
package/node/lib/index.js
CHANGED
|
@@ -4114,7 +4114,6 @@ function invariant(condition, message) {
|
|
|
4114
4114
|
|
|
4115
4115
|
// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
4116
4116
|
var nodejsCustomInspectSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined;
|
|
4117
|
-
var nodejsCustomInspectSymbol$1 = nodejsCustomInspectSymbol;
|
|
4118
4117
|
|
|
4119
4118
|
/**
|
|
4120
4119
|
* The `defineInspect()` function defines `inspect()` prototype method as alias of `toJSON`
|
|
@@ -4125,8 +4124,8 @@ function defineInspect(classObject) {
|
|
|
4125
4124
|
typeof fn === 'function' || invariant(0);
|
|
4126
4125
|
classObject.prototype.inspect = fn; // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
4127
4126
|
|
|
4128
|
-
if (nodejsCustomInspectSymbol
|
|
4129
|
-
classObject.prototype[nodejsCustomInspectSymbol
|
|
4127
|
+
if (nodejsCustomInspectSymbol) {
|
|
4128
|
+
classObject.prototype[nodejsCustomInspectSymbol] = fn;
|
|
4130
4129
|
}
|
|
4131
4130
|
}
|
|
4132
4131
|
|
|
@@ -4369,7 +4368,7 @@ function formatArray(array, seenValues) {
|
|
|
4369
4368
|
}
|
|
4370
4369
|
|
|
4371
4370
|
function getCustomFn(object) {
|
|
4372
|
-
var customInspectFn = object[String(nodejsCustomInspectSymbol
|
|
4371
|
+
var customInspectFn = object[String(nodejsCustomInspectSymbol)];
|
|
4373
4372
|
|
|
4374
4373
|
if (typeof customInspectFn === 'function') {
|
|
4375
4374
|
return customInspectFn;
|
|
@@ -7355,7 +7354,10 @@ function getAbsoluteUrl(path, baseUrl) {
|
|
|
7355
7354
|
// Resolve a relative request URL against a given custom "baseUrl"
|
|
7356
7355
|
// or the current location (in the case of browser/browser-like environments).
|
|
7357
7356
|
const origin = baseUrl || (typeof location !== 'undefined' && location.origin);
|
|
7358
|
-
return origin
|
|
7357
|
+
return origin
|
|
7358
|
+
? // Encode and decode the path to preserve escaped characters.
|
|
7359
|
+
decodeURI(new URL(encodeURI(path), origin).href)
|
|
7360
|
+
: path;
|
|
7359
7361
|
}
|
|
7360
7362
|
|
|
7361
7363
|
/**
|
|
@@ -7846,8 +7848,10 @@ Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
|
7846
7848
|
const message = messageTemplate.join('\n\n');
|
|
7847
7849
|
switch (strategy) {
|
|
7848
7850
|
case 'error': {
|
|
7851
|
+
// Print a developer-friendly error.
|
|
7849
7852
|
devUtils.error('Error: %s', message);
|
|
7850
|
-
|
|
7853
|
+
// Throw an exception to halt request processing and not perform the original request.
|
|
7854
|
+
throw new Error('Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.');
|
|
7851
7855
|
}
|
|
7852
7856
|
case 'warn': {
|
|
7853
7857
|
devUtils.warn('Warning: %s', message);
|
|
@@ -7914,6 +7918,23 @@ function handleRequest(request, handlers, options, emitter, handleRequestOptions
|
|
|
7914
7918
|
});
|
|
7915
7919
|
}
|
|
7916
7920
|
|
|
7921
|
+
/**
|
|
7922
|
+
* Pipes all emitted events from one emitter to another.
|
|
7923
|
+
*/
|
|
7924
|
+
function pipeEvents(source, destination) {
|
|
7925
|
+
const rawEmit = source.emit;
|
|
7926
|
+
// @ts-ignore
|
|
7927
|
+
if (rawEmit._isPiped) {
|
|
7928
|
+
return;
|
|
7929
|
+
}
|
|
7930
|
+
source.emit = function (event, ...data) {
|
|
7931
|
+
destination.emit(event, ...data);
|
|
7932
|
+
return rawEmit.call(this, event, ...data);
|
|
7933
|
+
};
|
|
7934
|
+
// @ts-ignore
|
|
7935
|
+
source.emit._isPiped = true;
|
|
7936
|
+
}
|
|
7937
|
+
|
|
7917
7938
|
const DEFAULT_LISTEN_OPTIONS = {
|
|
7918
7939
|
onUnhandledRequest: 'warn',
|
|
7919
7940
|
};
|
|
@@ -7923,6 +7944,8 @@ const DEFAULT_LISTEN_OPTIONS = {
|
|
|
7923
7944
|
*/
|
|
7924
7945
|
function createSetupServer(...interceptors$1) {
|
|
7925
7946
|
const emitter = new lib$3.StrictEventEmitter();
|
|
7947
|
+
const publicEmitter = new lib$3.StrictEventEmitter();
|
|
7948
|
+
pipeEvents(emitter, publicEmitter);
|
|
7926
7949
|
return function setupServer(...requestHandlers) {
|
|
7927
7950
|
requestHandlers.forEach((handler) => {
|
|
7928
7951
|
if (Array.isArray(handler))
|
|
@@ -7992,11 +8015,20 @@ ${source.bold(`${pragma} ${header}`)}
|
|
|
7992
8015
|
`);
|
|
7993
8016
|
});
|
|
7994
8017
|
},
|
|
7995
|
-
|
|
7996
|
-
|
|
8018
|
+
events: {
|
|
8019
|
+
on(...args) {
|
|
8020
|
+
return publicEmitter.on(...args);
|
|
8021
|
+
},
|
|
8022
|
+
removeListener(...args) {
|
|
8023
|
+
return publicEmitter.removeListener(...args);
|
|
8024
|
+
},
|
|
8025
|
+
removeAllListeners(...args) {
|
|
8026
|
+
return publicEmitter.removeAllListeners(...args);
|
|
8027
|
+
},
|
|
7997
8028
|
},
|
|
7998
8029
|
close() {
|
|
7999
8030
|
emitter.removeAllListeners();
|
|
8031
|
+
publicEmitter.removeAllListeners();
|
|
8000
8032
|
interceptor.restore();
|
|
8001
8033
|
},
|
|
8002
8034
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
|
|
5
5
|
"main": "lib/umd/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"sideEffects": false,
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@mswjs/cookies": "^0.1.6",
|
|
68
|
-
"@mswjs/interceptors": "^0.12.
|
|
68
|
+
"@mswjs/interceptors": "^0.12.6",
|
|
69
69
|
"@open-draft/until": "^1.0.3",
|
|
70
70
|
"@types/cookie": "^0.4.1",
|
|
71
71
|
"@types/inquirer": "^7.3.3",
|