msw 2.11.2 → 2.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/index.js +33 -24
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +33 -24
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/utils/handleRequest.js +8 -8
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs +8 -8
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/iife/index.js +40 -31
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +4 -4
- package/src/browser/setupWorker/start/utils/getWorkerInstance.ts +17 -16
- package/src/browser/utils/deferNetworkRequestsUntil.ts +1 -1
- package/src/core/utils/handleRequest.ts +8 -8
package/lib/browser/index.js
CHANGED
|
@@ -142,17 +142,16 @@ var DEFAULT_START_OPTIONS = {
|
|
|
142
142
|
// src/browser/setupWorker/start/createStartHandler.ts
|
|
143
143
|
var import_devUtils6 = require("../core/utils/internal/devUtils");
|
|
144
144
|
|
|
145
|
-
// node_modules/.pnpm
|
|
146
|
-
|
|
145
|
+
// node_modules/.pnpm/until-async@3.0.2/node_modules/until-async/lib/index.js
|
|
146
|
+
async function until(callback) {
|
|
147
147
|
try {
|
|
148
|
-
|
|
148
|
+
return [null, await callback().catch((error2) => {
|
|
149
149
|
throw error2;
|
|
150
|
-
});
|
|
151
|
-
return { error: null, data };
|
|
150
|
+
})];
|
|
152
151
|
} catch (error2) {
|
|
153
|
-
return
|
|
152
|
+
return [error2, null];
|
|
154
153
|
}
|
|
155
|
-
}
|
|
154
|
+
}
|
|
156
155
|
|
|
157
156
|
// src/browser/setupWorker/start/utils/getWorkerInstance.ts
|
|
158
157
|
var import_devUtils = require("../core/utils/internal/devUtils");
|
|
@@ -201,19 +200,17 @@ var getWorkerInstance = async (url, options = {}, findWorker) => {
|
|
|
201
200
|
existingRegistration
|
|
202
201
|
];
|
|
203
202
|
}
|
|
204
|
-
const registrationResult = await until(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (registrationResult.error) {
|
|
216
|
-
const isWorkerMissing = registrationResult.error.message.includes("(404)");
|
|
203
|
+
const [registrationError, registrationResult] = await until(async () => {
|
|
204
|
+
const registration = await navigator.serviceWorker.register(url, options);
|
|
205
|
+
return [
|
|
206
|
+
// Compare existing worker registration by its worker URL,
|
|
207
|
+
// to prevent irrelevant workers to resolve here (such as Codesandbox worker).
|
|
208
|
+
getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker),
|
|
209
|
+
registration
|
|
210
|
+
];
|
|
211
|
+
});
|
|
212
|
+
if (registrationError) {
|
|
213
|
+
const isWorkerMissing = registrationError.message.includes("(404)");
|
|
217
214
|
if (isWorkerMissing) {
|
|
218
215
|
const scopeUrl = new URL(options?.scope || "/", location.href);
|
|
219
216
|
throw new Error(
|
|
@@ -227,11 +224,11 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
|
|
|
227
224
|
throw new Error(
|
|
228
225
|
import_devUtils.devUtils.formatMessage(
|
|
229
226
|
"Failed to register the Service Worker:\n\n%s",
|
|
230
|
-
|
|
227
|
+
registrationError.message
|
|
231
228
|
)
|
|
232
229
|
);
|
|
233
230
|
}
|
|
234
|
-
return registrationResult
|
|
231
|
+
return registrationResult;
|
|
235
232
|
};
|
|
236
233
|
|
|
237
234
|
// node_modules/.pnpm/@open-draft+deferred-promise@2.2.0/node_modules/@open-draft/deferred-promise/build/index.mjs
|
|
@@ -1655,6 +1652,18 @@ var WorkerChannel = class extends Emitter2 {
|
|
|
1655
1652
|
}
|
|
1656
1653
|
};
|
|
1657
1654
|
|
|
1655
|
+
// node_modules/.pnpm/@open-draft+until@2.1.0/node_modules/@open-draft/until/lib/index.mjs
|
|
1656
|
+
var until2 = async (promise) => {
|
|
1657
|
+
try {
|
|
1658
|
+
const data = await promise().catch((error2) => {
|
|
1659
|
+
throw error2;
|
|
1660
|
+
});
|
|
1661
|
+
return { error: null, data };
|
|
1662
|
+
} catch (error2) {
|
|
1663
|
+
return { error: error2, data: null };
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1666
|
+
|
|
1658
1667
|
// node_modules/.pnpm/@mswjs+interceptors@0.39.1/node_modules/@mswjs/interceptors/lib/browser/chunk-L37TY7LC.mjs
|
|
1659
1668
|
var InterceptorError = class extends Error {
|
|
1660
1669
|
constructor(message) {
|
|
@@ -1817,7 +1826,7 @@ async function handleRequest2(options) {
|
|
|
1817
1826
|
);
|
|
1818
1827
|
}
|
|
1819
1828
|
}
|
|
1820
|
-
const result = await
|
|
1829
|
+
const result = await until2(async () => {
|
|
1821
1830
|
const requestListenersPromise = emitAsync(options.emitter, "request", {
|
|
1822
1831
|
requestId: options.requestId,
|
|
1823
1832
|
request: options.request,
|
|
@@ -1853,7 +1862,7 @@ async function handleRequest2(options) {
|
|
|
1853
1862
|
unhandledExceptionController[kResponsePromise].resolve(void 0);
|
|
1854
1863
|
}
|
|
1855
1864
|
});
|
|
1856
|
-
const nextResult = await
|
|
1865
|
+
const nextResult = await until2(
|
|
1857
1866
|
() => unhandledExceptionController[kResponsePromise]
|
|
1858
1867
|
);
|
|
1859
1868
|
if (nextResult.error) {
|