msw 1.3.1 → 2.0.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/README.md +32 -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 +751 -0
- package/lib/browser/index.mjs +733 -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 +6238 -12395
- 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 +55 -25
- 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,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://kettanaito.com/discord).
|
|
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
|
|
|
@@ -38,8 +41,7 @@
|
|
|
38
41
|
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
42
|
|
|
40
43
|
- [Documentation](https://mswjs.io/docs)
|
|
41
|
-
- [**Getting started**](https://mswjs.io/docs/getting-started
|
|
42
|
-
- [Recipes](https://mswjs.io/docs/recipes)
|
|
44
|
+
- [**Getting started**](https://mswjs.io/docs/getting-started)
|
|
43
45
|
- [FAQ](https://mswjs.io/docs/faq)
|
|
44
46
|
|
|
45
47
|
## Examples
|
|
@@ -48,12 +50,12 @@ This README will give you a brief overview on the library but there's no better
|
|
|
48
50
|
|
|
49
51
|
## Browser
|
|
50
52
|
|
|
51
|
-
- [Learn more about using MSW in a browser](https://mswjs.io/docs/
|
|
53
|
+
- [Learn more about using MSW in a browser](https://mswjs.io/docs/integrations/browser)
|
|
52
54
|
- [`setupWorker` API](https://mswjs.io/docs/api/setup-worker)
|
|
53
55
|
|
|
54
56
|
### How does it work?
|
|
55
57
|
|
|
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
|
|
58
|
+
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
59
|
|
|
58
60
|
**Take a look at this quick presentation on how Mock Service Worker functions in a browser:**
|
|
59
61
|
|
|
@@ -71,17 +73,20 @@ In-browser usage is what sets Mock Service Worker apart from other tools. Utiliz
|
|
|
71
73
|
```js
|
|
72
74
|
// src/mocks.js
|
|
73
75
|
// 1. Import the library.
|
|
74
|
-
import {
|
|
76
|
+
import { http, HttpResponse } from 'msw'
|
|
77
|
+
import { setupWorker } from 'msw/browser'
|
|
75
78
|
|
|
76
79
|
// 2. Describe network behavior with request handlers.
|
|
77
80
|
const worker = setupWorker(
|
|
78
|
-
|
|
79
|
-
return
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
http.get('https://github.com/octocat', ({ request, params, cookies }) => {
|
|
82
|
+
return HttpResponse.json(
|
|
83
|
+
{
|
|
84
|
+
message: 'Mocked response',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
status: 202,
|
|
88
|
+
statusText: 'Mocked status',
|
|
89
|
+
},
|
|
85
90
|
)
|
|
86
91
|
}),
|
|
87
92
|
)
|
|
@@ -98,7 +103,7 @@ Performing a `GET https://github.com/octocat` request in your application will r
|
|
|
98
103
|
|
|
99
104
|
## Node.js
|
|
100
105
|
|
|
101
|
-
- [Learn more about using MSW in Node.js](https://mswjs.io/docs/
|
|
106
|
+
- [Learn more about using MSW in Node.js](https://mswjs.io/docs/integrations/node)
|
|
102
107
|
- [`setupServer` API](https://mswjs.io/docs/api/setup-server)
|
|
103
108
|
|
|
104
109
|
### How does it work?
|
|
@@ -118,7 +123,7 @@ Take a look at the example of an integration test in Jest that uses [React Testi
|
|
|
118
123
|
// test/Dashboard.test.js
|
|
119
124
|
|
|
120
125
|
import React from 'react'
|
|
121
|
-
import {
|
|
126
|
+
import { http, HttpResponse } from 'msw'
|
|
122
127
|
import { setupServer } from 'msw/node'
|
|
123
128
|
import { render, screen, waitFor } from '@testing-library/react'
|
|
124
129
|
import Dashboard from '../src/components/Dashboard'
|
|
@@ -127,19 +132,17 @@ const server = setupServer(
|
|
|
127
132
|
// Describe network behavior with request handlers.
|
|
128
133
|
// Tip: move the handlers into their own module and
|
|
129
134
|
// import it across your browser and Node.js setups!
|
|
130
|
-
|
|
131
|
-
return
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
]),
|
|
142
|
-
)
|
|
135
|
+
http.get('/posts', ({ request, params, cookies }) => {
|
|
136
|
+
return HttpResponse.json([
|
|
137
|
+
{
|
|
138
|
+
id: 'f8dd058f-9006-4174-8d49-e3086bc39c21',
|
|
139
|
+
title: `Avoid Nesting When You're Testing`,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: '8ac96078-6434-4959-80ed-cc834e7fef61',
|
|
143
|
+
title: `How I Built A Modern Website In 2021`,
|
|
144
|
+
},
|
|
145
|
+
])
|
|
143
146
|
}),
|
|
144
147
|
)
|
|
145
148
|
|
|
@@ -174,7 +177,7 @@ it('displays the list of recent posts', async () => {
|
|
|
174
177
|
})
|
|
175
178
|
```
|
|
176
179
|
|
|
177
|
-
> Don't get overwhelmed! We've prepared a step-by-step [**Getting started**](https://mswjs.io/docs/getting-started
|
|
180
|
+
> 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
181
|
|
|
179
182
|
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
183
|
|
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 };
|