msw 0.0.0-fetch.rc-20 → 0.0.0-fetch.rc-22
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/README.md +5 -2
- package/lib/browser/index.d.ts +21 -8
- package/lib/browser/index.js +14 -6
- package/lib/browser/index.mjs +14 -6
- package/lib/core/{GraphQLHandler-ef45ae39.d.ts → GraphQLHandler-a441dd03.d.ts} +18 -6
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/{RequestHandler-7c716cf7.d.ts → RequestHandler-b59044ae.d.ts} +36 -10
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/bypass.d.ts +3 -1
- package/lib/core/delay.d.ts +3 -0
- package/lib/core/graphql.d.ts +62 -30
- package/lib/core/graphql.js +30 -14
- package/lib/core/graphql.mjs +30 -14
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.js +23 -18
- package/lib/core/handlers/GraphQLHandler.mjs +23 -18
- package/lib/core/handlers/HttpHandler.d.ts +17 -5
- package/lib/core/handlers/HttpHandler.js +16 -15
- package/lib/core/handlers/HttpHandler.mjs +16 -15
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js +37 -30
- package/lib/core/handlers/RequestHandler.mjs +37 -30
- package/lib/core/http.d.ts +10 -1
- package/lib/core/index.d.ts +2 -2
- package/lib/core/passthrough.d.ts +3 -1
- package/lib/core/sharedOptions.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/getResponse.d.ts +1 -1
- package/lib/core/utils/getResponse.js +2 -2
- package/lib/core/utils/getResponse.mjs +2 -2
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/utils/request/onUnhandledRequest.d.ts +1 -1
- package/lib/core/utils/request/onUnhandledRequest.js +1 -1
- package/lib/core/utils/request/onUnhandledRequest.mjs +1 -1
- package/lib/iife/index.js +279 -138
- package/lib/mockServiceWorker.js +3 -3
- package/lib/native/index.d.ts +20 -7
- package/lib/native/index.js +5 -0
- package/lib/native/index.mjs +5 -0
- package/lib/node/index.d.ts +20 -7
- package/lib/node/index.js +5 -0
- package/lib/node/index.mjs +5 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
> [!IMPORTANT]\
|
|
2
|
+
> **MSW 2.0 is finally here! 🎉** Read the [Release notes](https://github.com/mswjs/msw/releases/tag/v2.0.0) and please follow the [**Migration guidelines**](https://mswjs.io/docs/migrations/1.x-to-2.x) to upgrade. If you're having any questions while upgrading, please reach out in our [Discord server](https://discord.gg/z29WbnfDC5).
|
|
3
|
+
|
|
1
4
|
<br />
|
|
2
5
|
|
|
3
6
|
<p align="center">
|
|
@@ -25,7 +28,7 @@
|
|
|
25
28
|
|
|
26
29
|
- **Seamless**. A dedicated layer of requests interception at your disposal. Keep your application's code and tests unaware of whether something is mocked or not.
|
|
27
30
|
- **Deviation-free**. Request the same production resources and test the actual behavior of your app. Augment an existing API, or design it as you go when there is none.
|
|
28
|
-
- **Familiar & Powerful**. Use [Express](https://github.com/expressjs/express)-like routing syntax to
|
|
31
|
+
- **Familiar & Powerful**. Use [Express](https://github.com/expressjs/express)-like routing syntax to intercept requests. Use parameters, wildcards, and regular expressions to match requests, and respond with necessary status codes, headers, cookies, delays, or completely custom resolvers.
|
|
29
32
|
|
|
30
33
|
---
|
|
31
34
|
|
|
@@ -53,7 +56,7 @@ This README will give you a brief overview on the library but there's no better
|
|
|
53
56
|
|
|
54
57
|
### How does it work?
|
|
55
58
|
|
|
56
|
-
In-browser usage is what sets Mock Service Worker apart from other tools. Utilizing the [Service Worker API](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API), which can intercept requests for the purpose of caching, Mock Service Worker responds to
|
|
59
|
+
In-browser usage is what sets Mock Service Worker apart from other tools. Utilizing the [Service Worker API](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API), which can intercept requests for the purpose of caching, Mock Service Worker responds to intercepted requests with your mock definition on the network level. This way your application knows nothing about the mocking.
|
|
57
60
|
|
|
58
61
|
**Take a look at this quick presentation on how Mock Service Worker functions in a browser:**
|
|
59
62
|
|
package/lib/browser/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ interface StartOptions extends SharedOptions {
|
|
|
16
16
|
options?: RegistrationOptions;
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
* Disables the logging of
|
|
19
|
+
* Disables the logging of the intercepted requests
|
|
20
20
|
* into browser's console.
|
|
21
21
|
* @default false
|
|
22
22
|
*/
|
|
@@ -38,36 +38,48 @@ type StopHandler = () => void;
|
|
|
38
38
|
interface SetupWorker {
|
|
39
39
|
/**
|
|
40
40
|
* Registers and activates the mock Service Worker.
|
|
41
|
-
*
|
|
41
|
+
*
|
|
42
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker/start `worker.start()` API reference}
|
|
42
43
|
*/
|
|
43
44
|
start: (options?: StartOptions) => StartReturnType;
|
|
44
45
|
/**
|
|
45
46
|
* Stops requests interception for the current client.
|
|
46
|
-
*
|
|
47
|
+
*
|
|
48
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker/stop `worker.stop()` API reference}
|
|
47
49
|
*/
|
|
48
50
|
stop: StopHandler;
|
|
49
51
|
/**
|
|
50
52
|
* Prepends given request handlers to the list of existing handlers.
|
|
51
53
|
* @param {RequestHandler[]} handlers List of runtime request handlers.
|
|
52
|
-
*
|
|
54
|
+
*
|
|
55
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker/use `worker.use()` API reference}
|
|
53
56
|
*/
|
|
54
57
|
use: (...handlers: RequestHandler[]) => void;
|
|
55
58
|
/**
|
|
56
59
|
* Marks all request handlers that respond using `res.once()` as unused.
|
|
57
|
-
*
|
|
60
|
+
*
|
|
61
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker/restore-handlers `worker.restoreHandlers()` API reference}
|
|
58
62
|
*/
|
|
59
63
|
restoreHandlers: () => void;
|
|
60
64
|
/**
|
|
61
65
|
* Resets request handlers to the initial list given to the `setupWorker` call, or to the explicit next request handlers list, if given.
|
|
62
66
|
* @param {RequestHandler[]} nextHandlers List of the new initial request handlers.
|
|
63
|
-
*
|
|
67
|
+
*
|
|
68
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker/reset-handlers `worker.resetHandlers()` API reference}
|
|
64
69
|
*/
|
|
65
70
|
resetHandlers: (...nextHandlers: RequestHandler[]) => void;
|
|
66
71
|
/**
|
|
67
72
|
* Returns a readonly list of currently active request handlers.
|
|
68
|
-
*
|
|
73
|
+
*
|
|
74
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker/list-handlers `worker.listHandlers()` API reference}
|
|
69
75
|
*/
|
|
70
76
|
listHandlers(): ReadonlyArray<RequestHandler<RequestHandlerDefaultInfo, any>>;
|
|
77
|
+
/**
|
|
78
|
+
* Life-cycle events.
|
|
79
|
+
* Life-cycle events allow you to subscribe to the internal library events occurring during the request/response handling.
|
|
80
|
+
*
|
|
81
|
+
* @see {@link https://mswjs.io/docs/api/life-cycle-events Life-cycle Events API reference}
|
|
82
|
+
*/
|
|
71
83
|
events: LifeCycleEventEmitter<LifeCycleEventsMap>;
|
|
72
84
|
}
|
|
73
85
|
|
|
@@ -84,7 +96,8 @@ declare class SetupWorkerApi extends SetupApi<LifeCycleEventsMap> implements Set
|
|
|
84
96
|
/**
|
|
85
97
|
* Sets up a requests interception in the browser with the given request handlers.
|
|
86
98
|
* @param {RequestHandler[]} handlers List of request handlers.
|
|
87
|
-
*
|
|
99
|
+
*
|
|
100
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker `setupWorker()` API reference}
|
|
88
101
|
*/
|
|
89
102
|
declare function setupWorker(...handlers: Array<RequestHandler>): SetupWorker;
|
|
90
103
|
|
package/lib/browser/index.js
CHANGED
|
@@ -259,7 +259,7 @@ var createRequestListener = (context, options) => {
|
|
|
259
259
|
messageChannel.postMessage("NOT_FOUND");
|
|
260
260
|
},
|
|
261
261
|
onMockedResponse(_0, _1) {
|
|
262
|
-
return __async(this, arguments, function* (response, { handler,
|
|
262
|
+
return __async(this, arguments, function* (response, { handler, parsedResult }) {
|
|
263
263
|
const responseClone = response.clone();
|
|
264
264
|
const responseInit = (0, import_toResponseInit.toResponseInit)(response);
|
|
265
265
|
const responseStream = responseClone.body;
|
|
@@ -274,7 +274,11 @@ var createRequestListener = (context, options) => {
|
|
|
274
274
|
);
|
|
275
275
|
if (!options.quiet) {
|
|
276
276
|
context.emitter.once("response:mocked", ({ response: response2 }) => {
|
|
277
|
-
handler.log(
|
|
277
|
+
handler.log({
|
|
278
|
+
request: requestCloneForLogs,
|
|
279
|
+
response: response2,
|
|
280
|
+
parsedResult
|
|
281
|
+
});
|
|
278
282
|
});
|
|
279
283
|
}
|
|
280
284
|
});
|
|
@@ -317,9 +321,9 @@ function requestIntegrityCheck(context, serviceWorker) {
|
|
|
317
321
|
const { payload: actualChecksum } = yield context.events.once(
|
|
318
322
|
"INTEGRITY_CHECK_RESPONSE"
|
|
319
323
|
);
|
|
320
|
-
if (actualChecksum !== "
|
|
324
|
+
if (actualChecksum !== "0877fcdc026242810f5bfde0d7178db4") {
|
|
321
325
|
throw new Error(
|
|
322
|
-
`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"
|
|
326
|
+
`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"0877fcdc026242810f5bfde0d7178db4"}).`
|
|
323
327
|
);
|
|
324
328
|
}
|
|
325
329
|
return serviceWorker;
|
|
@@ -535,10 +539,14 @@ function createFallbackRequestListener(context, options) {
|
|
|
535
539
|
options,
|
|
536
540
|
context.emitter,
|
|
537
541
|
{
|
|
538
|
-
onMockedResponse(_, { handler,
|
|
542
|
+
onMockedResponse(_, { handler, parsedResult }) {
|
|
539
543
|
if (!options.quiet) {
|
|
540
544
|
context.emitter.once("response:mocked", ({ response: response2 }) => {
|
|
541
|
-
handler.log(
|
|
545
|
+
handler.log({
|
|
546
|
+
request: requestCloneForLogs,
|
|
547
|
+
response: response2,
|
|
548
|
+
parsedResult
|
|
549
|
+
});
|
|
542
550
|
});
|
|
543
551
|
}
|
|
544
552
|
}
|
package/lib/browser/index.mjs
CHANGED
|
@@ -235,7 +235,7 @@ var createRequestListener = (context, options) => {
|
|
|
235
235
|
messageChannel.postMessage("NOT_FOUND");
|
|
236
236
|
},
|
|
237
237
|
onMockedResponse(_0, _1) {
|
|
238
|
-
return __async(this, arguments, function* (response, { handler,
|
|
238
|
+
return __async(this, arguments, function* (response, { handler, parsedResult }) {
|
|
239
239
|
const responseClone = response.clone();
|
|
240
240
|
const responseInit = toResponseInit(response);
|
|
241
241
|
const responseStream = responseClone.body;
|
|
@@ -250,7 +250,11 @@ var createRequestListener = (context, options) => {
|
|
|
250
250
|
);
|
|
251
251
|
if (!options.quiet) {
|
|
252
252
|
context.emitter.once("response:mocked", ({ response: response2 }) => {
|
|
253
|
-
handler.log(
|
|
253
|
+
handler.log({
|
|
254
|
+
request: requestCloneForLogs,
|
|
255
|
+
response: response2,
|
|
256
|
+
parsedResult
|
|
257
|
+
});
|
|
254
258
|
});
|
|
255
259
|
}
|
|
256
260
|
});
|
|
@@ -293,9 +297,9 @@ function requestIntegrityCheck(context, serviceWorker) {
|
|
|
293
297
|
const { payload: actualChecksum } = yield context.events.once(
|
|
294
298
|
"INTEGRITY_CHECK_RESPONSE"
|
|
295
299
|
);
|
|
296
|
-
if (actualChecksum !== "
|
|
300
|
+
if (actualChecksum !== "0877fcdc026242810f5bfde0d7178db4") {
|
|
297
301
|
throw new Error(
|
|
298
|
-
`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"
|
|
302
|
+
`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"0877fcdc026242810f5bfde0d7178db4"}).`
|
|
299
303
|
);
|
|
300
304
|
}
|
|
301
305
|
return serviceWorker;
|
|
@@ -513,10 +517,14 @@ function createFallbackRequestListener(context, options) {
|
|
|
513
517
|
options,
|
|
514
518
|
context.emitter,
|
|
515
519
|
{
|
|
516
|
-
onMockedResponse(_, { handler,
|
|
520
|
+
onMockedResponse(_, { handler, parsedResult }) {
|
|
517
521
|
if (!options.quiet) {
|
|
518
522
|
context.emitter.once("response:mocked", ({ response: response2 }) => {
|
|
519
|
-
handler.log(
|
|
523
|
+
handler.log({
|
|
524
|
+
request: requestCloneForLogs,
|
|
525
|
+
response: response2,
|
|
526
|
+
parsedResult
|
|
527
|
+
});
|
|
520
528
|
});
|
|
521
529
|
}
|
|
522
530
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OperationTypeNode, DocumentNode, GraphQLError } from 'graphql';
|
|
2
|
-
import { g as RequestHandlerDefaultInfo, D as DefaultBodyType, R as RequestHandler, a as ResponseResolver, f as RequestHandlerOptions } from './RequestHandler-
|
|
2
|
+
import { g as RequestHandlerDefaultInfo, D as DefaultBodyType, R as RequestHandler, a as ResponseResolver, f as RequestHandlerOptions } from './RequestHandler-b59044ae.js';
|
|
3
3
|
import { Path } from './utils/matching/matchRequestUrl.js';
|
|
4
4
|
|
|
5
5
|
interface ParsedGraphQLQuery {
|
|
@@ -49,14 +49,26 @@ declare function isDocumentNode(value: DocumentNode | any): value is DocumentNod
|
|
|
49
49
|
declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, ParsedGraphQLRequest, GraphQLResolverExtras<any>> {
|
|
50
50
|
private endpoint;
|
|
51
51
|
constructor(operationType: ExpectedOperationTypeNode, operationName: GraphQLHandlerNameSelector, endpoint: Path, resolver: ResponseResolver<GraphQLResolverExtras<any>, any, any>, options?: RequestHandlerOptions);
|
|
52
|
-
parse(
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
parse(args: {
|
|
53
|
+
request: Request;
|
|
54
|
+
}): Promise<ParsedGraphQLRequest<GraphQLVariables>>;
|
|
55
|
+
predicate(args: {
|
|
56
|
+
request: Request;
|
|
57
|
+
parsedResult: ParsedGraphQLRequest;
|
|
58
|
+
}): boolean;
|
|
59
|
+
protected extendResolverArgs(args: {
|
|
60
|
+
request: Request;
|
|
61
|
+
parsedResult: ParsedGraphQLRequest<GraphQLVariables>;
|
|
62
|
+
}): {
|
|
55
63
|
query: string;
|
|
56
64
|
operationName: string;
|
|
57
65
|
variables: GraphQLVariables;
|
|
58
66
|
};
|
|
59
|
-
log(
|
|
67
|
+
log(args: {
|
|
68
|
+
request: Request;
|
|
69
|
+
response: Response;
|
|
70
|
+
parsedResult: ParsedGraphQLRequest;
|
|
71
|
+
}): Promise<void>;
|
|
60
72
|
}
|
|
61
73
|
|
|
62
|
-
export { ExpectedOperationTypeNode as E, GraphQLHandler as G, ParsedGraphQLRequest as P, GraphQLVariables as a, GraphQLRequestBody as b, GraphQLJsonRequestBody as c,
|
|
74
|
+
export { ExpectedOperationTypeNode as E, GraphQLHandler as G, ParsedGraphQLRequest as P, GraphQLVariables as a, GraphQLRequestBody as b, GraphQLJsonRequestBody as c, GraphQLHandlerNameSelector as d, GraphQLResolverExtras as e, GraphQLResponseBody as f, ParsedGraphQLQuery as g, GraphQLParsedOperationsMap as h, GraphQLMultipartRequestBody as i, parseGraphQLRequest as j, GraphQLHandlerInfo as k, isDocumentNode as l, parseDocumentNode as p };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { e as HttpResponse, H as HttpResponseInit, S as StrictRequest, d as StrictResponse } from './RequestHandler-
|
|
1
|
+
export { e as HttpResponse, H as HttpResponseInit, S as StrictRequest, d as StrictResponse } from './RequestHandler-b59044ae.js';
|
|
2
2
|
import './typeUtils.js';
|
|
@@ -2,7 +2,7 @@ import { MaybePromise } from './typeUtils.js';
|
|
|
2
2
|
|
|
3
3
|
interface ResponseLookupResult {
|
|
4
4
|
handler: RequestHandler;
|
|
5
|
-
|
|
5
|
+
parsedResult?: any;
|
|
6
6
|
response?: Response;
|
|
7
7
|
}
|
|
8
8
|
interface ResponseResolutionContext {
|
|
@@ -27,9 +27,15 @@ interface StrictResponse<BodyType extends DefaultBodyType> extends Response {
|
|
|
27
27
|
readonly [bodyType]: BodyType;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* A
|
|
30
|
+
* A drop-in replacement for the standard `Response` class
|
|
31
|
+
* to allow additional features, like mocking the response `Set-Cookie` header.
|
|
32
|
+
*
|
|
31
33
|
* @example
|
|
32
34
|
* new HttpResponse('Hello world', { status: 201 })
|
|
35
|
+
* HttpResponse.json({ name: 'John' })
|
|
36
|
+
* HttpResponse.formData(form)
|
|
37
|
+
*
|
|
38
|
+
* @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}
|
|
33
39
|
*/
|
|
34
40
|
declare class HttpResponse extends Response {
|
|
35
41
|
constructor(body?: BodyInit | null, init?: HttpResponseInit);
|
|
@@ -117,28 +123,48 @@ declare abstract class RequestHandler<HandlerInfo extends RequestHandlerDefaultI
|
|
|
117
123
|
private options?;
|
|
118
124
|
constructor(args: RequestHandlerArgs<HandlerInfo, HandlerOptions>);
|
|
119
125
|
/**
|
|
120
|
-
* Determine if the
|
|
126
|
+
* Determine if the intercepted request should be mocked.
|
|
121
127
|
*/
|
|
122
|
-
abstract predicate(
|
|
128
|
+
abstract predicate(args: {
|
|
129
|
+
request: Request;
|
|
130
|
+
parsedResult: ParsedResult;
|
|
131
|
+
resolutionContext?: ResponseResolutionContext;
|
|
132
|
+
}): boolean;
|
|
123
133
|
/**
|
|
124
134
|
* Print out the successfully handled request.
|
|
125
135
|
*/
|
|
126
|
-
abstract log(
|
|
136
|
+
abstract log(args: {
|
|
137
|
+
request: Request;
|
|
138
|
+
response: Response;
|
|
139
|
+
parsedResult: ParsedResult;
|
|
140
|
+
}): void;
|
|
127
141
|
/**
|
|
128
|
-
* Parse the
|
|
142
|
+
* Parse the intercepted request to extract additional information from it.
|
|
129
143
|
* Parsed result is then exposed to other methods of this request handler.
|
|
130
144
|
*/
|
|
131
|
-
parse(
|
|
145
|
+
parse(_args: {
|
|
146
|
+
request: Request;
|
|
147
|
+
resolutionContext?: ResponseResolutionContext;
|
|
148
|
+
}): Promise<ParsedResult>;
|
|
132
149
|
/**
|
|
133
150
|
* Test if this handler matches the given request.
|
|
134
151
|
*/
|
|
135
|
-
test(
|
|
136
|
-
|
|
152
|
+
test(args: {
|
|
153
|
+
request: Request;
|
|
154
|
+
resolutionContext?: ResponseResolutionContext;
|
|
155
|
+
}): Promise<boolean>;
|
|
156
|
+
protected extendResolverArgs(_args: {
|
|
157
|
+
request: Request;
|
|
158
|
+
parsedResult: ParsedResult;
|
|
159
|
+
}): ResolverExtras;
|
|
137
160
|
/**
|
|
138
161
|
* Execute this request handler and produce a mocked response
|
|
139
162
|
* using the given resolver function.
|
|
140
163
|
*/
|
|
141
|
-
run(
|
|
164
|
+
run(args: {
|
|
165
|
+
request: StrictRequest<any>;
|
|
166
|
+
resolutionContext?: ResponseResolutionContext;
|
|
167
|
+
}): Promise<RequestHandlerExecutionResult<ParsedResult> | null>;
|
|
142
168
|
private wrapResolver;
|
|
143
169
|
private createExecutionResult;
|
|
144
170
|
}
|
package/lib/core/SetupApi.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventMap, Emitter } from 'strict-event-emitter';
|
|
2
|
-
import { R as RequestHandler, g as RequestHandlerDefaultInfo } from './RequestHandler-
|
|
2
|
+
import { R as RequestHandler, g as RequestHandlerDefaultInfo } from './RequestHandler-b59044ae.js';
|
|
3
3
|
import { LifeCycleEventEmitter } from './sharedOptions.js';
|
|
4
4
|
import { Disposable } from './utils/internal/Disposable.js';
|
|
5
5
|
import './typeUtils.js';
|
package/lib/core/bypass.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type BypassRequestInput = string | URL | Request;
|
|
2
2
|
/**
|
|
3
|
-
* Creates a `Request` instance that will always be
|
|
3
|
+
* Creates a `Request` instance that will always be ignored by MSW.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* import { bypass } from 'msw'
|
|
@@ -8,6 +8,8 @@ type BypassRequestInput = string | URL | Request;
|
|
|
8
8
|
* fetch(bypass('/resource'))
|
|
9
9
|
* fetch(bypass(new URL('/resource', 'https://example.com)))
|
|
10
10
|
* fetch(bypass(new Request('https://example.com/resource')))
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://mswjs.io/docs/api/bypass `bypass()` API reference}
|
|
11
13
|
*/
|
|
12
14
|
declare function bypass(input: BypassRequestInput, init?: RequestInit): Request;
|
|
13
15
|
|
package/lib/core/delay.d.ts
CHANGED
|
@@ -5,10 +5,13 @@ declare const NODE_SERVER_RESPONSE_TIME = 5;
|
|
|
5
5
|
type DelayMode = 'real' | 'infinite';
|
|
6
6
|
/**
|
|
7
7
|
* Delays the response by the given duration (ms).
|
|
8
|
+
*
|
|
8
9
|
* @example
|
|
9
10
|
* await delay() // emulate realistic server response time
|
|
10
11
|
* await delay(1200) // delay response by 1200ms
|
|
11
12
|
* await delay('infinite') // delay response infinitely
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://mswjs.io/docs/api/delay `delay()` API reference}
|
|
12
15
|
*/
|
|
13
16
|
declare function delay(durationOrMode?: DelayMode | number): Promise<void>;
|
|
14
17
|
|
package/lib/core/graphql.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
|
-
import { a as ResponseResolver, f as RequestHandlerOptions } from './RequestHandler-
|
|
3
|
-
import { a as GraphQLVariables, d as
|
|
2
|
+
import { a as ResponseResolver, f as RequestHandlerOptions } from './RequestHandler-b59044ae.js';
|
|
3
|
+
import { a as GraphQLVariables, d as GraphQLHandlerNameSelector, e as GraphQLResolverExtras, f as GraphQLResponseBody, G as GraphQLHandler } from './GraphQLHandler-a441dd03.js';
|
|
4
4
|
import { Path } from './utils/matching/matchRequestUrl.js';
|
|
5
5
|
import './typeUtils.js';
|
|
6
6
|
|
|
@@ -15,63 +15,95 @@ interface TypedDocumentNode<Result = {
|
|
|
15
15
|
}
|
|
16
16
|
declare const standardGraphQLHandlers: {
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* graphql.operation(() => {
|
|
21
|
-
* return HttpResponse.json({ data: { name: 'John' } })
|
|
22
|
-
* })
|
|
23
|
-
* @see {@link https://mswjs.io/docs/api/graphql/operation `graphql.operation()`}
|
|
24
|
-
*/
|
|
25
|
-
operation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>) => GraphQLHandler;
|
|
26
|
-
/**
|
|
27
|
-
* Captures a GraphQL query by a given name.
|
|
18
|
+
* Intercepts a GraphQL query by a given name.
|
|
19
|
+
*
|
|
28
20
|
* @example
|
|
29
21
|
* graphql.query('GetUser', () => {
|
|
30
22
|
* return HttpResponse.json({ data: { user: { name: 'John' } } })
|
|
31
23
|
* })
|
|
32
|
-
*
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
|
|
33
26
|
*/
|
|
34
|
-
query: <
|
|
27
|
+
query: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
35
28
|
/**
|
|
36
|
-
*
|
|
29
|
+
* Intercepts a GraphQL mutation by its name.
|
|
30
|
+
*
|
|
37
31
|
* @example
|
|
38
32
|
* graphql.mutation('SavePost', () => {
|
|
39
33
|
* return HttpResponse.json({ data: { post: { id: 'abc-123 } } })
|
|
40
34
|
* })
|
|
41
|
-
*
|
|
35
|
+
*
|
|
36
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
|
|
37
|
+
*
|
|
42
38
|
*/
|
|
43
|
-
mutation: <
|
|
44
|
-
};
|
|
45
|
-
declare function createGraphQLLink(url: Path): typeof standardGraphQLHandlers;
|
|
46
|
-
declare const graphql: {
|
|
47
|
-
link: typeof createGraphQLLink;
|
|
39
|
+
mutation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
48
40
|
/**
|
|
49
|
-
*
|
|
41
|
+
* Intercepts any GraphQL operation, regardless of its type or name.
|
|
42
|
+
*
|
|
50
43
|
* @example
|
|
51
44
|
* graphql.operation(() => {
|
|
52
45
|
* return HttpResponse.json({ data: { name: 'John' } })
|
|
53
46
|
* })
|
|
54
|
-
*
|
|
47
|
+
*
|
|
48
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
|
|
55
49
|
*/
|
|
56
|
-
operation: <
|
|
50
|
+
operation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables_1>, null, GraphQLResponseBody<Query_1>>) => GraphQLHandler;
|
|
51
|
+
};
|
|
52
|
+
declare function createGraphQLLink(url: Path): typeof standardGraphQLHandlers;
|
|
53
|
+
/**
|
|
54
|
+
* A namespace to intercept and mock GraphQL operations
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* graphql.query('GetUser', resolver)
|
|
58
|
+
* graphql.mutation('DeletePost', resolver)
|
|
59
|
+
*
|
|
60
|
+
* @see {@link https://mswjs.io/docs/api/graphql `graphql` API reference}
|
|
61
|
+
*/
|
|
62
|
+
declare const graphql: {
|
|
63
|
+
/**
|
|
64
|
+
* Intercepts GraphQL operations scoped by the given URL.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* const github = graphql.link('https://api.github.com/graphql')
|
|
68
|
+
* github.query('GetRepo', resolver)
|
|
69
|
+
*
|
|
70
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
|
|
71
|
+
*/
|
|
72
|
+
link: typeof createGraphQLLink;
|
|
57
73
|
/**
|
|
58
|
-
*
|
|
74
|
+
* Intercepts a GraphQL query by a given name.
|
|
75
|
+
*
|
|
59
76
|
* @example
|
|
60
77
|
* graphql.query('GetUser', () => {
|
|
61
78
|
* return HttpResponse.json({ data: { user: { name: 'John' } } })
|
|
62
79
|
* })
|
|
63
|
-
*
|
|
80
|
+
*
|
|
81
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
|
|
64
82
|
*/
|
|
65
|
-
query: <
|
|
83
|
+
query: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
66
84
|
/**
|
|
67
|
-
*
|
|
85
|
+
* Intercepts a GraphQL mutation by its name.
|
|
86
|
+
*
|
|
68
87
|
* @example
|
|
69
88
|
* graphql.mutation('SavePost', () => {
|
|
70
89
|
* return HttpResponse.json({ data: { post: { id: 'abc-123 } } })
|
|
71
90
|
* })
|
|
72
|
-
*
|
|
91
|
+
*
|
|
92
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
mutation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
96
|
+
/**
|
|
97
|
+
* Intercepts any GraphQL operation, regardless of its type or name.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* graphql.operation(() => {
|
|
101
|
+
* return HttpResponse.json({ data: { name: 'John' } })
|
|
102
|
+
* })
|
|
103
|
+
*
|
|
104
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
|
|
73
105
|
*/
|
|
74
|
-
|
|
106
|
+
operation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables_1>, null, GraphQLResponseBody<Query_1>>) => GraphQLHandler;
|
|
75
107
|
};
|
|
76
108
|
|
|
77
109
|
export { TypedDocumentNode, graphql };
|
package/lib/core/graphql.js
CHANGED
|
@@ -57,32 +57,39 @@ function createGraphQLOperationHandler(url) {
|
|
|
57
57
|
}
|
|
58
58
|
const standardGraphQLHandlers = {
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* graphql.operation(() => {
|
|
63
|
-
* return HttpResponse.json({ data: { name: 'John' } })
|
|
64
|
-
* })
|
|
65
|
-
* @see {@link https://mswjs.io/docs/api/graphql/operation `graphql.operation()`}
|
|
66
|
-
*/
|
|
67
|
-
operation: createGraphQLOperationHandler("*"),
|
|
68
|
-
/**
|
|
69
|
-
* Captures a GraphQL query by a given name.
|
|
60
|
+
* Intercepts a GraphQL query by a given name.
|
|
61
|
+
*
|
|
70
62
|
* @example
|
|
71
63
|
* graphql.query('GetUser', () => {
|
|
72
64
|
* return HttpResponse.json({ data: { user: { name: 'John' } } })
|
|
73
65
|
* })
|
|
74
|
-
*
|
|
66
|
+
*
|
|
67
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
|
|
75
68
|
*/
|
|
76
69
|
query: createScopedGraphQLHandler("query", "*"),
|
|
77
70
|
/**
|
|
78
|
-
*
|
|
71
|
+
* Intercepts a GraphQL mutation by its name.
|
|
72
|
+
*
|
|
79
73
|
* @example
|
|
80
74
|
* graphql.mutation('SavePost', () => {
|
|
81
75
|
* return HttpResponse.json({ data: { post: { id: 'abc-123 } } })
|
|
82
76
|
* })
|
|
83
|
-
*
|
|
77
|
+
*
|
|
78
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
|
|
79
|
+
*
|
|
84
80
|
*/
|
|
85
|
-
mutation: createScopedGraphQLHandler("mutation", "*")
|
|
81
|
+
mutation: createScopedGraphQLHandler("mutation", "*"),
|
|
82
|
+
/**
|
|
83
|
+
* Intercepts any GraphQL operation, regardless of its type or name.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* graphql.operation(() => {
|
|
87
|
+
* return HttpResponse.json({ data: { name: 'John' } })
|
|
88
|
+
* })
|
|
89
|
+
*
|
|
90
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
|
|
91
|
+
*/
|
|
92
|
+
operation: createGraphQLOperationHandler("*")
|
|
86
93
|
};
|
|
87
94
|
function createGraphQLLink(url) {
|
|
88
95
|
return {
|
|
@@ -92,5 +99,14 @@ function createGraphQLLink(url) {
|
|
|
92
99
|
};
|
|
93
100
|
}
|
|
94
101
|
const graphql = __spreadProps(__spreadValues({}, standardGraphQLHandlers), {
|
|
102
|
+
/**
|
|
103
|
+
* Intercepts GraphQL operations scoped by the given URL.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* const github = graphql.link('https://api.github.com/graphql')
|
|
107
|
+
* github.query('GetRepo', resolver)
|
|
108
|
+
*
|
|
109
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
|
|
110
|
+
*/
|
|
95
111
|
link: createGraphQLLink
|
|
96
112
|
});
|
package/lib/core/graphql.mjs
CHANGED
|
@@ -38,32 +38,39 @@ function createGraphQLOperationHandler(url) {
|
|
|
38
38
|
}
|
|
39
39
|
const standardGraphQLHandlers = {
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* graphql.operation(() => {
|
|
44
|
-
* return HttpResponse.json({ data: { name: 'John' } })
|
|
45
|
-
* })
|
|
46
|
-
* @see {@link https://mswjs.io/docs/api/graphql/operation `graphql.operation()`}
|
|
47
|
-
*/
|
|
48
|
-
operation: createGraphQLOperationHandler("*"),
|
|
49
|
-
/**
|
|
50
|
-
* Captures a GraphQL query by a given name.
|
|
41
|
+
* Intercepts a GraphQL query by a given name.
|
|
42
|
+
*
|
|
51
43
|
* @example
|
|
52
44
|
* graphql.query('GetUser', () => {
|
|
53
45
|
* return HttpResponse.json({ data: { user: { name: 'John' } } })
|
|
54
46
|
* })
|
|
55
|
-
*
|
|
47
|
+
*
|
|
48
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
|
|
56
49
|
*/
|
|
57
50
|
query: createScopedGraphQLHandler("query", "*"),
|
|
58
51
|
/**
|
|
59
|
-
*
|
|
52
|
+
* Intercepts a GraphQL mutation by its name.
|
|
53
|
+
*
|
|
60
54
|
* @example
|
|
61
55
|
* graphql.mutation('SavePost', () => {
|
|
62
56
|
* return HttpResponse.json({ data: { post: { id: 'abc-123 } } })
|
|
63
57
|
* })
|
|
64
|
-
*
|
|
58
|
+
*
|
|
59
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
|
|
60
|
+
*
|
|
65
61
|
*/
|
|
66
|
-
mutation: createScopedGraphQLHandler("mutation", "*")
|
|
62
|
+
mutation: createScopedGraphQLHandler("mutation", "*"),
|
|
63
|
+
/**
|
|
64
|
+
* Intercepts any GraphQL operation, regardless of its type or name.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* graphql.operation(() => {
|
|
68
|
+
* return HttpResponse.json({ data: { name: 'John' } })
|
|
69
|
+
* })
|
|
70
|
+
*
|
|
71
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
|
|
72
|
+
*/
|
|
73
|
+
operation: createGraphQLOperationHandler("*")
|
|
67
74
|
};
|
|
68
75
|
function createGraphQLLink(url) {
|
|
69
76
|
return {
|
|
@@ -73,6 +80,15 @@ function createGraphQLLink(url) {
|
|
|
73
80
|
};
|
|
74
81
|
}
|
|
75
82
|
const graphql = __spreadProps(__spreadValues({}, standardGraphQLHandlers), {
|
|
83
|
+
/**
|
|
84
|
+
* Intercepts GraphQL operations scoped by the given URL.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* const github = graphql.link('https://api.github.com/graphql')
|
|
88
|
+
* github.query('GetRepo', resolver)
|
|
89
|
+
*
|
|
90
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
|
|
91
|
+
*/
|
|
76
92
|
link: createGraphQLLink
|
|
77
93
|
});
|
|
78
94
|
export {
|