@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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkECRLBCQNjs = require('./chunk-ECRLBCQN.js');
|
|
4
4
|
|
|
5
5
|
// node_modules/has-symbols/shams.js
|
|
6
|
-
var require_shams =
|
|
6
|
+
var require_shams = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
7
7
|
"node_modules/has-symbols/shams.js"(exports, module) {
|
|
8
8
|
"use strict";
|
|
9
9
|
module.exports = function hasSymbols() {
|
|
@@ -55,7 +55,7 @@ var require_shams = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
// node_modules/has-tostringtag/shams.js
|
|
58
|
-
var require_shams2 =
|
|
58
|
+
var require_shams2 = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
59
59
|
"node_modules/has-tostringtag/shams.js"(exports, module) {
|
|
60
60
|
"use strict";
|
|
61
61
|
var hasSymbols = require_shams();
|
|
@@ -66,7 +66,7 @@ var require_shams2 = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
// node_modules/call-bind/node_modules/has-symbols/shams.js
|
|
69
|
-
var require_shams3 =
|
|
69
|
+
var require_shams3 = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
70
70
|
"node_modules/call-bind/node_modules/has-symbols/shams.js"(exports, module) {
|
|
71
71
|
"use strict";
|
|
72
72
|
module.exports = function hasSymbols() {
|
|
@@ -118,7 +118,7 @@ var require_shams3 = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
// node_modules/call-bind/node_modules/has-symbols/index.js
|
|
121
|
-
var require_has_symbols =
|
|
121
|
+
var require_has_symbols = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
122
122
|
"node_modules/call-bind/node_modules/has-symbols/index.js"(exports, module) {
|
|
123
123
|
"use strict";
|
|
124
124
|
var origSymbol = typeof Symbol !== "undefined" && Symbol;
|
|
@@ -142,7 +142,7 @@ var require_has_symbols = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
// node_modules/function-bind/implementation.js
|
|
145
|
-
var require_implementation =
|
|
145
|
+
var require_implementation = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
146
146
|
"node_modules/function-bind/implementation.js"(exports, module) {
|
|
147
147
|
"use strict";
|
|
148
148
|
var ERROR_MESSAGE = "Function.prototype.bind called on incompatible ";
|
|
@@ -192,7 +192,7 @@ var require_implementation = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
192
192
|
});
|
|
193
193
|
|
|
194
194
|
// node_modules/function-bind/index.js
|
|
195
|
-
var require_function_bind =
|
|
195
|
+
var require_function_bind = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
196
196
|
"node_modules/function-bind/index.js"(exports, module) {
|
|
197
197
|
"use strict";
|
|
198
198
|
var implementation = require_implementation();
|
|
@@ -201,7 +201,7 @@ var require_function_bind = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
201
201
|
});
|
|
202
202
|
|
|
203
203
|
// node_modules/has/src/index.js
|
|
204
|
-
var require_src =
|
|
204
|
+
var require_src = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
205
205
|
"node_modules/has/src/index.js"(exports, module) {
|
|
206
206
|
"use strict";
|
|
207
207
|
var bind = require_function_bind();
|
|
@@ -210,7 +210,7 @@ var require_src = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
210
210
|
});
|
|
211
211
|
|
|
212
212
|
// node_modules/call-bind/node_modules/get-intrinsic/index.js
|
|
213
|
-
var require_get_intrinsic =
|
|
213
|
+
var require_get_intrinsic = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
214
214
|
"node_modules/call-bind/node_modules/get-intrinsic/index.js"(exports, module) {
|
|
215
215
|
"use strict";
|
|
216
216
|
var undefined2;
|
|
@@ -500,7 +500,7 @@ var require_get_intrinsic = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
500
500
|
});
|
|
501
501
|
|
|
502
502
|
// node_modules/call-bind/index.js
|
|
503
|
-
var require_call_bind =
|
|
503
|
+
var require_call_bind = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
504
504
|
"node_modules/call-bind/index.js"(exports, module) {
|
|
505
505
|
"use strict";
|
|
506
506
|
var bind = require_function_bind();
|
|
@@ -544,7 +544,7 @@ var require_call_bind = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
544
544
|
});
|
|
545
545
|
|
|
546
546
|
// node_modules/call-bind/callBound.js
|
|
547
|
-
var require_callBound =
|
|
547
|
+
var require_callBound = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
548
548
|
"node_modules/call-bind/callBound.js"(exports, module) {
|
|
549
549
|
"use strict";
|
|
550
550
|
var GetIntrinsic = require_get_intrinsic();
|
|
@@ -561,7 +561,7 @@ var require_callBound = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
561
561
|
});
|
|
562
562
|
|
|
563
563
|
// node_modules/is-arguments/index.js
|
|
564
|
-
var require_is_arguments =
|
|
564
|
+
var require_is_arguments = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
565
565
|
"node_modules/is-arguments/index.js"(exports, module) {
|
|
566
566
|
"use strict";
|
|
567
567
|
var hasToStringTag = require_shams2()();
|
|
@@ -588,7 +588,7 @@ var require_is_arguments = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
588
588
|
});
|
|
589
589
|
|
|
590
590
|
// node_modules/is-generator-function/index.js
|
|
591
|
-
var require_is_generator_function =
|
|
591
|
+
var require_is_generator_function = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
592
592
|
"node_modules/is-generator-function/index.js"(exports, module) {
|
|
593
593
|
"use strict";
|
|
594
594
|
var toStr = Object.prototype.toString;
|
|
@@ -630,7 +630,7 @@ var require_is_generator_function = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
630
630
|
});
|
|
631
631
|
|
|
632
632
|
// node_modules/is-callable/index.js
|
|
633
|
-
var require_is_callable =
|
|
633
|
+
var require_is_callable = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
634
634
|
"node_modules/is-callable/index.js"(exports, module) {
|
|
635
635
|
"use strict";
|
|
636
636
|
var fnToStr = Function.prototype.toString;
|
|
@@ -728,7 +728,7 @@ var require_is_callable = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
728
728
|
});
|
|
729
729
|
|
|
730
730
|
// node_modules/for-each/index.js
|
|
731
|
-
var require_for_each =
|
|
731
|
+
var require_for_each = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
732
732
|
"node_modules/for-each/index.js"(exports, module) {
|
|
733
733
|
"use strict";
|
|
734
734
|
var isCallable = require_is_callable();
|
|
@@ -786,7 +786,7 @@ var require_for_each = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
786
786
|
});
|
|
787
787
|
|
|
788
788
|
// node_modules/available-typed-arrays/index.js
|
|
789
|
-
var require_available_typed_arrays =
|
|
789
|
+
var require_available_typed_arrays = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
790
790
|
"node_modules/available-typed-arrays/index.js"(exports, module) {
|
|
791
791
|
"use strict";
|
|
792
792
|
var possibleNames = [
|
|
@@ -816,7 +816,7 @@ var require_available_typed_arrays = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
816
816
|
});
|
|
817
817
|
|
|
818
818
|
// node_modules/has-symbols/index.js
|
|
819
|
-
var require_has_symbols2 =
|
|
819
|
+
var require_has_symbols2 = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
820
820
|
"node_modules/has-symbols/index.js"(exports, module) {
|
|
821
821
|
"use strict";
|
|
822
822
|
var origSymbol = typeof Symbol !== "undefined" && Symbol;
|
|
@@ -840,7 +840,7 @@ var require_has_symbols2 = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
840
840
|
});
|
|
841
841
|
|
|
842
842
|
// node_modules/get-intrinsic/index.js
|
|
843
|
-
var require_get_intrinsic2 =
|
|
843
|
+
var require_get_intrinsic2 = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
844
844
|
"node_modules/get-intrinsic/index.js"(exports, module) {
|
|
845
845
|
"use strict";
|
|
846
846
|
var undefined2;
|
|
@@ -1134,7 +1134,7 @@ var require_get_intrinsic2 = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
1134
1134
|
});
|
|
1135
1135
|
|
|
1136
1136
|
// node_modules/es-abstract/helpers/getOwnPropertyDescriptor.js
|
|
1137
|
-
var require_getOwnPropertyDescriptor =
|
|
1137
|
+
var require_getOwnPropertyDescriptor = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
1138
1138
|
"node_modules/es-abstract/helpers/getOwnPropertyDescriptor.js"(exports, module) {
|
|
1139
1139
|
"use strict";
|
|
1140
1140
|
var GetIntrinsic = require_get_intrinsic2();
|
|
@@ -1151,7 +1151,7 @@ var require_getOwnPropertyDescriptor = _chunkOK5YCL7Ljs.__commonJS.call(void 0,
|
|
|
1151
1151
|
});
|
|
1152
1152
|
|
|
1153
1153
|
// node_modules/is-typed-array/index.js
|
|
1154
|
-
var require_is_typed_array =
|
|
1154
|
+
var require_is_typed_array = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
1155
1155
|
"node_modules/is-typed-array/index.js"(exports, module) {
|
|
1156
1156
|
"use strict";
|
|
1157
1157
|
var forEach = require_for_each();
|
|
@@ -1216,7 +1216,7 @@ var require_is_typed_array = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
1216
1216
|
});
|
|
1217
1217
|
|
|
1218
1218
|
// node_modules/which-typed-array/index.js
|
|
1219
|
-
var require_which_typed_array =
|
|
1219
|
+
var require_which_typed_array = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
1220
1220
|
"node_modules/which-typed-array/index.js"(exports, module) {
|
|
1221
1221
|
"use strict";
|
|
1222
1222
|
var forEach = require_for_each();
|
|
@@ -1275,7 +1275,7 @@ var require_which_typed_array = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
1275
1275
|
});
|
|
1276
1276
|
|
|
1277
1277
|
// node_modules/util/support/types.js
|
|
1278
|
-
var require_types =
|
|
1278
|
+
var require_types = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
1279
1279
|
"node_modules/util/support/types.js"(exports) {
|
|
1280
1280
|
"use strict";
|
|
1281
1281
|
var isArgumentsObject = require_is_arguments();
|
|
@@ -1505,7 +1505,7 @@ var require_types = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
1505
1505
|
});
|
|
1506
1506
|
|
|
1507
1507
|
// node_modules/util/support/isBufferBrowser.js
|
|
1508
|
-
var require_isBufferBrowser =
|
|
1508
|
+
var require_isBufferBrowser = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
1509
1509
|
"node_modules/util/support/isBufferBrowser.js"(exports, module) {
|
|
1510
1510
|
module.exports = function isBuffer(arg) {
|
|
1511
1511
|
return arg && typeof arg === "object" && typeof arg.copy === "function" && typeof arg.fill === "function" && typeof arg.readUInt8 === "function";
|
|
@@ -1514,7 +1514,7 @@ var require_isBufferBrowser = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
1514
1514
|
});
|
|
1515
1515
|
|
|
1516
1516
|
// node_modules/inherits/inherits_browser.js
|
|
1517
|
-
var require_inherits_browser =
|
|
1517
|
+
var require_inherits_browser = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
1518
1518
|
"node_modules/inherits/inherits_browser.js"(exports, module) {
|
|
1519
1519
|
if (typeof Object.create === "function") {
|
|
1520
1520
|
module.exports = function inherits(ctor, superCtor) {
|
|
@@ -1546,7 +1546,7 @@ var require_inherits_browser = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
|
1546
1546
|
});
|
|
1547
1547
|
|
|
1548
1548
|
// node_modules/util/util.js
|
|
1549
|
-
var require_util =
|
|
1549
|
+
var require_util = _chunkECRLBCQNjs.__commonJS.call(void 0, {
|
|
1550
1550
|
"node_modules/util/util.js"(exports) {
|
|
1551
1551
|
var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function getOwnPropertyDescriptors2(obj) {
|
|
1552
1552
|
var keys = Object.keys(obj);
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
decodeBuffer,
|
|
3
3
|
encodeBuffer,
|
|
4
4
|
toArrayBuffer
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-UYUNRMLU.mjs";
|
|
6
6
|
import {
|
|
7
7
|
toInteractiveRequest,
|
|
8
8
|
uuidv4
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
IS_PATCHED_MODULE,
|
|
12
12
|
Interceptor
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-O7B67YBY.mjs";
|
|
14
14
|
|
|
15
15
|
// src/interceptors/XMLHttpRequest/index.ts
|
|
16
16
|
import { invariant as invariant2 } from "outvariant";
|
|
@@ -197,9 +197,9 @@ function createResponse(request, responseBody) {
|
|
|
197
197
|
// src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts
|
|
198
198
|
import { invariant } from "outvariant";
|
|
199
199
|
var XMLHttpRequestController = class {
|
|
200
|
-
constructor(initialRequest,
|
|
200
|
+
constructor(initialRequest, logger) {
|
|
201
201
|
this.initialRequest = initialRequest;
|
|
202
|
-
this.
|
|
202
|
+
this.logger = logger;
|
|
203
203
|
this.method = "GET";
|
|
204
204
|
this.url = null;
|
|
205
205
|
this.events = /* @__PURE__ */ new Map();
|
|
@@ -233,20 +233,20 @@ var XMLHttpRequestController = class {
|
|
|
233
233
|
this.method = method;
|
|
234
234
|
this.url = toAbsoluteUrl(url);
|
|
235
235
|
}
|
|
236
|
-
this.
|
|
237
|
-
this.
|
|
236
|
+
this.logger = this.logger.extend(`${this.method} ${this.url.href}`);
|
|
237
|
+
this.logger.info("open", this.method, this.url.href);
|
|
238
238
|
return invoke();
|
|
239
239
|
}
|
|
240
240
|
case "addEventListener": {
|
|
241
241
|
const [eventName, listener] = args;
|
|
242
242
|
this.registerEvent(eventName, listener);
|
|
243
|
-
this.
|
|
243
|
+
this.logger.info("addEventListener", eventName, listener.name);
|
|
244
244
|
return invoke();
|
|
245
245
|
}
|
|
246
246
|
case "setRequestHeader": {
|
|
247
247
|
const [name, value] = args;
|
|
248
248
|
this.requestHeaders.set(name, value);
|
|
249
|
-
this.
|
|
249
|
+
this.logger.info("setRequestHeader", name, value);
|
|
250
250
|
return invoke();
|
|
251
251
|
}
|
|
252
252
|
case "send": {
|
|
@@ -272,7 +272,7 @@ var XMLHttpRequestController = class {
|
|
|
272
272
|
const onceRequestSettled = ((_a = this.onRequest) == null ? void 0 : _a.call(this, fetchRequest, this.requestId)) || Promise.resolve();
|
|
273
273
|
onceRequestSettled.finally(() => {
|
|
274
274
|
if (this.request.readyState < this.request.LOADING) {
|
|
275
|
-
this.
|
|
275
|
+
this.logger.info(
|
|
276
276
|
"request callback settled but request has not been handled (readystate %d), performing as-is...",
|
|
277
277
|
this.request.readyState
|
|
278
278
|
);
|
|
@@ -293,10 +293,10 @@ var XMLHttpRequestController = class {
|
|
|
293
293
|
const prevEvents = this.events.get(eventName) || [];
|
|
294
294
|
const nextEvents = prevEvents.concat(listener);
|
|
295
295
|
this.events.set(eventName, nextEvents);
|
|
296
|
-
this.
|
|
296
|
+
this.logger.info('registered event "%s"', eventName, listener.name);
|
|
297
297
|
}
|
|
298
298
|
respondWith(response) {
|
|
299
|
-
this.
|
|
299
|
+
this.logger.info(
|
|
300
300
|
"responding with a mocked response: %d %s",
|
|
301
301
|
response.status,
|
|
302
302
|
response.statusText
|
|
@@ -306,13 +306,17 @@ var XMLHttpRequestController = class {
|
|
|
306
306
|
define(this.request, "responseURL", this.url.href);
|
|
307
307
|
this.request.getResponseHeader = new Proxy(this.request.getResponseHeader, {
|
|
308
308
|
apply: (_, __, args) => {
|
|
309
|
-
this.
|
|
309
|
+
this.logger.info("getResponseHeader", args[0]);
|
|
310
310
|
if (this.request.readyState < this.request.HEADERS_RECEIVED) {
|
|
311
|
-
this.
|
|
311
|
+
this.logger.info("headers not received yet, returning null");
|
|
312
312
|
return null;
|
|
313
313
|
}
|
|
314
314
|
const headerValue = response.headers.get(args[0]);
|
|
315
|
-
this.
|
|
315
|
+
this.logger.info(
|
|
316
|
+
'resolved response header "%s" to',
|
|
317
|
+
args[0],
|
|
318
|
+
headerValue
|
|
319
|
+
);
|
|
316
320
|
return headerValue;
|
|
317
321
|
}
|
|
318
322
|
});
|
|
@@ -320,13 +324,13 @@ var XMLHttpRequestController = class {
|
|
|
320
324
|
this.request.getAllResponseHeaders,
|
|
321
325
|
{
|
|
322
326
|
apply: () => {
|
|
323
|
-
this.
|
|
327
|
+
this.logger.info("getAllResponseHeaders");
|
|
324
328
|
if (this.request.readyState < this.request.HEADERS_RECEIVED) {
|
|
325
|
-
this.
|
|
329
|
+
this.logger.info("headers not received yet, returning empty string");
|
|
326
330
|
return "";
|
|
327
331
|
}
|
|
328
332
|
const allHeaders = headersToString(response.headers);
|
|
329
|
-
this.
|
|
333
|
+
this.logger.info("resolved all response headers to", allHeaders);
|
|
330
334
|
return allHeaders;
|
|
331
335
|
}
|
|
332
336
|
}
|
|
@@ -349,7 +353,7 @@ var XMLHttpRequestController = class {
|
|
|
349
353
|
}
|
|
350
354
|
});
|
|
351
355
|
const totalResponseBodyLength = response.headers.has("Content-Length") ? Number(response.headers.get("Content-Length")) : void 0;
|
|
352
|
-
this.
|
|
356
|
+
this.logger.info("calculated response body length", totalResponseBodyLength);
|
|
353
357
|
this.trigger("loadstart", {
|
|
354
358
|
loaded: 0,
|
|
355
359
|
total: totalResponseBodyLength
|
|
@@ -357,7 +361,7 @@ var XMLHttpRequestController = class {
|
|
|
357
361
|
this.setReadyState(this.request.HEADERS_RECEIVED);
|
|
358
362
|
this.setReadyState(this.request.LOADING);
|
|
359
363
|
const finalizeResponse = () => {
|
|
360
|
-
this.
|
|
364
|
+
this.logger.info("finalizing the mocked response...");
|
|
361
365
|
this.setReadyState(this.request.DONE);
|
|
362
366
|
this.trigger("load", {
|
|
363
367
|
loaded: this.responseBuffer.byteLength,
|
|
@@ -369,17 +373,17 @@ var XMLHttpRequestController = class {
|
|
|
369
373
|
});
|
|
370
374
|
};
|
|
371
375
|
if (response.body) {
|
|
372
|
-
this.
|
|
376
|
+
this.logger.info("mocked response has body, streaming...");
|
|
373
377
|
const reader = response.body.getReader();
|
|
374
378
|
const readNextResponseBodyChunk = async () => {
|
|
375
379
|
const { value, done } = await reader.read();
|
|
376
380
|
if (done) {
|
|
377
|
-
this.
|
|
381
|
+
this.logger.info("response body stream done!");
|
|
378
382
|
finalizeResponse();
|
|
379
383
|
return;
|
|
380
384
|
}
|
|
381
385
|
if (value) {
|
|
382
|
-
this.
|
|
386
|
+
this.logger.info("read response body chunk:", value);
|
|
383
387
|
this.responseBuffer = concatArrayBuffer(this.responseBuffer, value);
|
|
384
388
|
this.trigger("progress", {
|
|
385
389
|
loaded: this.responseBuffer.byteLength,
|
|
@@ -397,19 +401,22 @@ var XMLHttpRequestController = class {
|
|
|
397
401
|
return decodeBuffer(this.responseBuffer);
|
|
398
402
|
}
|
|
399
403
|
get response() {
|
|
400
|
-
this.
|
|
404
|
+
this.logger.info(
|
|
405
|
+
"getResponse (responseType: %s)",
|
|
406
|
+
this.request.responseType
|
|
407
|
+
);
|
|
401
408
|
if (this.request.readyState !== this.request.DONE) {
|
|
402
409
|
return null;
|
|
403
410
|
}
|
|
404
411
|
switch (this.request.responseType) {
|
|
405
412
|
case "json": {
|
|
406
413
|
const responseJson = parseJson(this.responseBufferToText());
|
|
407
|
-
this.
|
|
414
|
+
this.logger.info("resolved response JSON", responseJson);
|
|
408
415
|
return responseJson;
|
|
409
416
|
}
|
|
410
417
|
case "arraybuffer": {
|
|
411
418
|
const arrayBuffer = toArrayBuffer(this.responseBuffer);
|
|
412
|
-
this.
|
|
419
|
+
this.logger.info("resolved response ArrayBuffer", arrayBuffer);
|
|
413
420
|
return arrayBuffer;
|
|
414
421
|
}
|
|
415
422
|
case "blob": {
|
|
@@ -417,7 +424,7 @@ var XMLHttpRequestController = class {
|
|
|
417
424
|
const responseBlob = new Blob([this.responseBufferToText()], {
|
|
418
425
|
type: mimeType
|
|
419
426
|
});
|
|
420
|
-
this.
|
|
427
|
+
this.logger.info(
|
|
421
428
|
"resolved response Blob (mime type: %s)",
|
|
422
429
|
responseBlob,
|
|
423
430
|
mimeType
|
|
@@ -426,7 +433,7 @@ var XMLHttpRequestController = class {
|
|
|
426
433
|
}
|
|
427
434
|
default: {
|
|
428
435
|
const responseText = this.responseBufferToText();
|
|
429
|
-
this.
|
|
436
|
+
this.logger.info(
|
|
430
437
|
'resolving "%s" response type as text',
|
|
431
438
|
this.request.responseType,
|
|
432
439
|
responseText
|
|
@@ -444,7 +451,7 @@ var XMLHttpRequestController = class {
|
|
|
444
451
|
return "";
|
|
445
452
|
}
|
|
446
453
|
const responseText = this.responseBufferToText();
|
|
447
|
-
this.
|
|
454
|
+
this.logger.info('getResponseText: "%s"', responseText);
|
|
448
455
|
return responseText;
|
|
449
456
|
}
|
|
450
457
|
get responseXML() {
|
|
@@ -471,35 +478,39 @@ var XMLHttpRequestController = class {
|
|
|
471
478
|
return null;
|
|
472
479
|
}
|
|
473
480
|
errorWith(error) {
|
|
474
|
-
this.
|
|
481
|
+
this.logger.info("responding with an error");
|
|
475
482
|
this.setReadyState(this.request.DONE);
|
|
476
483
|
this.trigger("error");
|
|
477
484
|
this.trigger("loadend");
|
|
478
485
|
}
|
|
479
486
|
setReadyState(nextReadyState) {
|
|
480
|
-
this.
|
|
487
|
+
this.logger.info(
|
|
488
|
+
"setReadyState: %d -> %d",
|
|
489
|
+
this.request.readyState,
|
|
490
|
+
nextReadyState
|
|
491
|
+
);
|
|
481
492
|
if (this.request.readyState === nextReadyState) {
|
|
482
|
-
this.
|
|
493
|
+
this.logger.info("ready state identical, skipping transition...");
|
|
483
494
|
return;
|
|
484
495
|
}
|
|
485
496
|
define(this.request, "readyState", nextReadyState);
|
|
486
|
-
this.
|
|
497
|
+
this.logger.info("set readyState to: %d", nextReadyState);
|
|
487
498
|
if (nextReadyState !== this.request.UNSENT) {
|
|
488
|
-
this.
|
|
499
|
+
this.logger.info('triggerring "readystatechange" event...');
|
|
489
500
|
this.trigger("readystatechange");
|
|
490
501
|
}
|
|
491
502
|
}
|
|
492
503
|
trigger(eventName, options) {
|
|
493
504
|
const callback = this.request[`on${eventName}`];
|
|
494
505
|
const event = createEvent(this.request, eventName, options);
|
|
495
|
-
this.
|
|
506
|
+
this.logger.info('trigger "%s"', eventName, options || "");
|
|
496
507
|
if (typeof callback === "function") {
|
|
497
|
-
this.
|
|
508
|
+
this.logger.info('found a direct "%s" callback, calling...', eventName);
|
|
498
509
|
callback.call(this.request, event);
|
|
499
510
|
}
|
|
500
511
|
for (const [registeredEventName, listeners] of this.events) {
|
|
501
512
|
if (registeredEventName === eventName) {
|
|
502
|
-
this.
|
|
513
|
+
this.logger.info(
|
|
503
514
|
'found %d listener(s) for "%s" event, calling...',
|
|
504
515
|
listeners.length,
|
|
505
516
|
eventName
|
|
@@ -509,7 +520,7 @@ var XMLHttpRequestController = class {
|
|
|
509
520
|
}
|
|
510
521
|
}
|
|
511
522
|
toFetchApiRequest() {
|
|
512
|
-
this.
|
|
523
|
+
this.logger.info("converting request to a Fetch API Request...");
|
|
513
524
|
const fetchRequest = new Request(this.url.href, {
|
|
514
525
|
method: this.method,
|
|
515
526
|
headers: this.requestHeaders,
|
|
@@ -537,7 +548,7 @@ var XMLHttpRequestController = class {
|
|
|
537
548
|
}
|
|
538
549
|
});
|
|
539
550
|
define(fetchRequest, "headers", proxyHeaders);
|
|
540
|
-
this.
|
|
551
|
+
this.logger.info("converted request to a Fetch API Request!", fetchRequest);
|
|
541
552
|
return fetchRequest;
|
|
542
553
|
}
|
|
543
554
|
};
|
|
@@ -555,11 +566,11 @@ function define(target, property, value) {
|
|
|
555
566
|
// src/interceptors/XMLHttpRequest/XMLHttpRequestProxy.ts
|
|
556
567
|
function createXMLHttpRequestProxy({
|
|
557
568
|
emitter,
|
|
558
|
-
|
|
569
|
+
logger
|
|
559
570
|
}) {
|
|
560
571
|
const XMLHttpRequestProxy = new Proxy(globalThis.XMLHttpRequest, {
|
|
561
572
|
construct(target, args, newTarget) {
|
|
562
|
-
|
|
573
|
+
logger.info("constructed new XMLHttpRequest");
|
|
563
574
|
const originalRequest = Reflect.construct(target, args, newTarget);
|
|
564
575
|
const prototypeDescriptors = Object.getOwnPropertyDescriptors(
|
|
565
576
|
target.prototype
|
|
@@ -573,16 +584,16 @@ function createXMLHttpRequestProxy({
|
|
|
573
584
|
}
|
|
574
585
|
const requestController = new XMLHttpRequestController(
|
|
575
586
|
originalRequest,
|
|
576
|
-
|
|
587
|
+
logger
|
|
577
588
|
);
|
|
578
589
|
requestController.onRequest = async function(request, requestId) {
|
|
579
590
|
const interactiveRequest = toInteractiveRequest(request);
|
|
580
|
-
this.
|
|
591
|
+
this.logger.info(
|
|
581
592
|
'emitting the "request" event for %s listener(s)...',
|
|
582
593
|
emitter.listenerCount("request")
|
|
583
594
|
);
|
|
584
595
|
emitter.emit("request", interactiveRequest, requestId);
|
|
585
|
-
this.
|
|
596
|
+
this.logger.info("awaiting mocked response...");
|
|
586
597
|
const resolverResult = await until(async () => {
|
|
587
598
|
await emitter.untilIdle(
|
|
588
599
|
"request",
|
|
@@ -590,13 +601,13 @@ function createXMLHttpRequestProxy({
|
|
|
590
601
|
return pendingRequestId === requestId;
|
|
591
602
|
}
|
|
592
603
|
);
|
|
593
|
-
this.
|
|
604
|
+
this.logger.info('all "request" listeners settled!');
|
|
594
605
|
const [mockedResponse2] = await interactiveRequest.respondWith.invoked();
|
|
595
|
-
this.
|
|
606
|
+
this.logger.info("event.respondWith called with:", mockedResponse2);
|
|
596
607
|
return mockedResponse2;
|
|
597
608
|
});
|
|
598
609
|
if (resolverResult.error) {
|
|
599
|
-
this.
|
|
610
|
+
this.logger.info(
|
|
600
611
|
"request listener threw an exception, aborting request...",
|
|
601
612
|
resolverResult.error
|
|
602
613
|
);
|
|
@@ -605,17 +616,19 @@ function createXMLHttpRequestProxy({
|
|
|
605
616
|
}
|
|
606
617
|
const mockedResponse = resolverResult.data;
|
|
607
618
|
if (typeof mockedResponse !== "undefined") {
|
|
608
|
-
this.
|
|
619
|
+
this.logger.info(
|
|
609
620
|
"received mocked response: %d %s",
|
|
610
621
|
mockedResponse.status,
|
|
611
622
|
mockedResponse.statusText
|
|
612
623
|
);
|
|
613
624
|
return requestController.respondWith(mockedResponse);
|
|
614
625
|
}
|
|
615
|
-
this.
|
|
626
|
+
this.logger.info(
|
|
627
|
+
"no mocked response received, performing request as-is..."
|
|
628
|
+
);
|
|
616
629
|
};
|
|
617
630
|
requestController.onResponse = async function(response, request, requestId) {
|
|
618
|
-
this.
|
|
631
|
+
this.logger.info(
|
|
619
632
|
'emitting the "response" event for %s listener(s)...',
|
|
620
633
|
emitter.listenerCount("response")
|
|
621
634
|
);
|
|
@@ -636,8 +649,8 @@ var _XMLHttpRequestInterceptor = class extends Interceptor {
|
|
|
636
649
|
return typeof globalThis.XMLHttpRequest !== "undefined";
|
|
637
650
|
}
|
|
638
651
|
setup() {
|
|
639
|
-
const
|
|
640
|
-
|
|
652
|
+
const logger = this.logger.extend("setup");
|
|
653
|
+
logger.info('patching "XMLHttpRequest" module...');
|
|
641
654
|
const PureXMLHttpRequest = globalThis.XMLHttpRequest;
|
|
642
655
|
invariant2(
|
|
643
656
|
!PureXMLHttpRequest[IS_PATCHED_MODULE],
|
|
@@ -645,9 +658,9 @@ var _XMLHttpRequestInterceptor = class extends Interceptor {
|
|
|
645
658
|
);
|
|
646
659
|
globalThis.XMLHttpRequest = createXMLHttpRequestProxy({
|
|
647
660
|
emitter: this.emitter,
|
|
648
|
-
|
|
661
|
+
logger: this.logger
|
|
649
662
|
});
|
|
650
|
-
|
|
663
|
+
logger.info(
|
|
651
664
|
'native "XMLHttpRequest" module patched!',
|
|
652
665
|
globalThis.XMLHttpRequest.name
|
|
653
666
|
);
|
|
@@ -661,7 +674,7 @@ var _XMLHttpRequestInterceptor = class extends Interceptor {
|
|
|
661
674
|
value: void 0
|
|
662
675
|
});
|
|
663
676
|
globalThis.XMLHttpRequest = PureXMLHttpRequest;
|
|
664
|
-
|
|
677
|
+
logger.info(
|
|
665
678
|
'native "XMLHttpRequest" module restored!',
|
|
666
679
|
globalThis.XMLHttpRequest.name
|
|
667
680
|
);
|