@mswjs/interceptors 0.41.6 → 0.41.8
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/{XMLHttpRequest-DNly-bu0.cjs → XMLHttpRequest-B11I9TBx.cjs} +10 -8
- package/lib/browser/{XMLHttpRequest-DNly-bu0.cjs.map → XMLHttpRequest-B11I9TBx.cjs.map} +1 -1
- package/lib/browser/{XMLHttpRequest-DaQ73vVt.mjs → XMLHttpRequest-DHEkSoRN.mjs} +10 -8
- package/lib/{node/XMLHttpRequest-Cj07Pos7.mjs.map → browser/XMLHttpRequest-DHEkSoRN.mjs.map} +1 -1
- package/lib/browser/{fetch-BS6cxWzo.mjs → fetch-BJwfdses.mjs} +11 -8
- package/lib/browser/{fetch-BS6cxWzo.mjs.map → fetch-BJwfdses.mjs.map} +1 -1
- package/lib/browser/{fetch-BmrYPMQ0.cjs → fetch-M8iXkZ3L.cjs} +11 -8
- package/lib/browser/{fetch-BmrYPMQ0.cjs.map → fetch-M8iXkZ3L.cjs.map} +1 -1
- package/lib/browser/{getRawRequest-BP--nUwn.mjs → getRawRequest-B1BqgWG6.mjs} +39 -15
- package/lib/browser/getRawRequest-B1BqgWG6.mjs.map +1 -0
- package/lib/browser/{getRawRequest-B6GjFKAr.cjs → getRawRequest-DdfaiPVH.cjs} +39 -15
- package/lib/browser/getRawRequest-DdfaiPVH.cjs.map +1 -0
- package/lib/browser/{handleRequest-CnDA8MVO.mjs → handleRequest-1Yqu_ho_.mjs} +3 -3
- package/lib/browser/{handleRequest-CnDA8MVO.mjs.map → handleRequest-1Yqu_ho_.mjs.map} +1 -1
- package/lib/browser/{handleRequest-BIte-8l8.cjs → handleRequest-Cz4_wmQ9.cjs} +3 -3
- package/lib/browser/{handleRequest-BIte-8l8.cjs.map → handleRequest-Cz4_wmQ9.cjs.map} +1 -1
- package/lib/browser/{hasConfigurableGlobal-B39W0thh.mjs → hasConfigurableGlobal-C8zq1MCg.mjs} +34 -23
- package/lib/browser/hasConfigurableGlobal-C8zq1MCg.mjs.map +1 -0
- package/lib/browser/{hasConfigurableGlobal-B5o6PHq3.cjs → hasConfigurableGlobal-CS7adEvV.cjs} +37 -26
- package/lib/browser/hasConfigurableGlobal-CS7adEvV.cjs.map +1 -0
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.d.cts +2 -0
- package/lib/browser/index.d.mts +2 -0
- package/lib/browser/index.mjs +1 -1
- package/lib/browser/interceptors/WebSocket/index.cjs +2 -2
- package/lib/browser/interceptors/WebSocket/index.cjs.map +1 -1
- package/lib/browser/interceptors/WebSocket/index.mjs +2 -2
- package/lib/browser/interceptors/WebSocket/index.mjs.map +1 -1
- package/lib/browser/interceptors/XMLHttpRequest/index.cjs +4 -4
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +4 -4
- package/lib/browser/interceptors/fetch/index.cjs +4 -4
- package/lib/browser/interceptors/fetch/index.mjs +4 -4
- package/lib/browser/presets/browser.cjs +5 -5
- package/lib/browser/presets/browser.mjs +5 -5
- package/lib/node/{BatchInterceptor-0prNZ0wK.mjs → BatchInterceptor-DdMNfSUY.mjs} +2 -2
- package/lib/node/{BatchInterceptor-0prNZ0wK.mjs.map → BatchInterceptor-DdMNfSUY.mjs.map} +1 -1
- package/lib/node/{BatchInterceptor-Bo8JunSK.cjs → BatchInterceptor-Z1lwK23r.cjs} +2 -2
- package/lib/node/{BatchInterceptor-Bo8JunSK.cjs.map → BatchInterceptor-Z1lwK23r.cjs.map} +1 -1
- package/lib/node/{ClientRequest-OY5NnrOh.cjs → ClientRequest-DFs7FPNi.cjs} +8 -7
- package/lib/node/ClientRequest-DFs7FPNi.cjs.map +1 -0
- package/lib/node/{ClientRequest-BquJl6T-.mjs → ClientRequest-dRpI9v1o.mjs} +8 -7
- package/lib/node/ClientRequest-dRpI9v1o.mjs.map +1 -0
- package/lib/node/RemoteHttpInterceptor.cjs +7 -7
- package/lib/node/RemoteHttpInterceptor.mjs +7 -7
- package/lib/node/{XMLHttpRequest-Cj07Pos7.mjs → XMLHttpRequest-DhupxLHX.mjs} +10 -8
- package/lib/{browser/XMLHttpRequest-DaQ73vVt.mjs.map → node/XMLHttpRequest-DhupxLHX.mjs.map} +1 -1
- package/lib/node/{XMLHttpRequest-C1KTngEF.cjs → XMLHttpRequest-Dyi6ahGz.cjs} +10 -8
- package/lib/node/{XMLHttpRequest-C1KTngEF.cjs.map → XMLHttpRequest-Dyi6ahGz.cjs.map} +1 -1
- package/lib/node/{fetch-UxWd1aQX.mjs → fetch-BqMcbuYR.mjs} +11 -8
- package/lib/node/{fetch-UxWd1aQX.mjs.map → fetch-BqMcbuYR.mjs.map} +1 -1
- package/lib/node/{fetch-B9UiBg-M.cjs → fetch-aQJu1Gf_.cjs} +11 -8
- package/lib/node/{fetch-B9UiBg-M.cjs.map → fetch-aQJu1Gf_.cjs.map} +1 -1
- package/lib/node/{fetchUtils-Bq0Mdmkv.mjs → fetchUtils-BKJ1XmiO.mjs} +39 -15
- package/lib/node/{fetchUtils-Bq0Mdmkv.mjs.map → fetchUtils-BKJ1XmiO.mjs.map} +1 -1
- package/lib/node/{fetchUtils-BAlG765A.cjs → fetchUtils-umV5xXBy.cjs} +39 -15
- package/lib/node/{fetchUtils-BAlG765A.cjs.map → fetchUtils-umV5xXBy.cjs.map} +1 -1
- package/lib/node/{handleRequest-u6jpjgrr.mjs → handleRequest-DCLzePtS.mjs} +2 -2
- package/lib/node/{handleRequest-u6jpjgrr.mjs.map → handleRequest-DCLzePtS.mjs.map} +1 -1
- package/lib/node/{handleRequest-DUPo40Df.cjs → handleRequest-DVOthWJo.cjs} +2 -2
- package/lib/node/{handleRequest-DUPo40Df.cjs.map → handleRequest-DVOthWJo.cjs.map} +1 -1
- package/lib/node/{hasConfigurableGlobal-jN_-v3gp.mjs → hasConfigurableGlobal-BiTmog1u.mjs} +34 -23
- package/lib/node/hasConfigurableGlobal-BiTmog1u.mjs.map +1 -0
- package/lib/node/{hasConfigurableGlobal-Befl_QJD.cjs → hasConfigurableGlobal-MjY06_Ok.cjs} +37 -26
- package/lib/node/hasConfigurableGlobal-MjY06_Ok.cjs.map +1 -0
- package/lib/node/index.cjs +2 -2
- package/lib/node/index.d.cts +2 -0
- package/lib/node/index.d.mts +2 -0
- package/lib/node/index.mjs +2 -2
- package/lib/node/interceptors/ClientRequest/index.cjs +3 -3
- package/lib/node/interceptors/ClientRequest/index.mjs +3 -3
- package/lib/node/interceptors/XMLHttpRequest/index.cjs +4 -4
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +4 -4
- package/lib/node/interceptors/fetch/index.cjs +4 -4
- package/lib/node/interceptors/fetch/index.mjs +4 -4
- package/lib/node/presets/node.cjs +6 -6
- package/lib/node/presets/node.mjs +6 -6
- package/package.json +1 -1
- package/src/interceptors/ClientRequest/utils/recordRawHeaders.test.ts +33 -0
- package/src/interceptors/ClientRequest/utils/recordRawHeaders.ts +19 -4
- package/src/interceptors/WebSocket/index.ts +2 -2
- package/src/interceptors/XMLHttpRequest/index.ts +4 -5
- package/src/interceptors/fetch/index.ts +13 -8
- package/src/utils/fetchUtils.test.ts +22 -0
- package/src/utils/fetchUtils.ts +61 -16
- package/src/utils/hasConfigurableGlobal.ts +1 -1
- package/src/utils/patchesRegistry.test.ts +240 -0
- package/src/utils/patchesRegistry.ts +134 -0
- package/lib/browser/getRawRequest-B6GjFKAr.cjs.map +0 -1
- package/lib/browser/getRawRequest-BP--nUwn.mjs.map +0 -1
- package/lib/browser/hasConfigurableGlobal-B39W0thh.mjs.map +0 -1
- package/lib/browser/hasConfigurableGlobal-B5o6PHq3.cjs.map +0 -1
- package/lib/node/ClientRequest-BquJl6T-.mjs.map +0 -1
- package/lib/node/ClientRequest-OY5NnrOh.cjs.map +0 -1
- package/lib/node/hasConfigurableGlobal-Befl_QJD.cjs.map +0 -1
- package/lib/node/hasConfigurableGlobal-jN_-v3gp.mjs.map +0 -1
- package/src/utils/globalUtils.test.ts +0 -144
- package/src/utils/globalsRegistry.ts +0 -107
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { invariant } from 'outvariant'
|
|
2
|
-
|
|
3
|
-
class GlobalsRegistry {
|
|
4
|
-
#globals = new Map<keyof typeof globalThis, () => void>()
|
|
5
|
-
|
|
6
|
-
public replaceGlobal<K extends keyof typeof globalThis>(
|
|
7
|
-
key: K,
|
|
8
|
-
nextValue: (typeof globalThis)[K]
|
|
9
|
-
): () => void {
|
|
10
|
-
invariant(
|
|
11
|
-
!this.#globals.has(key),
|
|
12
|
-
`Failed to replace a global value at "${key}": already replaced.`
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
const match = getDeepPropertyDescriptor(globalThis, key)
|
|
16
|
-
|
|
17
|
-
if (typeof match === 'undefined') {
|
|
18
|
-
console.warn(
|
|
19
|
-
`Failed to replace a global value at "${key}": not a global value.`
|
|
20
|
-
)
|
|
21
|
-
return () => {}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
Object.defineProperty(globalThis, key, {
|
|
25
|
-
value: nextValue,
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: true,
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
const restoreGlobal = () => {
|
|
31
|
-
if (!this.#globals.has(key)) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (match.owner === globalThis) {
|
|
36
|
-
Object.defineProperty(match.owner, key, match.descriptor)
|
|
37
|
-
} else {
|
|
38
|
-
/**
|
|
39
|
-
* @todo Delete the proxy property set by the registry.
|
|
40
|
-
* If the owner isn't `globalThis`, the property is likely nested in the prototype.
|
|
41
|
-
* The registry does not meddle with those, they are left intact.
|
|
42
|
-
*/
|
|
43
|
-
Reflect.deleteProperty(globalThis, key)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.#globals.delete(key)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.#globals.set(key, restoreGlobal)
|
|
50
|
-
|
|
51
|
-
return restoreGlobal
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public restoreAllGlobals(): void {
|
|
55
|
-
const errors: Array<Error> = []
|
|
56
|
-
|
|
57
|
-
for (const [, restoreGlobal] of this.#globals) {
|
|
58
|
-
try {
|
|
59
|
-
restoreGlobal()
|
|
60
|
-
} catch (error) {
|
|
61
|
-
if (error instanceof Error) {
|
|
62
|
-
errors.push(error)
|
|
63
|
-
} else {
|
|
64
|
-
throw error
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (errors.length > 0) {
|
|
70
|
-
throw new AggregateError(errors, 'FOO!')
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export const globalsRegistry = new GlobalsRegistry()
|
|
76
|
-
|
|
77
|
-
interface DeepDescriptorMatch {
|
|
78
|
-
owner: object
|
|
79
|
-
descriptor: PropertyDescriptor
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Returns a property descriptor for the given property on the owner.
|
|
84
|
-
* Walks down the prototype chain if the property does not exist on the owner.
|
|
85
|
-
* Handy for getting a global property descriptor where `globalThis` is
|
|
86
|
-
* replaced with a controlled class (e.g. ServiceWorkerGlobalScope).
|
|
87
|
-
*/
|
|
88
|
-
export function getDeepPropertyDescriptor<Owner extends object>(
|
|
89
|
-
owner: Owner,
|
|
90
|
-
key: keyof Owner
|
|
91
|
-
): DeepDescriptorMatch | undefined {
|
|
92
|
-
let currentOwner: Owner | null = owner
|
|
93
|
-
let descriptor: PropertyDescriptor | undefined
|
|
94
|
-
|
|
95
|
-
while (currentOwner) {
|
|
96
|
-
descriptor = Object.getOwnPropertyDescriptor(currentOwner, key)
|
|
97
|
-
|
|
98
|
-
if (descriptor) {
|
|
99
|
-
return {
|
|
100
|
-
owner: currentOwner,
|
|
101
|
-
descriptor,
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
currentOwner = Object.getPrototypeOf(currentOwner)
|
|
106
|
-
}
|
|
107
|
-
}
|