@mswjs/interceptors 0.22.10 → 0.22.11
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/{Interceptor-c794917d.d.ts → Interceptor-c8fc448a.d.ts} +3 -3
- package/lib/browser/{chunk-KX4GZMPY.mjs → chunk-4W72RMFC.mjs} +15 -11
- package/lib/browser/{chunk-OK5YCL7L.js → chunk-ECRLBCQN.js} +55 -55
- package/lib/browser/{chunk-KQGVZIDK.js → chunk-EGQUVEJ3.js} +19 -15
- package/lib/browser/{chunk-2EIH6L6D.js → chunk-KCAWLR7J.js} +25 -25
- package/lib/browser/{chunk-CKVJ2NZB.mjs → chunk-MJZRQFUP.mjs} +67 -54
- package/lib/browser/{chunk-H4SFMU2L.js → chunk-NHFEA72Q.js} +74 -61
- package/lib/browser/{chunk-2GVXYEMC.mjs → chunk-O7B67YBY.mjs} +54 -54
- package/lib/browser/{chunk-65HGG3CV.mjs → chunk-UYUNRMLU.mjs} +1 -1
- package/lib/browser/index.d.ts +3 -3
- package/lib/browser/index.js +8 -8
- package/lib/browser/index.mjs +6 -6
- package/lib/browser/interceptors/XMLHttpRequest/index.d.ts +2 -2
- package/lib/browser/interceptors/XMLHttpRequest/index.js +4 -4
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +3 -3
- package/lib/browser/interceptors/fetch/index.d.ts +2 -2
- package/lib/browser/interceptors/fetch/index.js +3 -3
- package/lib/browser/interceptors/fetch/index.mjs +2 -2
- package/lib/browser/presets/browser.d.ts +2 -2
- package/lib/browser/presets/browser.js +6 -6
- package/lib/browser/presets/browser.mjs +4 -4
- package/lib/node/{BatchInterceptor-5c1e5de3.d.ts → BatchInterceptor-fe69020d.d.ts} +1 -1
- package/lib/node/{Interceptor-b3a4098c.d.ts → Interceptor-f9dfe016.d.ts} +3 -3
- package/lib/node/RemoteHttpInterceptor.d.ts +3 -3
- package/lib/node/RemoteHttpInterceptor.js +25 -19
- package/lib/node/RemoteHttpInterceptor.mjs +21 -15
- package/lib/node/{chunk-VTP5KY7W.js → chunk-2OJRZCGS.js} +71 -58
- package/lib/node/{chunk-6CRMKMDL.mjs → chunk-3V5OWTY7.mjs} +54 -55
- package/lib/node/{chunk-62KFIM4W.js → chunk-6KJ5M2VR.js} +56 -57
- package/lib/node/{chunk-A3X67VOL.js → chunk-7XU7Q63W.js} +111 -94
- package/lib/node/{chunk-MUUQLKVJ.js → chunk-PKB2CXQV.js} +3 -3
- package/lib/node/{chunk-SFLY7F52.js → chunk-RJMXHEGJ.js} +6 -6
- package/lib/node/{chunk-EHQJSMSD.mjs → chunk-RL5IV5PL.mjs} +67 -54
- package/lib/node/{chunk-RFVEKRYP.mjs → chunk-S5A4P4BZ.mjs} +1 -1
- package/lib/node/{chunk-IC6Y7RGW.mjs → chunk-SBAVVQIW.mjs} +5 -5
- package/lib/node/{chunk-W27FTX2A.mjs → chunk-XVHIXGXD.mjs} +111 -94
- package/lib/node/index.d.ts +3 -3
- package/lib/node/index.js +4 -4
- package/lib/node/index.mjs +3 -3
- package/lib/node/interceptors/ClientRequest/index.d.ts +2 -2
- package/lib/node/interceptors/ClientRequest/index.js +3 -3
- package/lib/node/interceptors/ClientRequest/index.mjs +2 -2
- package/lib/node/interceptors/XMLHttpRequest/index.d.ts +2 -2
- package/lib/node/interceptors/XMLHttpRequest/index.js +4 -4
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +3 -3
- package/lib/node/interceptors/fetch/index.d.ts +2 -2
- package/lib/node/interceptors/fetch/index.js +16 -12
- package/lib/node/interceptors/fetch/index.mjs +15 -11
- package/lib/node/presets/node.d.ts +2 -2
- package/lib/node/presets/node.js +6 -6
- package/lib/node/presets/node.mjs +4 -4
- package/package.json +2 -3
- package/src/BatchInterceptor.ts +4 -4
- package/src/Interceptor.ts +27 -27
- package/src/RemoteHttpInterceptor.ts +16 -10
- package/src/interceptors/ClientRequest/NodeClientRequest.test.ts +11 -11
- package/src/interceptors/ClientRequest/NodeClientRequest.ts +47 -38
- package/src/interceptors/ClientRequest/http.request.ts +3 -3
- package/src/interceptors/ClientRequest/index.ts +4 -4
- package/src/interceptors/ClientRequest/utils/createRequest.test.ts +5 -5
- package/src/interceptors/ClientRequest/utils/getIncomingMessageBody.ts +7 -7
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.ts +27 -27
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.ts +4 -4
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.ts +7 -4
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +47 -36
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestProxy.ts +15 -13
- package/src/interceptors/XMLHttpRequest/index.ts +5 -5
- package/src/interceptors/fetch/index.ts +14 -11
- package/src/utils/AsyncEventEmitter.ts +27 -27
- package/src/utils/cloneObject.ts +7 -7
- package/src/utils/getUrlByRequestOptions.ts +13 -13
- package/src/utils/debug.ts +0 -4
package/src/utils/cloneObject.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Logger } from '@open-draft/logger'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const logger = new Logger('cloneObject')
|
|
4
4
|
|
|
5
5
|
function isPlainObject(obj?: Record<string, any>): boolean {
|
|
6
|
-
|
|
6
|
+
logger.info('is plain object?', obj)
|
|
7
7
|
|
|
8
8
|
if (obj == null || !obj.constructor?.name) {
|
|
9
|
-
|
|
9
|
+
logger.info('given object is undefined, not a plain object...')
|
|
10
10
|
return false
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
logger.info('checking the object constructor:', obj.constructor.name)
|
|
14
14
|
return obj.constructor.name === 'Object'
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function cloneObject<ObjectType extends Record<string, any>>(
|
|
18
18
|
obj: ObjectType
|
|
19
19
|
): ObjectType {
|
|
20
|
-
|
|
20
|
+
logger.info('cloning object:', obj)
|
|
21
21
|
|
|
22
22
|
const enumerableProperties = Object.entries(obj).reduce<Record<string, any>>(
|
|
23
23
|
(acc, [key, value]) => {
|
|
24
|
-
|
|
24
|
+
logger.info('analyzing key-value pair:', key, value)
|
|
25
25
|
|
|
26
26
|
// Recursively clone only plain objects, omitting class instances.
|
|
27
27
|
acc[key] = isPlainObject(value) ? cloneObject(value) : value
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Agent } from 'http'
|
|
2
2
|
import { RequestOptions, Agent as HttpsAgent } from 'https'
|
|
3
|
-
import {
|
|
3
|
+
import { Logger } from '@open-draft/logger'
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const logger = new Logger('utils getUrlByRequestOptions')
|
|
6
6
|
|
|
7
7
|
// Request instance constructed by the "request" library
|
|
8
8
|
// has a "self" property that has a "uri" field. This is
|
|
@@ -124,43 +124,43 @@ function getHostname(host: string, port?: number): string {
|
|
|
124
124
|
* Creates a `URL` instance from a given `RequestOptions` object.
|
|
125
125
|
*/
|
|
126
126
|
export function getUrlByRequestOptions(options: ResolvedRequestOptions): URL {
|
|
127
|
-
|
|
127
|
+
logger.info('request options', options)
|
|
128
128
|
|
|
129
129
|
if (options.uri) {
|
|
130
|
-
|
|
130
|
+
logger.info(
|
|
131
131
|
'constructing url from explicitly provided "options.uri": %s',
|
|
132
132
|
options.uri
|
|
133
133
|
)
|
|
134
134
|
return new URL(options.uri.href)
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
logger.info('figuring out url from request options...')
|
|
138
138
|
|
|
139
139
|
const protocol = getProtocolByRequestOptions(options)
|
|
140
|
-
|
|
140
|
+
logger.info('protocol', protocol)
|
|
141
141
|
|
|
142
142
|
const host = getHostByRequestOptions(options)
|
|
143
|
-
|
|
143
|
+
logger.info('host', host)
|
|
144
144
|
|
|
145
145
|
const port = getPortByRequestOptions(options)
|
|
146
|
-
|
|
146
|
+
logger.info('port', port)
|
|
147
147
|
|
|
148
148
|
const hostname = getHostname(host, port)
|
|
149
|
-
|
|
149
|
+
logger.info('hostname', hostname)
|
|
150
150
|
|
|
151
151
|
const path = options.path || DEFAULT_PATH
|
|
152
|
-
|
|
152
|
+
logger.info('path', path)
|
|
153
153
|
|
|
154
154
|
const credentials = getAuthByRequestOptions(options)
|
|
155
|
-
|
|
155
|
+
logger.info('credentials', credentials)
|
|
156
156
|
|
|
157
157
|
const authString = credentials
|
|
158
158
|
? `${credentials.username}:${credentials.password}@`
|
|
159
159
|
: ''
|
|
160
|
-
|
|
160
|
+
logger.info('auth string:', authString)
|
|
161
161
|
|
|
162
162
|
const url = new URL(`${protocol}//${authString}${hostname}${path}`)
|
|
163
|
-
|
|
163
|
+
logger.info('created url:', url)
|
|
164
164
|
|
|
165
165
|
return url
|
|
166
166
|
}
|
package/src/utils/debug.ts
DELETED