msw 0.21.3 → 0.22.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/README.md +3 -9
- package/lib/esm/errors-deps.js +6 -7
- package/lib/esm/fetch-deps.js +44 -22
- package/lib/esm/{matchRequestUrl-deps.js → getCallFrame-deps.js} +32 -5
- package/lib/esm/graphql.js +601 -465
- package/lib/esm/index.js +56 -50
- package/lib/esm/mockServiceWorker.js +16 -10
- package/lib/esm/rest-deps.js +10 -1
- package/lib/esm/rest.js +1 -1
- package/lib/types/context/errors.d.ts +3 -3
- package/lib/types/context/json.d.ts +5 -1
- package/lib/types/index.d.ts +3 -2
- package/lib/types/native/index.d.ts +1 -7
- package/lib/types/node/createSetupServer.d.ts +2 -23
- package/{node/node/createSetupServer.d.ts → lib/types/node/glossary.d.ts} +12 -13
- package/lib/types/node/index.d.ts +1 -0
- package/lib/types/node/setupServer.d.ts +1 -7
- package/lib/types/response.d.ts +7 -2
- package/lib/types/rest.d.ts +60 -30
- package/lib/types/setupWorker/glossary.d.ts +22 -0
- package/lib/types/setupWorker/setupWorker.d.ts +1 -19
- package/lib/types/utils/handlers/requestHandler.d.ts +13 -1
- package/lib/types/utils/internal/getCallFrame.d.ts +4 -0
- package/lib/types/utils/internal/isObject.d.ts +4 -0
- package/lib/types/utils/internal/mergeRight.d.ts +1 -1
- package/lib/types/utils/request/onUnhandledRequest.d.ts +1 -1
- package/lib/umd/index.js +720 -519
- package/lib/umd/mockServiceWorker.js +16 -10
- package/native/index.js +2017 -125
- package/node/index.js +2017 -125
- package/package.json +34 -32
- package/lib/types/LiveStorage.d.ts +0 -17
- package/node/context/delay.d.ts +0 -11
- package/node/context/fetch.d.ts +0 -8
- package/node/context/set.d.ts +0 -2
- package/node/context/status.d.ts +0 -2
- package/node/node/index.d.ts +0 -5
- package/node/node/setupServer.d.ts +0 -7
- package/node/response.d.ts +0 -25
- package/node/utils/NetworkError.d.ts +0 -3
- package/node/utils/getResponse.d.ts +0 -14
- package/node/utils/handlers/requestHandler.d.ts +0 -74
- package/node/utils/handlers/requestHandlerUtils.d.ts +0 -4
- package/node/utils/internal/compose.d.ts +0 -5
- package/node/utils/internal/isNodeProcess.d.ts +0 -5
- package/node/utils/internal/jsonParse.d.ts +0 -5
- package/node/utils/request/getPublicUrlFromRequest.d.ts +0 -6
- package/node/utils/request/onUnhandledRequest.d.ts +0 -5
- package/node/utils/request/parseBody.d.ts +0 -5
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
/* eslint-disable */
|
|
8
8
|
/* tslint:disable */
|
|
9
9
|
|
|
10
|
-
const INTEGRITY_CHECKSUM = '
|
|
10
|
+
const INTEGRITY_CHECKSUM = '65d33ca82955e1c5928aed19d1bdf3f9'
|
|
11
11
|
const bypassHeaderName = 'x-msw-bypass'
|
|
12
12
|
|
|
13
13
|
let clients = {}
|
|
@@ -74,11 +74,22 @@ self.addEventListener('message', async function (event) {
|
|
|
74
74
|
}
|
|
75
75
|
})
|
|
76
76
|
|
|
77
|
-
self.addEventListener('fetch',
|
|
77
|
+
self.addEventListener('fetch', function (event) {
|
|
78
78
|
const { clientId, request } = event
|
|
79
79
|
const requestClone = request.clone()
|
|
80
80
|
const getOriginalResponse = () => fetch(requestClone)
|
|
81
81
|
|
|
82
|
+
// Bypass navigation requests.
|
|
83
|
+
if (request.mode === 'navigate') {
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Bypass mocking if the current client isn't present in the internal clients map
|
|
88
|
+
// (i.e. has the mocking disabled).
|
|
89
|
+
if (!clients[clientId]) {
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
82
93
|
// Opening the DevTools triggers the "only-if-cached" request
|
|
83
94
|
// that cannot be handled by the worker. Bypass such requests.
|
|
84
95
|
if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
|
|
@@ -89,20 +100,15 @@ self.addEventListener('fetch', async function (event) {
|
|
|
89
100
|
new Promise(async (resolve, reject) => {
|
|
90
101
|
const client = await event.target.clients.get(clientId)
|
|
91
102
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
!client ||
|
|
95
|
-
// Bypass mocking if the current client has mocking disabled
|
|
96
|
-
!clients[clientId] ||
|
|
97
|
-
// Bypass mocking for navigation requests
|
|
98
|
-
request.mode === 'navigate'
|
|
99
|
-
) {
|
|
103
|
+
// Bypass mocking when the request client is not active.
|
|
104
|
+
if (!client) {
|
|
100
105
|
return resolve(getOriginalResponse())
|
|
101
106
|
}
|
|
102
107
|
|
|
103
108
|
// Bypass requests with the explicit bypass header
|
|
104
109
|
if (requestClone.headers.get(bypassHeaderName) === 'true') {
|
|
105
110
|
const modifiedHeaders = serializeHeaders(requestClone.headers)
|
|
111
|
+
|
|
106
112
|
// Remove the bypass header to comply with the CORS preflight check
|
|
107
113
|
delete modifiedHeaders[bypassHeaderName]
|
|
108
114
|
|