msw 2.11.2 → 2.11.4
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 +129 -114
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +129 -114
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{HttpResponse-BbwAqLE_.d.ts → HttpResponse-BpT5A_2L.d.ts} +1 -0
- package/lib/core/{HttpResponse-B4YmE-GJ.d.mts → HttpResponse-DGUjNQHG.d.mts} +1 -0
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/HttpResponse.js.map +1 -1
- package/lib/core/HttpResponse.mjs.map +1 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +1 -1
- package/lib/core/graphql.d.ts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.js +0 -5
- package/lib/core/handlers/HttpHandler.js.map +1 -1
- package/lib/core/handlers/HttpHandler.mjs +1 -6
- package/lib/core/handlers/HttpHandler.mjs.map +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +1 -1
- package/lib/core/index.d.ts +1 -1
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.js +1 -1
- package/lib/core/utils/HttpResponse/decorators.js.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.mjs +1 -1
- package/lib/core/utils/HttpResponse/decorators.mjs.map +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +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/core/utils/internal/isHandlerKind.d.mts +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/utils/logging/serializeResponse.js +1 -1
- package/lib/core/utils/logging/serializeResponse.js.map +1 -1
- package/lib/core/utils/logging/serializeResponse.mjs +1 -1
- package/lib/core/utils/logging/serializeResponse.mjs.map +1 -1
- package/lib/core/utils/request/getRequestCookies.js +3 -13
- package/lib/core/utils/request/getRequestCookies.js.map +1 -1
- package/lib/core/utils/request/getRequestCookies.mjs +6 -3
- package/lib/core/utils/request/getRequestCookies.mjs.map +1 -1
- package/lib/core/utils/url/cleanUrl.d.mts +1 -2
- package/lib/core/utils/url/cleanUrl.d.ts +1 -2
- package/lib/core/utils/url/cleanUrl.js +1 -5
- package/lib/core/utils/url/cleanUrl.js.map +1 -1
- package/lib/core/utils/url/cleanUrl.mjs +1 -5
- package/lib/core/utils/url/cleanUrl.mjs.map +1 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.mts +1 -2
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.ts +1 -2
- package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -1
- package/lib/core/ws/WebSocketMemoryClientStore.d.mts +1 -2
- package/lib/core/ws/WebSocketMemoryClientStore.d.ts +1 -2
- package/lib/core/ws/WebSocketMemoryClientStore.js.map +1 -1
- package/lib/core/ws/WebSocketMemoryClientStore.mjs.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +2 -3
- package/lib/core/ws/handleWebSocketEvent.d.ts +2 -3
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
- package/lib/core/ws/utils/getMessageLength.d.mts +1 -1
- package/lib/core/ws/utils/getMessageLength.d.ts +1 -1
- package/lib/core/ws/utils/getMessageLength.js.map +1 -1
- package/lib/core/ws/utils/getMessageLength.mjs.map +1 -1
- package/lib/iife/index.js +595 -636
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +2 -1
- package/lib/shims/cookie.d.mts +7 -0
- package/lib/shims/cookie.d.ts +7 -0
- package/lib/shims/cookie.js +204 -0
- package/lib/shims/cookie.mjs +196 -0
- package/lib/shims/statuses.d.mts +6 -0
- package/lib/shims/statuses.d.ts +6 -0
- package/lib/shims/statuses.js +195 -0
- package/lib/shims/statuses.mjs +187 -0
- package/package.json +7 -8
- package/src/browser/setupWorker/glossary.ts +1 -5
- package/src/browser/setupWorker/setupWorker.ts +4 -9
- package/src/browser/setupWorker/start/createRequestListener.ts +4 -1
- package/src/browser/setupWorker/start/utils/getWorkerInstance.ts +17 -16
- package/src/browser/utils/{supportsReadableStreamTransfer.ts → supports.ts} +13 -0
- package/src/browser/utils/workerChannel.ts +13 -0
- package/src/core/HttpResponse.ts +1 -0
- package/src/core/handlers/HttpHandler.ts +1 -8
- package/src/core/utils/HttpResponse/decorators.ts +1 -1
- package/src/core/utils/handleRequest.ts +8 -8
- package/src/core/utils/logging/serializeResponse.ts +1 -1
- package/src/core/utils/request/getRequestCookies.ts +6 -3
- package/src/core/utils/url/cleanUrl.ts +0 -4
- package/src/core/ws/WebSocketIndexedDBClientStore.ts +1 -1
- package/src/core/ws/WebSocketMemoryClientStore.ts +1 -1
- package/src/core/ws/handleWebSocketEvent.ts +1 -1
- package/src/core/ws/utils/getMessageLength.ts +1 -1
- package/src/mockServiceWorker.js +1 -0
- package/src/shims/cookie.ts +7 -0
- package/src/shims/statuses.ts +6 -0
- package/src/tsconfig.src.json +1 -6
- package/src/browser/utils/deferNetworkRequestsUntil.test.ts +0 -48
- package/src/browser/utils/deferNetworkRequestsUntil.ts +0 -29
package/src/tsconfig.src.json
CHANGED
|
@@ -3,12 +3,7 @@
|
|
|
3
3
|
// living in the "src" directory.
|
|
4
4
|
"extends": "../tsconfig.base.json",
|
|
5
5
|
"compilerOptions": {
|
|
6
|
-
"composite": true
|
|
7
|
-
"baseUrl": "./",
|
|
8
|
-
"paths": {
|
|
9
|
-
"~/core": ["core"],
|
|
10
|
-
"~/core/*": ["core/*"]
|
|
11
|
-
}
|
|
6
|
+
"composite": true
|
|
12
7
|
},
|
|
13
8
|
"include": ["../global.d.ts", "./**/*.ts"],
|
|
14
9
|
"exclude": ["./**/*.test.ts"]
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @vitest-environment jsdom
|
|
3
|
-
*/
|
|
4
|
-
import { deferNetworkRequestsUntil } from './deferNetworkRequestsUntil'
|
|
5
|
-
|
|
6
|
-
beforeAll(() => {
|
|
7
|
-
// Stubs native `fetch` function to remove any external
|
|
8
|
-
// asynchronicity from this test suite.
|
|
9
|
-
window.fetch = vi.fn().mockImplementation(() => {
|
|
10
|
-
return Promise.resolve({
|
|
11
|
-
json: () => ({
|
|
12
|
-
response: 'body',
|
|
13
|
-
}),
|
|
14
|
-
})
|
|
15
|
-
})
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
afterAll(() => {
|
|
19
|
-
vi.restoreAllMocks()
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
test('defers any requests that happen while a given promise is pending', async () => {
|
|
23
|
-
const events: string[] = []
|
|
24
|
-
|
|
25
|
-
// Emulate a Service Worker registration Promise.
|
|
26
|
-
const workerPromise = new Promise<null>((resolve) => {
|
|
27
|
-
setTimeout(resolve, 1000)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
workerPromise.then(() => {
|
|
31
|
-
events.push('promise resolved')
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
// Calling this functions intercepts all requests that happen while
|
|
35
|
-
// the given promise is pending, and defers their execution
|
|
36
|
-
// until the promise is resolved.
|
|
37
|
-
deferNetworkRequestsUntil(workerPromise)
|
|
38
|
-
|
|
39
|
-
// Perform a request.
|
|
40
|
-
const requestPromise = fetch('/user').then(() => {
|
|
41
|
-
events.push('response received')
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
await Promise.all([workerPromise, requestPromise])
|
|
45
|
-
|
|
46
|
-
// Assert the order of resolved events.
|
|
47
|
-
expect(events).toEqual(['promise resolved', 'response received'])
|
|
48
|
-
})
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { until } from '@open-draft/until'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Intercepts and defers any requests on the page
|
|
5
|
-
* until the Service Worker instance is ready.
|
|
6
|
-
* Must only be used in a browser.
|
|
7
|
-
*/
|
|
8
|
-
export function deferNetworkRequestsUntil(predicatePromise: Promise<any>) {
|
|
9
|
-
// Defer any `XMLHttpRequest` requests until the Service Worker is ready.
|
|
10
|
-
const originalXhrSend = window.XMLHttpRequest.prototype.send
|
|
11
|
-
window.XMLHttpRequest.prototype.send = function (
|
|
12
|
-
...args: Parameters<XMLHttpRequest['send']>
|
|
13
|
-
) {
|
|
14
|
-
// Keep this function synchronous to comply with `XMLHttpRequest.prototype.send`,
|
|
15
|
-
// because that method is always synchronous.
|
|
16
|
-
until(() => predicatePromise).then(() => {
|
|
17
|
-
window.XMLHttpRequest.prototype.send = originalXhrSend
|
|
18
|
-
this.send(...args)
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Defer any `fetch` requests until the Service Worker is ready.
|
|
23
|
-
const originalFetch = window.fetch
|
|
24
|
-
window.fetch = async (...args) => {
|
|
25
|
-
await until(() => predicatePromise)
|
|
26
|
-
window.fetch = originalFetch
|
|
27
|
-
return window.fetch(...args)
|
|
28
|
-
}
|
|
29
|
-
}
|