msw 1.3.2 → 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 +6203 -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
|
@@ -0,0 +1,733 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/browser/setupWorker/setupWorker.ts
|
|
42
|
+
import { invariant } from "outvariant";
|
|
43
|
+
import { isNodeProcess } from "is-node-process";
|
|
44
|
+
|
|
45
|
+
// src/browser/setupWorker/start/createStartHandler.ts
|
|
46
|
+
import { until as until3 } from "@open-draft/until";
|
|
47
|
+
import { devUtils as devUtils6 } from '../core/utils/internal/devUtils.mjs';
|
|
48
|
+
|
|
49
|
+
// src/browser/setupWorker/start/utils/getWorkerInstance.ts
|
|
50
|
+
import { until } from "@open-draft/until";
|
|
51
|
+
import { devUtils } from '../core/utils/internal/devUtils.mjs';
|
|
52
|
+
|
|
53
|
+
// src/browser/utils/getAbsoluteWorkerUrl.ts
|
|
54
|
+
function getAbsoluteWorkerUrl(workerUrl) {
|
|
55
|
+
return new URL(workerUrl, location.href).href;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/browser/setupWorker/start/utils/getWorkerByRegistration.ts
|
|
59
|
+
function getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker) {
|
|
60
|
+
const allStates = [
|
|
61
|
+
registration.active,
|
|
62
|
+
registration.installing,
|
|
63
|
+
registration.waiting
|
|
64
|
+
];
|
|
65
|
+
const relevantStates = allStates.filter((state) => {
|
|
66
|
+
return state != null;
|
|
67
|
+
});
|
|
68
|
+
const worker = relevantStates.find((worker2) => {
|
|
69
|
+
return findWorker(worker2.scriptURL, absoluteWorkerUrl);
|
|
70
|
+
});
|
|
71
|
+
return worker || null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/browser/setupWorker/start/utils/getWorkerInstance.ts
|
|
75
|
+
var getWorkerInstance = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (url, options = {}, findWorker) {
|
|
76
|
+
const absoluteWorkerUrl = getAbsoluteWorkerUrl(url);
|
|
77
|
+
const mockRegistrations = yield navigator.serviceWorker.getRegistrations().then(
|
|
78
|
+
(registrations) => registrations.filter(
|
|
79
|
+
(registration) => getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker)
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
if (!navigator.serviceWorker.controller && mockRegistrations.length > 0) {
|
|
83
|
+
location.reload();
|
|
84
|
+
}
|
|
85
|
+
const [existingRegistration] = mockRegistrations;
|
|
86
|
+
if (existingRegistration) {
|
|
87
|
+
return existingRegistration.update().then(() => {
|
|
88
|
+
return [
|
|
89
|
+
getWorkerByRegistration(
|
|
90
|
+
existingRegistration,
|
|
91
|
+
absoluteWorkerUrl,
|
|
92
|
+
findWorker
|
|
93
|
+
),
|
|
94
|
+
existingRegistration
|
|
95
|
+
];
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
const registrationResult = yield until(
|
|
99
|
+
() => __async(void 0, null, function* () {
|
|
100
|
+
const registration = yield navigator.serviceWorker.register(url, options);
|
|
101
|
+
return [
|
|
102
|
+
// Compare existing worker registration by its worker URL,
|
|
103
|
+
// to prevent irrelevant workers to resolve here (such as Codesandbox worker).
|
|
104
|
+
getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker),
|
|
105
|
+
registration
|
|
106
|
+
];
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
if (registrationResult.error) {
|
|
110
|
+
const isWorkerMissing = registrationResult.error.message.includes("(404)");
|
|
111
|
+
if (isWorkerMissing) {
|
|
112
|
+
const scopeUrl = new URL((options == null ? void 0 : options.scope) || "/", location.href);
|
|
113
|
+
throw new Error(
|
|
114
|
+
devUtils.formatMessage(`Failed to register a Service Worker for scope ('${scopeUrl.href}') with script ('${absoluteWorkerUrl}'): Service Worker script does not exist at the given path.
|
|
115
|
+
|
|
116
|
+
Did you forget to run "npx msw init <PUBLIC_DIR>"?
|
|
117
|
+
|
|
118
|
+
Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/init`)
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
throw new Error(
|
|
122
|
+
devUtils.formatMessage(
|
|
123
|
+
"Failed to register the Service Worker:\n\n%s",
|
|
124
|
+
registrationResult.error.message
|
|
125
|
+
)
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
return registrationResult.data;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// src/browser/setupWorker/start/utils/enableMocking.ts
|
|
132
|
+
import { devUtils as devUtils3 } from '../core/utils/internal/devUtils.mjs';
|
|
133
|
+
|
|
134
|
+
// src/browser/setupWorker/start/utils/printStartMessage.ts
|
|
135
|
+
import { devUtils as devUtils2 } from '../core/utils/internal/devUtils.mjs';
|
|
136
|
+
function printStartMessage(args = {}) {
|
|
137
|
+
if (args.quiet) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const message = args.message || "Mocking enabled.";
|
|
141
|
+
console.groupCollapsed(
|
|
142
|
+
`%c${devUtils2.formatMessage(message)}`,
|
|
143
|
+
"color:orangered;font-weight:bold;"
|
|
144
|
+
);
|
|
145
|
+
console.log(
|
|
146
|
+
"%cDocumentation: %chttps://mswjs.io/docs",
|
|
147
|
+
"font-weight:bold",
|
|
148
|
+
"font-weight:normal"
|
|
149
|
+
);
|
|
150
|
+
console.log("Found an issue? https://github.com/mswjs/msw/issues");
|
|
151
|
+
if (args.workerUrl) {
|
|
152
|
+
console.log("Worker script URL:", args.workerUrl);
|
|
153
|
+
}
|
|
154
|
+
if (args.workerScope) {
|
|
155
|
+
console.log("Worker scope:", args.workerScope);
|
|
156
|
+
}
|
|
157
|
+
console.groupEnd();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/browser/setupWorker/start/utils/enableMocking.ts
|
|
161
|
+
function enableMocking(context, options) {
|
|
162
|
+
return __async(this, null, function* () {
|
|
163
|
+
var _a, _b;
|
|
164
|
+
context.workerChannel.send("MOCK_ACTIVATE");
|
|
165
|
+
yield context.events.once("MOCKING_ENABLED");
|
|
166
|
+
if (context.isMockingEnabled) {
|
|
167
|
+
devUtils3.warn(
|
|
168
|
+
`Found a redundant "worker.start()" call. Note that starting the worker while mocking is already enabled will have no effect. Consider removing this "worker.start()" call.`
|
|
169
|
+
);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
context.isMockingEnabled = true;
|
|
173
|
+
printStartMessage({
|
|
174
|
+
quiet: options.quiet,
|
|
175
|
+
workerScope: (_a = context.registration) == null ? void 0 : _a.scope,
|
|
176
|
+
workerUrl: (_b = context.worker) == null ? void 0 : _b.scriptURL
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/browser/setupWorker/start/utils/createMessageChannel.ts
|
|
182
|
+
var WorkerChannel = class {
|
|
183
|
+
constructor(port) {
|
|
184
|
+
this.port = port;
|
|
185
|
+
}
|
|
186
|
+
postMessage(event, ...rest) {
|
|
187
|
+
const [data, transfer] = rest;
|
|
188
|
+
this.port.postMessage(
|
|
189
|
+
{ type: event, data },
|
|
190
|
+
{
|
|
191
|
+
// @ts-ignore ReadableStream can be transferred
|
|
192
|
+
// but TypeScript doesn't acknowledge that.
|
|
193
|
+
transfer
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// src/browser/utils/pruneGetRequestBody.ts
|
|
200
|
+
function pruneGetRequestBody(request) {
|
|
201
|
+
if (["HEAD", "GET"].includes(request.method)) {
|
|
202
|
+
return void 0;
|
|
203
|
+
}
|
|
204
|
+
return request.body;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// src/browser/utils/parseWorkerRequest.ts
|
|
208
|
+
function parseWorkerRequest(incomingRequest) {
|
|
209
|
+
return new Request(incomingRequest.url, __spreadProps(__spreadValues({}, incomingRequest), {
|
|
210
|
+
body: pruneGetRequestBody(incomingRequest)
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/browser/setupWorker/start/createRequestListener.ts
|
|
215
|
+
import { handleRequest } from '../core/utils/handleRequest.mjs';
|
|
216
|
+
import { devUtils as devUtils4 } from '../core/utils/internal/devUtils.mjs';
|
|
217
|
+
import { toResponseInit } from '../core/utils/toResponseInit.mjs';
|
|
218
|
+
var createRequestListener = (context, options) => {
|
|
219
|
+
return (event, message) => __async(void 0, null, function* () {
|
|
220
|
+
var _b;
|
|
221
|
+
const messageChannel = new WorkerChannel(event.ports[0]);
|
|
222
|
+
const requestId = message.payload.id;
|
|
223
|
+
const request = parseWorkerRequest(message.payload);
|
|
224
|
+
const requestCloneForLogs = request.clone();
|
|
225
|
+
try {
|
|
226
|
+
let _a;
|
|
227
|
+
yield handleRequest(
|
|
228
|
+
request,
|
|
229
|
+
requestId,
|
|
230
|
+
context.requestHandlers,
|
|
231
|
+
options,
|
|
232
|
+
context.emitter,
|
|
233
|
+
{
|
|
234
|
+
onPassthroughResponse() {
|
|
235
|
+
messageChannel.postMessage("NOT_FOUND");
|
|
236
|
+
},
|
|
237
|
+
onMockedResponse(_0, _1) {
|
|
238
|
+
return __async(this, arguments, function* (response, { handler, parsedResult }) {
|
|
239
|
+
const responseClone = response.clone();
|
|
240
|
+
const responseInit = toResponseInit(response);
|
|
241
|
+
if (context.supports.readableStreamTransfer) {
|
|
242
|
+
const responseStream = response.body;
|
|
243
|
+
messageChannel.postMessage(
|
|
244
|
+
"MOCK_RESPONSE",
|
|
245
|
+
__spreadProps(__spreadValues({}, responseInit), {
|
|
246
|
+
body: responseStream
|
|
247
|
+
}),
|
|
248
|
+
responseStream ? [responseStream] : void 0
|
|
249
|
+
);
|
|
250
|
+
} else {
|
|
251
|
+
const responseBuffer = yield responseClone.arrayBuffer();
|
|
252
|
+
messageChannel.postMessage("MOCK_RESPONSE", __spreadProps(__spreadValues({}, responseInit), {
|
|
253
|
+
body: responseBuffer
|
|
254
|
+
}));
|
|
255
|
+
}
|
|
256
|
+
if (!options.quiet) {
|
|
257
|
+
context.emitter.once("response:mocked", ({ response: response2 }) => {
|
|
258
|
+
handler.log({
|
|
259
|
+
request: requestCloneForLogs,
|
|
260
|
+
response: response2,
|
|
261
|
+
parsedResult
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
);
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (error instanceof Error) {
|
|
271
|
+
devUtils4.error(
|
|
272
|
+
`Uncaught exception in the request handler for "%s %s":
|
|
273
|
+
|
|
274
|
+
%s
|
|
275
|
+
|
|
276
|
+
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/recipes/mocking-error-responses`,
|
|
277
|
+
request.method,
|
|
278
|
+
request.url,
|
|
279
|
+
(_b = error.stack) != null ? _b : error
|
|
280
|
+
);
|
|
281
|
+
messageChannel.postMessage("MOCK_RESPONSE", {
|
|
282
|
+
status: 500,
|
|
283
|
+
statusText: "Request Handler Error",
|
|
284
|
+
headers: {
|
|
285
|
+
"Content-Type": "application/json"
|
|
286
|
+
},
|
|
287
|
+
body: JSON.stringify({
|
|
288
|
+
name: error.name,
|
|
289
|
+
message: error.message,
|
|
290
|
+
stack: error.stack
|
|
291
|
+
})
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
// src/browser/utils/requestIntegrityCheck.ts
|
|
299
|
+
function requestIntegrityCheck(context, serviceWorker) {
|
|
300
|
+
return __async(this, null, function* () {
|
|
301
|
+
context.workerChannel.send("INTEGRITY_CHECK_REQUEST");
|
|
302
|
+
const { payload: actualChecksum } = yield context.events.once(
|
|
303
|
+
"INTEGRITY_CHECK_RESPONSE"
|
|
304
|
+
);
|
|
305
|
+
if (actualChecksum !== "0877fcdc026242810f5bfde0d7178db4") {
|
|
306
|
+
throw new Error(
|
|
307
|
+
`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"0877fcdc026242810f5bfde0d7178db4"}).`
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
return serviceWorker;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// src/browser/utils/deferNetworkRequestsUntil.ts
|
|
315
|
+
import { until as until2 } from "@open-draft/until";
|
|
316
|
+
function deferNetworkRequestsUntil(predicatePromise) {
|
|
317
|
+
const originalXhrSend = window.XMLHttpRequest.prototype.send;
|
|
318
|
+
window.XMLHttpRequest.prototype.send = function(...args) {
|
|
319
|
+
until2(() => predicatePromise).then(() => {
|
|
320
|
+
window.XMLHttpRequest.prototype.send = originalXhrSend;
|
|
321
|
+
this.send(...args);
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
const originalFetch = window.fetch;
|
|
325
|
+
window.fetch = (...args) => __async(this, null, function* () {
|
|
326
|
+
yield until2(() => predicatePromise);
|
|
327
|
+
window.fetch = originalFetch;
|
|
328
|
+
return window.fetch(...args);
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// src/browser/setupWorker/start/createResponseListener.ts
|
|
333
|
+
function createResponseListener(context) {
|
|
334
|
+
return (_, message) => {
|
|
335
|
+
var _a;
|
|
336
|
+
const { payload: responseJson } = message;
|
|
337
|
+
if ((_a = responseJson.type) == null ? void 0 : _a.includes("opaque")) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const response = responseJson.status === 0 ? Response.error() : new Response(responseJson.body, responseJson);
|
|
341
|
+
context.emitter.emit(
|
|
342
|
+
responseJson.isMockedResponse ? "response:mocked" : "response:bypass",
|
|
343
|
+
{
|
|
344
|
+
response,
|
|
345
|
+
/**
|
|
346
|
+
* @todo @fixme In this context, we don't know anything about
|
|
347
|
+
* the request.
|
|
348
|
+
*/
|
|
349
|
+
request: null,
|
|
350
|
+
requestId: responseJson.requestId
|
|
351
|
+
}
|
|
352
|
+
);
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// src/browser/setupWorker/start/utils/validateWorkerScope.ts
|
|
357
|
+
import { devUtils as devUtils5 } from '../core/utils/internal/devUtils.mjs';
|
|
358
|
+
function validateWorkerScope(registration, options) {
|
|
359
|
+
if (!(options == null ? void 0 : options.quiet) && !location.href.startsWith(registration.scope)) {
|
|
360
|
+
devUtils5.warn(
|
|
361
|
+
`Cannot intercept requests on this page because it's outside of the worker's scope ("${registration.scope}"). If you wish to mock API requests on this page, you must resolve this scope issue.
|
|
362
|
+
|
|
363
|
+
- (Recommended) Register the worker at the root level ("/") of your application.
|
|
364
|
+
- Set the "Service-Worker-Allowed" response header to allow out-of-scope workers.`
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// src/browser/setupWorker/start/createStartHandler.ts
|
|
370
|
+
var createStartHandler = (context) => {
|
|
371
|
+
return function start(options, customOptions) {
|
|
372
|
+
const startWorkerInstance = () => __async(this, null, function* () {
|
|
373
|
+
context.events.removeAllListeners();
|
|
374
|
+
context.workerChannel.on(
|
|
375
|
+
"REQUEST",
|
|
376
|
+
createRequestListener(context, options)
|
|
377
|
+
);
|
|
378
|
+
context.workerChannel.on("RESPONSE", createResponseListener(context));
|
|
379
|
+
const instance = yield getWorkerInstance(
|
|
380
|
+
options.serviceWorker.url,
|
|
381
|
+
options.serviceWorker.options,
|
|
382
|
+
options.findWorker
|
|
383
|
+
);
|
|
384
|
+
const [worker, registration] = instance;
|
|
385
|
+
if (!worker) {
|
|
386
|
+
const missingWorkerMessage = (customOptions == null ? void 0 : customOptions.findWorker) ? devUtils6.formatMessage(
|
|
387
|
+
`Failed to locate the Service Worker registration using a custom "findWorker" predicate.
|
|
388
|
+
|
|
389
|
+
Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
|
|
390
|
+
More details: https://mswjs.io/docs/api/setup-worker/start#findworker
|
|
391
|
+
`,
|
|
392
|
+
options.serviceWorker.url
|
|
393
|
+
) : devUtils6.formatMessage(
|
|
394
|
+
`Failed to locate the Service Worker registration.
|
|
395
|
+
|
|
396
|
+
This most likely means that the worker script URL "%s" cannot resolve against the actual public hostname (%s). This may happen if your application runs behind a proxy, or has a dynamic hostname.
|
|
397
|
+
|
|
398
|
+
Please consider using a custom "serviceWorker.url" option to point to the actual worker script location, or a custom "findWorker" option to resolve the Service Worker registration manually. More details: https://mswjs.io/docs/api/setup-worker/start`,
|
|
399
|
+
options.serviceWorker.url,
|
|
400
|
+
location.host
|
|
401
|
+
);
|
|
402
|
+
throw new Error(missingWorkerMessage);
|
|
403
|
+
}
|
|
404
|
+
context.worker = worker;
|
|
405
|
+
context.registration = registration;
|
|
406
|
+
context.events.addListener(window, "beforeunload", () => {
|
|
407
|
+
if (worker.state !== "redundant") {
|
|
408
|
+
context.workerChannel.send("CLIENT_CLOSED");
|
|
409
|
+
}
|
|
410
|
+
window.clearInterval(context.keepAliveInterval);
|
|
411
|
+
});
|
|
412
|
+
const integrityCheckResult = yield until3(
|
|
413
|
+
() => requestIntegrityCheck(context, worker)
|
|
414
|
+
);
|
|
415
|
+
if (integrityCheckResult.error) {
|
|
416
|
+
devUtils6.error(`Detected outdated Service Worker: ${integrityCheckResult.error.message}
|
|
417
|
+
|
|
418
|
+
The mocking is still enabled, but it's highly recommended that you update your Service Worker by running:
|
|
419
|
+
|
|
420
|
+
$ npx msw init <PUBLIC_DIR>
|
|
421
|
+
|
|
422
|
+
This is necessary to ensure that the Service Worker is in sync with the library to guarantee its stability.
|
|
423
|
+
If this message still persists after updating, please report an issue: https://github.com/open-draft/msw/issues `);
|
|
424
|
+
}
|
|
425
|
+
context.keepAliveInterval = window.setInterval(
|
|
426
|
+
() => context.workerChannel.send("KEEPALIVE_REQUEST"),
|
|
427
|
+
5e3
|
|
428
|
+
);
|
|
429
|
+
validateWorkerScope(registration, context.startOptions);
|
|
430
|
+
return registration;
|
|
431
|
+
});
|
|
432
|
+
const workerRegistration = startWorkerInstance().then(
|
|
433
|
+
(registration) => __async(this, null, function* () {
|
|
434
|
+
const pendingInstance = registration.installing || registration.waiting;
|
|
435
|
+
if (pendingInstance) {
|
|
436
|
+
yield new Promise((resolve) => {
|
|
437
|
+
pendingInstance.addEventListener("statechange", () => {
|
|
438
|
+
if (pendingInstance.state === "activated") {
|
|
439
|
+
return resolve();
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
yield enableMocking(context, options).catch((error) => {
|
|
445
|
+
throw new Error(`Failed to enable mocking: ${error == null ? void 0 : error.message}`);
|
|
446
|
+
});
|
|
447
|
+
return registration;
|
|
448
|
+
})
|
|
449
|
+
);
|
|
450
|
+
if (options.waitUntilReady) {
|
|
451
|
+
deferNetworkRequestsUntil(workerRegistration);
|
|
452
|
+
}
|
|
453
|
+
return workerRegistration;
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
// src/browser/setupWorker/stop/createStop.ts
|
|
458
|
+
import { devUtils as devUtils8 } from '../core/utils/internal/devUtils.mjs';
|
|
459
|
+
|
|
460
|
+
// src/browser/setupWorker/stop/utils/printStopMessage.ts
|
|
461
|
+
import { devUtils as devUtils7 } from '../core/utils/internal/devUtils.mjs';
|
|
462
|
+
function printStopMessage(args = {}) {
|
|
463
|
+
if (args.quiet) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
console.log(
|
|
467
|
+
`%c${devUtils7.formatMessage("Mocking disabled.")}`,
|
|
468
|
+
"color:orangered;font-weight:bold;"
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// src/browser/setupWorker/stop/createStop.ts
|
|
473
|
+
var createStop = (context) => {
|
|
474
|
+
return function stop() {
|
|
475
|
+
var _a;
|
|
476
|
+
if (!context.isMockingEnabled) {
|
|
477
|
+
devUtils8.warn(
|
|
478
|
+
'Found a redundant "worker.stop()" call. Note that stopping the worker while mocking already stopped has no effect. Consider removing this "worker.stop()" call.'
|
|
479
|
+
);
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
context.workerChannel.send("MOCK_DEACTIVATE");
|
|
483
|
+
context.isMockingEnabled = false;
|
|
484
|
+
window.clearInterval(context.keepAliveInterval);
|
|
485
|
+
printStopMessage({ quiet: (_a = context.startOptions) == null ? void 0 : _a.quiet });
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
// src/browser/setupWorker/start/utils/prepareStartHandler.ts
|
|
490
|
+
import { mergeRight } from '../core/utils/internal/mergeRight.mjs';
|
|
491
|
+
var DEFAULT_START_OPTIONS = {
|
|
492
|
+
serviceWorker: {
|
|
493
|
+
url: "/mockServiceWorker.js",
|
|
494
|
+
options: null
|
|
495
|
+
},
|
|
496
|
+
quiet: false,
|
|
497
|
+
waitUntilReady: true,
|
|
498
|
+
onUnhandledRequest: "warn",
|
|
499
|
+
findWorker(scriptURL, mockServiceWorkerUrl) {
|
|
500
|
+
return scriptURL === mockServiceWorkerUrl;
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
// src/browser/setupWorker/start/createFallbackRequestListener.ts
|
|
505
|
+
import {
|
|
506
|
+
BatchInterceptor
|
|
507
|
+
} from "@mswjs/interceptors";
|
|
508
|
+
import { FetchInterceptor } from "@mswjs/interceptors/fetch";
|
|
509
|
+
import { XMLHttpRequestInterceptor } from "@mswjs/interceptors/XMLHttpRequest";
|
|
510
|
+
import { handleRequest as handleRequest2 } from '../core/utils/handleRequest.mjs';
|
|
511
|
+
function createFallbackRequestListener(context, options) {
|
|
512
|
+
const interceptor = new BatchInterceptor({
|
|
513
|
+
name: "fallback",
|
|
514
|
+
interceptors: [new FetchInterceptor(), new XMLHttpRequestInterceptor()]
|
|
515
|
+
});
|
|
516
|
+
interceptor.on("request", (_0) => __async(this, [_0], function* ({ request, requestId }) {
|
|
517
|
+
const requestCloneForLogs = request.clone();
|
|
518
|
+
const response = yield handleRequest2(
|
|
519
|
+
request,
|
|
520
|
+
requestId,
|
|
521
|
+
context.requestHandlers,
|
|
522
|
+
options,
|
|
523
|
+
context.emitter,
|
|
524
|
+
{
|
|
525
|
+
onMockedResponse(_, { handler, parsedResult }) {
|
|
526
|
+
if (!options.quiet) {
|
|
527
|
+
context.emitter.once("response:mocked", ({ response: response2 }) => {
|
|
528
|
+
handler.log({
|
|
529
|
+
request: requestCloneForLogs,
|
|
530
|
+
response: response2,
|
|
531
|
+
parsedResult
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
);
|
|
538
|
+
if (response) {
|
|
539
|
+
request.respondWith(response);
|
|
540
|
+
}
|
|
541
|
+
}));
|
|
542
|
+
interceptor.on(
|
|
543
|
+
"response",
|
|
544
|
+
({ response, isMockedResponse, request, requestId }) => {
|
|
545
|
+
context.emitter.emit(
|
|
546
|
+
isMockedResponse ? "response:mocked" : "response:bypass",
|
|
547
|
+
{
|
|
548
|
+
response,
|
|
549
|
+
request,
|
|
550
|
+
requestId
|
|
551
|
+
}
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
);
|
|
555
|
+
interceptor.apply();
|
|
556
|
+
return interceptor;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// src/browser/setupWorker/start/createFallbackStart.ts
|
|
560
|
+
function createFallbackStart(context) {
|
|
561
|
+
return function start(options) {
|
|
562
|
+
return __async(this, null, function* () {
|
|
563
|
+
context.fallbackInterceptor = createFallbackRequestListener(
|
|
564
|
+
context,
|
|
565
|
+
options
|
|
566
|
+
);
|
|
567
|
+
printStartMessage({
|
|
568
|
+
message: "Mocking enabled (fallback mode).",
|
|
569
|
+
quiet: options.quiet
|
|
570
|
+
});
|
|
571
|
+
return void 0;
|
|
572
|
+
});
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// src/browser/setupWorker/stop/createFallbackStop.ts
|
|
577
|
+
function createFallbackStop(context) {
|
|
578
|
+
return function stop() {
|
|
579
|
+
var _a, _b;
|
|
580
|
+
(_a = context.fallbackInterceptor) == null ? void 0 : _a.dispose();
|
|
581
|
+
printStopMessage({ quiet: (_b = context.startOptions) == null ? void 0 : _b.quiet });
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// src/browser/setupWorker/setupWorker.ts
|
|
586
|
+
import { devUtils as devUtils9 } from '../core/utils/internal/devUtils.mjs';
|
|
587
|
+
import { SetupApi } from '../core/SetupApi.mjs';
|
|
588
|
+
import { mergeRight as mergeRight2 } from '../core/utils/internal/mergeRight.mjs';
|
|
589
|
+
|
|
590
|
+
// src/browser/utils/supportsReadableStreamTransfer.ts
|
|
591
|
+
function supportsReadableStreamTransfer() {
|
|
592
|
+
try {
|
|
593
|
+
const stream = new ReadableStream({
|
|
594
|
+
start: (controller) => controller.close()
|
|
595
|
+
});
|
|
596
|
+
const message = new MessageChannel();
|
|
597
|
+
message.port1.postMessage(stream, [stream]);
|
|
598
|
+
return true;
|
|
599
|
+
} catch (error) {
|
|
600
|
+
return false;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// src/browser/setupWorker/setupWorker.ts
|
|
605
|
+
var SetupWorkerApi = class extends SetupApi {
|
|
606
|
+
constructor(...handlers) {
|
|
607
|
+
super(...handlers);
|
|
608
|
+
this.startHandler = null;
|
|
609
|
+
this.stopHandler = null;
|
|
610
|
+
invariant(
|
|
611
|
+
!isNodeProcess(),
|
|
612
|
+
devUtils9.formatMessage(
|
|
613
|
+
"Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for Node.js environment instead."
|
|
614
|
+
)
|
|
615
|
+
);
|
|
616
|
+
this.listeners = [];
|
|
617
|
+
this.context = this.createWorkerContext();
|
|
618
|
+
}
|
|
619
|
+
createWorkerContext() {
|
|
620
|
+
const context = {
|
|
621
|
+
// Mocking is not considered enabled until the worker
|
|
622
|
+
// signals back the successful activation event.
|
|
623
|
+
isMockingEnabled: false,
|
|
624
|
+
startOptions: null,
|
|
625
|
+
worker: null,
|
|
626
|
+
registration: null,
|
|
627
|
+
requestHandlers: this.currentHandlers,
|
|
628
|
+
emitter: this.emitter,
|
|
629
|
+
workerChannel: {
|
|
630
|
+
on: (eventType, callback) => {
|
|
631
|
+
this.context.events.addListener(navigator.serviceWorker, "message", (event) => {
|
|
632
|
+
if (event.source !== this.context.worker) {
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
const message = event.data;
|
|
636
|
+
if (!message) {
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
if (message.type === eventType) {
|
|
640
|
+
callback(event, message);
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
},
|
|
644
|
+
send: (type) => {
|
|
645
|
+
var _a;
|
|
646
|
+
(_a = this.context.worker) == null ? void 0 : _a.postMessage(type);
|
|
647
|
+
}
|
|
648
|
+
},
|
|
649
|
+
events: {
|
|
650
|
+
addListener: (target, eventType, callback) => {
|
|
651
|
+
target.addEventListener(eventType, callback);
|
|
652
|
+
this.listeners.push({
|
|
653
|
+
eventType,
|
|
654
|
+
target,
|
|
655
|
+
callback
|
|
656
|
+
});
|
|
657
|
+
return () => {
|
|
658
|
+
target.removeEventListener(eventType, callback);
|
|
659
|
+
};
|
|
660
|
+
},
|
|
661
|
+
removeAllListeners: () => {
|
|
662
|
+
for (const { target, eventType, callback } of this.listeners) {
|
|
663
|
+
target.removeEventListener(eventType, callback);
|
|
664
|
+
}
|
|
665
|
+
this.listeners = [];
|
|
666
|
+
},
|
|
667
|
+
once: (eventType) => {
|
|
668
|
+
const bindings = [];
|
|
669
|
+
return new Promise((resolve, reject) => {
|
|
670
|
+
const handleIncomingMessage = (event) => {
|
|
671
|
+
try {
|
|
672
|
+
const message = event.data;
|
|
673
|
+
if (message.type === eventType) {
|
|
674
|
+
resolve(message);
|
|
675
|
+
}
|
|
676
|
+
} catch (error) {
|
|
677
|
+
reject(error);
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
bindings.push(
|
|
681
|
+
this.context.events.addListener(
|
|
682
|
+
navigator.serviceWorker,
|
|
683
|
+
"message",
|
|
684
|
+
handleIncomingMessage
|
|
685
|
+
),
|
|
686
|
+
this.context.events.addListener(
|
|
687
|
+
navigator.serviceWorker,
|
|
688
|
+
"messageerror",
|
|
689
|
+
reject
|
|
690
|
+
)
|
|
691
|
+
);
|
|
692
|
+
}).finally(() => {
|
|
693
|
+
bindings.forEach((unbind) => unbind());
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
supports: {
|
|
698
|
+
serviceWorkerApi: !("serviceWorker" in navigator) || location.protocol === "file:",
|
|
699
|
+
readableStreamTransfer: supportsReadableStreamTransfer()
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
Object.defineProperties(context, {
|
|
703
|
+
requestHandlers: {
|
|
704
|
+
get: () => this.currentHandlers
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
this.startHandler = context.supports.serviceWorkerApi ? createFallbackStart(context) : createStartHandler(context);
|
|
708
|
+
this.stopHandler = context.supports.serviceWorkerApi ? createFallbackStop(context) : createStop(context);
|
|
709
|
+
return context;
|
|
710
|
+
}
|
|
711
|
+
start() {
|
|
712
|
+
return __async(this, arguments, function* (options = {}) {
|
|
713
|
+
this.context.startOptions = mergeRight2(
|
|
714
|
+
DEFAULT_START_OPTIONS,
|
|
715
|
+
options
|
|
716
|
+
);
|
|
717
|
+
return yield this.startHandler(this.context.startOptions, options);
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
stop() {
|
|
721
|
+
super.dispose();
|
|
722
|
+
this.context.events.removeAllListeners();
|
|
723
|
+
this.context.emitter.removeAllListeners();
|
|
724
|
+
this.stopHandler();
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
function setupWorker(...handlers) {
|
|
728
|
+
return new SetupWorkerApi(...handlers);
|
|
729
|
+
}
|
|
730
|
+
export {
|
|
731
|
+
SetupWorkerApi,
|
|
732
|
+
setupWorker
|
|
733
|
+
};
|