msw 1.3.2 → 2.0.1
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 +45 -29
- package/browser/package.json +5 -0
- package/cli/init.js +3 -3
- package/config/constants.js +1 -2
- package/lib/browser/index.d.ts +104 -0
- package/lib/browser/index.js +752 -0
- package/lib/browser/index.mjs +734 -0
- package/lib/core/GraphQLHandler-b42ca96f.d.ts +74 -0
- package/lib/core/HttpResponse.d.ts +2 -0
- package/lib/core/HttpResponse.js +94 -0
- package/lib/core/HttpResponse.mjs +77 -0
- package/lib/core/RequestHandler-1a5dbdc7.d.ts +172 -0
- package/lib/core/SetupApi.d.ts +26 -0
- package/lib/core/SetupApi.js +83 -0
- package/lib/core/SetupApi.mjs +63 -0
- package/lib/core/bypass.d.ts +16 -0
- package/lib/core/bypass.js +36 -0
- package/lib/core/bypass.mjs +16 -0
- package/lib/core/delay.d.ts +18 -0
- package/lib/core/delay.js +92 -0
- package/lib/core/delay.mjs +72 -0
- package/lib/core/graphql.d.ts +109 -0
- package/lib/core/graphql.js +112 -0
- package/lib/core/graphql.mjs +96 -0
- package/lib/core/handlers/GraphQLHandler.d.ts +5 -0
- package/lib/core/handlers/GraphQLHandler.js +145 -0
- package/lib/core/handlers/GraphQLHandler.mjs +130 -0
- package/lib/core/handlers/HttpHandler.d.ts +62 -0
- package/lib/core/handlers/HttpHandler.js +149 -0
- package/lib/core/handlers/HttpHandler.mjs +133 -0
- package/lib/core/handlers/RequestHandler.d.ts +2 -0
- package/lib/core/handlers/RequestHandler.js +180 -0
- package/lib/core/handlers/RequestHandler.mjs +162 -0
- package/lib/core/http.d.ts +26 -0
- package/lib/core/http.js +39 -0
- package/lib/core/http.mjs +22 -0
- package/lib/core/http.spec.d.ts +2 -0
- package/lib/core/http.spec.js +15 -0
- package/lib/core/http.spec.mjs +14 -0
- package/lib/core/index.d.ts +18 -0
- package/lib/core/index.js +49 -0
- package/lib/core/index.mjs +28 -0
- package/lib/core/passthrough.d.ts +17 -0
- package/lib/core/passthrough.js +32 -0
- package/lib/core/passthrough.mjs +12 -0
- package/lib/core/sharedOptions.d.ts +66 -0
- package/lib/core/sharedOptions.js +16 -0
- package/lib/core/sharedOptions.mjs +0 -0
- package/lib/core/typeUtils.d.ts +7 -0
- package/lib/core/typeUtils.js +16 -0
- package/lib/core/typeUtils.mjs +0 -0
- package/lib/core/utils/HttpResponse/decorators.d.ts +12 -0
- package/lib/core/utils/HttpResponse/decorators.js +80 -0
- package/lib/core/utils/HttpResponse/decorators.mjs +52 -0
- package/lib/core/utils/getResponse.d.ts +2 -0
- package/lib/core/utils/getResponse.js +64 -0
- package/lib/core/utils/getResponse.mjs +44 -0
- package/lib/core/utils/handleRequest.d.ts +30 -0
- package/lib/core/utils/handleRequest.js +102 -0
- package/lib/core/utils/handleRequest.mjs +82 -0
- package/lib/core/utils/internal/Disposable.d.ts +7 -0
- package/lib/core/utils/internal/Disposable.js +53 -0
- package/lib/core/utils/internal/Disposable.mjs +33 -0
- package/lib/core/utils/internal/checkGlobals.d.ts +3 -0
- package/lib/core/utils/internal/checkGlobals.js +33 -0
- package/lib/core/utils/internal/checkGlobals.mjs +13 -0
- package/lib/core/utils/internal/devUtils.d.ts +19 -0
- package/lib/core/utils/internal/devUtils.js +40 -0
- package/lib/core/utils/internal/devUtils.mjs +20 -0
- package/lib/core/utils/internal/getCallFrame.d.ts +6 -0
- package/lib/core/utils/internal/getCallFrame.js +40 -0
- package/lib/core/utils/internal/getCallFrame.mjs +20 -0
- package/lib/core/utils/internal/isIterable.d.ts +6 -0
- package/lib/core/utils/internal/isIterable.js +29 -0
- package/lib/core/utils/internal/isIterable.mjs +9 -0
- package/lib/core/utils/internal/isObject.d.ts +6 -0
- package/lib/core/utils/internal/isObject.js +26 -0
- package/lib/core/utils/internal/isObject.mjs +6 -0
- package/lib/core/utils/internal/isStringEqual.d.ts +6 -0
- package/lib/core/utils/internal/isStringEqual.js +26 -0
- package/lib/core/utils/internal/isStringEqual.mjs +6 -0
- package/lib/core/utils/internal/jsonParse.d.ts +7 -0
- package/lib/core/utils/internal/jsonParse.js +30 -0
- package/lib/core/utils/internal/jsonParse.mjs +10 -0
- package/lib/core/utils/internal/mergeRight.d.ts +7 -0
- package/lib/core/utils/internal/mergeRight.js +39 -0
- package/lib/core/utils/internal/mergeRight.mjs +19 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +5 -0
- package/lib/core/utils/internal/parseGraphQLRequest.js +184 -0
- package/lib/core/utils/internal/parseGraphQLRequest.mjs +165 -0
- package/lib/core/utils/internal/parseMultipartData.d.ts +10 -0
- package/lib/core/utils/internal/parseMultipartData.js +81 -0
- package/lib/core/utils/internal/parseMultipartData.mjs +61 -0
- package/lib/core/utils/internal/pipeEvents.d.ts +8 -0
- package/lib/core/utils/internal/pipeEvents.js +34 -0
- package/lib/core/utils/internal/pipeEvents.mjs +14 -0
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +8 -0
- package/lib/core/utils/internal/requestHandlerUtils.js +36 -0
- package/lib/core/utils/internal/requestHandlerUtils.mjs +16 -0
- package/lib/core/utils/internal/toReadonlyArray.d.ts +6 -0
- package/lib/core/utils/internal/toReadonlyArray.js +28 -0
- package/lib/core/utils/internal/toReadonlyArray.mjs +8 -0
- package/lib/core/utils/internal/tryCatch.d.ts +3 -0
- package/lib/core/utils/internal/tryCatch.js +31 -0
- package/lib/core/utils/internal/tryCatch.mjs +11 -0
- package/lib/core/utils/internal/uuidv4.d.ts +3 -0
- package/lib/core/utils/internal/uuidv4.js +26 -0
- package/lib/core/utils/internal/uuidv4.mjs +6 -0
- package/lib/core/utils/logging/getStatusCodeColor.d.ts +11 -0
- package/lib/core/utils/logging/getStatusCodeColor.js +39 -0
- package/lib/core/utils/logging/getStatusCodeColor.mjs +19 -0
- package/lib/core/utils/logging/getTimestamp.d.ts +6 -0
- package/lib/core/utils/logging/getTimestamp.js +27 -0
- package/lib/core/utils/logging/getTimestamp.mjs +7 -0
- package/lib/core/utils/logging/serializeRequest.d.ts +12 -0
- package/lib/core/utils/logging/serializeRequest.js +55 -0
- package/lib/core/utils/logging/serializeRequest.mjs +35 -0
- package/lib/core/utils/logging/serializeResponse.d.ts +9 -0
- package/lib/core/utils/logging/serializeResponse.js +69 -0
- package/lib/core/utils/logging/serializeResponse.mjs +39 -0
- package/lib/core/utils/matching/matchRequestUrl.d.ts +19 -0
- package/lib/core/utils/matching/matchRequestUrl.js +50 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs +30 -0
- package/lib/core/utils/matching/normalizePath.d.ts +12 -0
- package/lib/core/utils/matching/normalizePath.js +32 -0
- package/lib/core/utils/matching/normalizePath.mjs +12 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.d.ts +7 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.js +30 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.mjs +10 -0
- package/lib/core/utils/request/getRequestCookies.d.ts +8 -0
- package/lib/core/utils/request/getRequestCookies.js +88 -0
- package/lib/core/utils/request/getRequestCookies.mjs +60 -0
- package/lib/core/utils/request/onUnhandledRequest.d.ts +12 -0
- package/lib/core/utils/request/onUnhandledRequest.js +193 -0
- package/lib/core/utils/request/onUnhandledRequest.mjs +165 -0
- package/lib/core/utils/request/readResponseCookies.d.ts +3 -0
- package/lib/core/utils/request/readResponseCookies.js +45 -0
- package/lib/core/utils/request/readResponseCookies.mjs +27 -0
- package/lib/core/utils/toResponseInit.d.ts +3 -0
- package/lib/core/utils/toResponseInit.js +30 -0
- package/lib/core/utils/toResponseInit.mjs +10 -0
- package/lib/core/utils/url/cleanUrl.d.ts +7 -0
- package/lib/core/utils/url/cleanUrl.js +31 -0
- package/lib/core/utils/url/cleanUrl.mjs +11 -0
- package/lib/core/utils/url/getAbsoluteUrl.d.ts +6 -0
- package/lib/core/utils/url/getAbsoluteUrl.js +37 -0
- package/lib/core/utils/url/getAbsoluteUrl.mjs +17 -0
- package/lib/core/utils/url/isAbsoluteUrl.d.ts +6 -0
- package/lib/core/utils/url/isAbsoluteUrl.js +26 -0
- package/lib/core/utils/url/isAbsoluteUrl.mjs +6 -0
- package/lib/iife/index.js +6204 -12360
- package/lib/mockServiceWorker.js +82 -93
- package/lib/native/index.d.ts +67 -7
- package/lib/native/index.js +74 -1500
- package/lib/native/index.mjs +69 -1514
- package/lib/node/index.d.ts +68 -9
- package/lib/node/index.js +77 -1508
- package/lib/node/index.mjs +71 -1521
- package/native/package.json +2 -1
- package/node/package.json +2 -1
- package/package.json +53 -23
- package/lib/SetupServerApi-1855d9c6.d.ts +0 -20
- package/lib/glossary-de6278a9.d.ts +0 -385
- package/lib/iife/index.js.map +0 -1
- package/lib/index.d.ts +0 -365
- package/lib/index.js +0 -2295
- package/lib/index.js.map +0 -1
- package/lib/node/index.js.map +0 -1
- package/lib/node/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
> **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://kettanaito.com/discord).
|
|
2
|
+
>
|
|
3
|
+
> We've also recorded the most comprehensive introduction to MSW ever. Learn how to mock APIs like a pro in our official video course:
|
|
4
|
+
|
|
5
|
+
<a href="https://egghead.io/courses/mock-rest-and-graphql-apis-with-mock-service-worker-8d471ece?af=8mci9b" target="_blank">
|
|
6
|
+
<img src="media/egghead-banner.png" alt="Mock REST and GraphQL APIs with Mock Service Worker" />
|
|
7
|
+
</a>
|
|
8
|
+
|
|
9
|
+
<br />
|
|
1
10
|
<br />
|
|
2
11
|
|
|
3
12
|
<p align="center">
|
|
@@ -21,11 +30,13 @@
|
|
|
21
30
|
|
|
22
31
|
<br />
|
|
23
32
|
|
|
33
|
+
<br />
|
|
34
|
+
|
|
24
35
|
## Features
|
|
25
36
|
|
|
26
37
|
- **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
38
|
- **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
|
|
39
|
+
- **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
40
|
|
|
30
41
|
---
|
|
31
42
|
|
|
@@ -38,8 +49,7 @@
|
|
|
38
49
|
This README will give you a brief overview on the library but there's no better place to start with Mock Service Worker than its official documentation.
|
|
39
50
|
|
|
40
51
|
- [Documentation](https://mswjs.io/docs)
|
|
41
|
-
- [**Getting started**](https://mswjs.io/docs/getting-started
|
|
42
|
-
- [Recipes](https://mswjs.io/docs/recipes)
|
|
52
|
+
- [**Getting started**](https://mswjs.io/docs/getting-started)
|
|
43
53
|
- [FAQ](https://mswjs.io/docs/faq)
|
|
44
54
|
|
|
45
55
|
## Examples
|
|
@@ -48,12 +58,12 @@ This README will give you a brief overview on the library but there's no better
|
|
|
48
58
|
|
|
49
59
|
## Browser
|
|
50
60
|
|
|
51
|
-
- [Learn more about using MSW in a browser](https://mswjs.io/docs/
|
|
61
|
+
- [Learn more about using MSW in a browser](https://mswjs.io/docs/integrations/browser)
|
|
52
62
|
- [`setupWorker` API](https://mswjs.io/docs/api/setup-worker)
|
|
53
63
|
|
|
54
64
|
### How does it work?
|
|
55
65
|
|
|
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
|
|
66
|
+
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
67
|
|
|
58
68
|
**Take a look at this quick presentation on how Mock Service Worker functions in a browser:**
|
|
59
69
|
|
|
@@ -71,17 +81,20 @@ In-browser usage is what sets Mock Service Worker apart from other tools. Utiliz
|
|
|
71
81
|
```js
|
|
72
82
|
// src/mocks.js
|
|
73
83
|
// 1. Import the library.
|
|
74
|
-
import {
|
|
84
|
+
import { http, HttpResponse } from 'msw'
|
|
85
|
+
import { setupWorker } from 'msw/browser'
|
|
75
86
|
|
|
76
87
|
// 2. Describe network behavior with request handlers.
|
|
77
88
|
const worker = setupWorker(
|
|
78
|
-
|
|
79
|
-
return
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
http.get('https://github.com/octocat', ({ request, params, cookies }) => {
|
|
90
|
+
return HttpResponse.json(
|
|
91
|
+
{
|
|
92
|
+
message: 'Mocked response',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
status: 202,
|
|
96
|
+
statusText: 'Mocked status',
|
|
97
|
+
},
|
|
85
98
|
)
|
|
86
99
|
}),
|
|
87
100
|
)
|
|
@@ -98,7 +111,7 @@ Performing a `GET https://github.com/octocat` request in your application will r
|
|
|
98
111
|
|
|
99
112
|
## Node.js
|
|
100
113
|
|
|
101
|
-
- [Learn more about using MSW in Node.js](https://mswjs.io/docs/
|
|
114
|
+
- [Learn more about using MSW in Node.js](https://mswjs.io/docs/integrations/node)
|
|
102
115
|
- [`setupServer` API](https://mswjs.io/docs/api/setup-server)
|
|
103
116
|
|
|
104
117
|
### How does it work?
|
|
@@ -118,7 +131,7 @@ Take a look at the example of an integration test in Jest that uses [React Testi
|
|
|
118
131
|
// test/Dashboard.test.js
|
|
119
132
|
|
|
120
133
|
import React from 'react'
|
|
121
|
-
import {
|
|
134
|
+
import { http, HttpResponse } from 'msw'
|
|
122
135
|
import { setupServer } from 'msw/node'
|
|
123
136
|
import { render, screen, waitFor } from '@testing-library/react'
|
|
124
137
|
import Dashboard from '../src/components/Dashboard'
|
|
@@ -127,19 +140,17 @@ const server = setupServer(
|
|
|
127
140
|
// Describe network behavior with request handlers.
|
|
128
141
|
// Tip: move the handlers into their own module and
|
|
129
142
|
// import it across your browser and Node.js setups!
|
|
130
|
-
|
|
131
|
-
return
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
]),
|
|
142
|
-
)
|
|
143
|
+
http.get('/posts', ({ request, params, cookies }) => {
|
|
144
|
+
return HttpResponse.json([
|
|
145
|
+
{
|
|
146
|
+
id: 'f8dd058f-9006-4174-8d49-e3086bc39c21',
|
|
147
|
+
title: `Avoid Nesting When You're Testing`,
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
id: '8ac96078-6434-4959-80ed-cc834e7fef61',
|
|
151
|
+
title: `How I Built A Modern Website In 2021`,
|
|
152
|
+
},
|
|
153
|
+
])
|
|
143
154
|
}),
|
|
144
155
|
)
|
|
145
156
|
|
|
@@ -174,7 +185,7 @@ it('displays the list of recent posts', async () => {
|
|
|
174
185
|
})
|
|
175
186
|
```
|
|
176
187
|
|
|
177
|
-
> Don't get overwhelmed! We've prepared a step-by-step [**Getting started**](https://mswjs.io/docs/getting-started
|
|
188
|
+
> Don't get overwhelmed! We've prepared a step-by-step [**Getting started**](https://mswjs.io/docs/getting-started) tutorial that you can follow to learn how to integrate Mock Service Worker into your project.
|
|
178
189
|
|
|
179
190
|
Despite the API being called `setupServer`, there are no actual servers involved! The name was chosen for familiarity, and the API was designed to resemble operating with an actual server.
|
|
180
191
|
|
|
@@ -202,6 +213,11 @@ Mock Service Worker is trusted by hundreds of thousands of engineers around the
|
|
|
202
213
|
</picture>
|
|
203
214
|
</a>
|
|
204
215
|
</td>
|
|
216
|
+
<td>
|
|
217
|
+
<a href="https://www.codacy.com/" target="_blank">
|
|
218
|
+
<img src="media/sponsors/codacy.svg" alt="Codacy" height="64" />
|
|
219
|
+
</a>
|
|
220
|
+
</td>
|
|
205
221
|
</tr>
|
|
206
222
|
</table>
|
|
207
223
|
|
package/cli/init.js
CHANGED
|
@@ -21,14 +21,14 @@ module.exports = async function init(args) {
|
|
|
21
21
|
|
|
22
22
|
if (!dirExists) {
|
|
23
23
|
// Try to create the directory if it doesn't exist
|
|
24
|
-
const
|
|
24
|
+
const createDirectoryResult = await until(() =>
|
|
25
25
|
fs.promises.mkdir(absolutePublicDir, { recursive: true }),
|
|
26
26
|
)
|
|
27
27
|
invariant(
|
|
28
|
-
|
|
28
|
+
createDirectoryResult.error == null,
|
|
29
29
|
'Failed to create a Service Worker at "%s": directory does not exist and could not be created.\nMake sure to include a relative path to the root directory of your server.\n\nSee the original error below:\n%s',
|
|
30
30
|
absolutePublicDir,
|
|
31
|
-
|
|
31
|
+
createDirectoryResult.error,
|
|
32
32
|
)
|
|
33
33
|
}
|
|
34
34
|
|
package/config/constants.js
CHANGED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { SharedOptions, LifeCycleEventEmitter, LifeCycleEventsMap } from "../core/sharedOptions";
|
|
2
|
+
import { RequestHandler, RequestHandlerDefaultInfo } from "../core/handlers/RequestHandler";
|
|
3
|
+
import { SetupApi } from "../core/SetupApi";
|
|
4
|
+
|
|
5
|
+
type FindWorker = (scriptUrl: string, mockServiceWorkerUrl: string) => boolean;
|
|
6
|
+
interface StartOptions extends SharedOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Service Worker registration options.
|
|
9
|
+
*/
|
|
10
|
+
serviceWorker?: {
|
|
11
|
+
/**
|
|
12
|
+
* Custom url to the worker script.
|
|
13
|
+
* @default "/mockServiceWorker.js"
|
|
14
|
+
*/
|
|
15
|
+
url?: string;
|
|
16
|
+
options?: RegistrationOptions;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Disables the logging of the intercepted requests
|
|
20
|
+
* into browser's console.
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
quiet?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Defers any network requests until the Service Worker
|
|
26
|
+
* instance is activated.
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
waitUntilReady?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* A custom lookup function to find a Mock Service Worker in the list
|
|
32
|
+
* of all registered Service Workers on the page.
|
|
33
|
+
*/
|
|
34
|
+
findWorker?: FindWorker;
|
|
35
|
+
}
|
|
36
|
+
type StartReturnType = Promise<ServiceWorkerRegistration | undefined>;
|
|
37
|
+
type StopHandler = () => void;
|
|
38
|
+
interface SetupWorker {
|
|
39
|
+
/**
|
|
40
|
+
* Registers and activates the mock Service Worker.
|
|
41
|
+
*
|
|
42
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker/start `worker.start()` API reference}
|
|
43
|
+
*/
|
|
44
|
+
start: (options?: StartOptions) => StartReturnType;
|
|
45
|
+
/**
|
|
46
|
+
* Stops requests interception for the current client.
|
|
47
|
+
*
|
|
48
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker/stop `worker.stop()` API reference}
|
|
49
|
+
*/
|
|
50
|
+
stop: StopHandler;
|
|
51
|
+
/**
|
|
52
|
+
* Prepends given request handlers to the list of existing handlers.
|
|
53
|
+
* @param {RequestHandler[]} handlers List of runtime request handlers.
|
|
54
|
+
*
|
|
55
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker/use `worker.use()` API reference}
|
|
56
|
+
*/
|
|
57
|
+
use: (...handlers: RequestHandler[]) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Marks all request handlers that respond using `res.once()` as unused.
|
|
60
|
+
*
|
|
61
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker/restore-handlers `worker.restoreHandlers()` API reference}
|
|
62
|
+
*/
|
|
63
|
+
restoreHandlers: () => void;
|
|
64
|
+
/**
|
|
65
|
+
* Resets request handlers to the initial list given to the `setupWorker` call, or to the explicit next request handlers list, if given.
|
|
66
|
+
* @param {RequestHandler[]} nextHandlers List of the new initial request handlers.
|
|
67
|
+
*
|
|
68
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker/reset-handlers `worker.resetHandlers()` API reference}
|
|
69
|
+
*/
|
|
70
|
+
resetHandlers: (...nextHandlers: RequestHandler[]) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Returns a readonly list of currently active request handlers.
|
|
73
|
+
*
|
|
74
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker/list-handlers `worker.listHandlers()` API reference}
|
|
75
|
+
*/
|
|
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
|
+
*/
|
|
83
|
+
events: LifeCycleEventEmitter<LifeCycleEventsMap>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
declare class SetupWorkerApi extends SetupApi<LifeCycleEventsMap> implements SetupWorker {
|
|
87
|
+
private context;
|
|
88
|
+
private startHandler;
|
|
89
|
+
private stopHandler;
|
|
90
|
+
private listeners;
|
|
91
|
+
constructor(...handlers: Array<RequestHandler>);
|
|
92
|
+
private createWorkerContext;
|
|
93
|
+
start(options?: StartOptions): StartReturnType;
|
|
94
|
+
stop(): void;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Sets up a requests interception in the browser with the given request handlers.
|
|
98
|
+
* @param {RequestHandler[]} handlers List of request handlers.
|
|
99
|
+
*
|
|
100
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker `setupWorker()` API reference}
|
|
101
|
+
*/
|
|
102
|
+
declare function setupWorker(...handlers: Array<RequestHandler>): SetupWorker;
|
|
103
|
+
|
|
104
|
+
export { SetupWorker, SetupWorkerApi, StartOptions, setupWorker };
|