@mswjs/interceptors 0.13.4 → 0.14.0
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/interceptors/ClientRequest/NodeClientRequest.d.ts +1 -1
- package/lib/interceptors/ClientRequest/NodeClientRequest.js +97 -104
- package/lib/interceptors/ClientRequest/NodeClientRequest.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.d.ts +3 -0
- package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js +46 -23
- package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js.map +1 -1
- package/lib/remote.js.map +1 -1
- package/package.json +12 -9
- package/src/interceptors/ClientRequest/NodeClientRequest.ts +89 -82
- package/src/interceptors/ClientRequest/utils/cloneIncomingMessage.test.ts +12 -7
- package/src/interceptors/ClientRequest/utils/cloneIncomingMessage.ts +54 -21
- package/src/remote.ts +4 -6
|
@@ -26,7 +26,7 @@ export declare class NodeClientRequest extends ClientRequest {
|
|
|
26
26
|
requestBody: Buffer[];
|
|
27
27
|
constructor([url, requestOptions, callback]: NormalizedClientRequestArgs, options: NodeClientOptions);
|
|
28
28
|
write(...args: ClientRequestWriteArgs): boolean;
|
|
29
|
-
end(...args: any):
|
|
29
|
+
end(...args: any): this;
|
|
30
30
|
emit(event: string, ...data: any[]): boolean;
|
|
31
31
|
private respondWith;
|
|
32
32
|
/**
|
|
@@ -147,117 +147,110 @@ var NodeClientRequest = /** @class */ (function (_super) {
|
|
|
147
147
|
return true;
|
|
148
148
|
};
|
|
149
149
|
NodeClientRequest.prototype.end = function () {
|
|
150
|
+
var _this = this;
|
|
150
151
|
var args = [];
|
|
151
152
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
152
153
|
args[_i] = arguments[_i];
|
|
153
154
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
// existing server.
|
|
208
|
-
this.log('writing request chunks...', this.chunks);
|
|
209
|
-
try {
|
|
210
|
-
for (_c = __values(this.chunks), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
211
|
-
_e = _d.value, chunk_1 = _e.chunk, encoding_1 = _e.encoding, callback_1 = _e.callback;
|
|
212
|
-
encoding_1
|
|
213
|
-
? _super.prototype.write.call(this, chunk_1, encoding_1, callback_1)
|
|
214
|
-
: _super.prototype.write.call(this, chunk_1, callback_1);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
218
|
-
finally {
|
|
219
|
-
try {
|
|
220
|
-
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
221
|
-
}
|
|
222
|
-
finally { if (e_1) throw e_1.error; }
|
|
223
|
-
}
|
|
224
|
-
this.once('error', function (error) {
|
|
225
|
-
_this.log('original request error:', error);
|
|
226
|
-
});
|
|
227
|
-
this.once('abort', function () {
|
|
228
|
-
_this.log('original request aborted!');
|
|
229
|
-
});
|
|
230
|
-
this.once('response-internal', function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
231
|
-
var responseBody;
|
|
232
|
-
return __generator(this, function (_a) {
|
|
233
|
-
switch (_a.label) {
|
|
234
|
-
case 0: return [4 /*yield*/, getIncomingMessageBody_1.getIncomingMessageBody(response)];
|
|
235
|
-
case 1:
|
|
236
|
-
responseBody = _a.sent();
|
|
237
|
-
this.log(response.statusCode, response.statusMessage, responseBody);
|
|
238
|
-
this.log('original response headers:', response.headers);
|
|
239
|
-
this.observer.emit('response', isomorphicRequest, {
|
|
240
|
-
status: response.statusCode || 200,
|
|
241
|
-
statusText: response.statusMessage || 'OK',
|
|
242
|
-
headers: lib_1.objectToHeaders(response.headers),
|
|
243
|
-
body: responseBody,
|
|
244
|
-
});
|
|
245
|
-
return [2 /*return*/];
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
}); });
|
|
249
|
-
this.log('performing original request...');
|
|
250
|
-
return [2 /*return*/, _super.prototype.end.apply(this, __spreadArray([], __read([
|
|
251
|
-
chunk,
|
|
252
|
-
encoding,
|
|
253
|
-
function () {
|
|
254
|
-
_this.log('original request end!');
|
|
255
|
-
callback === null || callback === void 0 ? void 0 : callback();
|
|
256
|
-
},
|
|
257
|
-
].filter(Boolean))))];
|
|
155
|
+
this.log('end', args);
|
|
156
|
+
var _a = __read(normalizeClientRequestEndArgs_1.normalizeClientRequestEndArgs.apply(void 0, __spreadArray([], __read(args))), 3), chunk = _a[0], encoding = _a[1], callback = _a[2];
|
|
157
|
+
this.log('normalized arguments:', { chunk: chunk, encoding: encoding, callback: callback });
|
|
158
|
+
var requestBody = this.getRequestBody(chunk);
|
|
159
|
+
var isomorphicRequest = this.toIsomorphicRequest(requestBody);
|
|
160
|
+
this.observer.emit('request', isomorphicRequest);
|
|
161
|
+
this.log('executing response resolver...');
|
|
162
|
+
// Execute the resolver Promise like a side-effect.
|
|
163
|
+
// Node.js 16 forces "ClientRequest.end" to be synchronous and return "this".
|
|
164
|
+
until_1.until(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
165
|
+
return [2 /*return*/, this.resolver(isomorphicRequest, this.response)];
|
|
166
|
+
}); }); }).then(function (_a) {
|
|
167
|
+
var e_1, _b;
|
|
168
|
+
var _c = __read(_a, 2), resolverException = _c[0], mockedResponse = _c[1];
|
|
169
|
+
// Halt the request whenever the resolver throws an exception.
|
|
170
|
+
if (resolverException) {
|
|
171
|
+
_this.log('encountered resolver exception, aborting request...', resolverException);
|
|
172
|
+
_this.emit('error', resolverException);
|
|
173
|
+
_this.terminate();
|
|
174
|
+
return _this;
|
|
175
|
+
}
|
|
176
|
+
if (mockedResponse) {
|
|
177
|
+
_this.log('received mocked response:', mockedResponse);
|
|
178
|
+
_this.responseSource = 'mock';
|
|
179
|
+
var isomorphicResponse = toIsoResponse_1.toIsoResponse(mockedResponse);
|
|
180
|
+
_this.respondWith(mockedResponse);
|
|
181
|
+
_this.log(isomorphicResponse.status, isomorphicResponse.statusText, isomorphicResponse.body, '(MOCKED)');
|
|
182
|
+
callback === null || callback === void 0 ? void 0 : callback();
|
|
183
|
+
_this.log('emitting the custom "response" event...');
|
|
184
|
+
_this.observer.emit('response', isomorphicRequest, isomorphicResponse);
|
|
185
|
+
return _this;
|
|
186
|
+
}
|
|
187
|
+
_this.log('no mocked response found!');
|
|
188
|
+
// Set the response source to "bypass".
|
|
189
|
+
// Any errors emitted past this point are not suppressed.
|
|
190
|
+
_this.responseSource = 'bypass';
|
|
191
|
+
// Propagate previously captured errors.
|
|
192
|
+
// For example, a ECONNREFUSED error when connecting to a non-existing host.
|
|
193
|
+
if (_this.capturedError) {
|
|
194
|
+
_this.emit('error', _this.capturedError);
|
|
195
|
+
return _this;
|
|
196
|
+
}
|
|
197
|
+
// Write the request body chunks in the order of ".write()" calls.
|
|
198
|
+
// Note that no request body has been written prior to this point
|
|
199
|
+
// in order to prevent the Socket to communicate with a potentially
|
|
200
|
+
// existing server.
|
|
201
|
+
_this.log('writing request chunks...', _this.chunks);
|
|
202
|
+
try {
|
|
203
|
+
for (var _d = __values(_this.chunks), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
204
|
+
var _f = _e.value, chunk_1 = _f.chunk, encoding_1 = _f.encoding, callback_1 = _f.callback;
|
|
205
|
+
encoding_1
|
|
206
|
+
? _super.prototype.write.call(_this, chunk_1, encoding_1, callback_1)
|
|
207
|
+
: _super.prototype.write.call(_this, chunk_1, callback_1);
|
|
258
208
|
}
|
|
209
|
+
}
|
|
210
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
211
|
+
finally {
|
|
212
|
+
try {
|
|
213
|
+
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
214
|
+
}
|
|
215
|
+
finally { if (e_1) throw e_1.error; }
|
|
216
|
+
}
|
|
217
|
+
_this.once('error', function (error) {
|
|
218
|
+
_this.log('original request error:', error);
|
|
219
|
+
});
|
|
220
|
+
_this.once('abort', function () {
|
|
221
|
+
_this.log('original request aborted!');
|
|
259
222
|
});
|
|
223
|
+
_this.once('response-internal', function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
224
|
+
var responseBody;
|
|
225
|
+
return __generator(this, function (_a) {
|
|
226
|
+
switch (_a.label) {
|
|
227
|
+
case 0: return [4 /*yield*/, getIncomingMessageBody_1.getIncomingMessageBody(response)];
|
|
228
|
+
case 1:
|
|
229
|
+
responseBody = _a.sent();
|
|
230
|
+
this.log(response.statusCode, response.statusMessage, responseBody);
|
|
231
|
+
this.log('original response headers:', response.headers);
|
|
232
|
+
this.log('emitting the custom "response" event...');
|
|
233
|
+
this.observer.emit('response', isomorphicRequest, {
|
|
234
|
+
status: response.statusCode || 200,
|
|
235
|
+
statusText: response.statusMessage || 'OK',
|
|
236
|
+
headers: lib_1.objectToHeaders(response.headers),
|
|
237
|
+
body: responseBody,
|
|
238
|
+
});
|
|
239
|
+
return [2 /*return*/];
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}); });
|
|
243
|
+
_this.log('performing original request...');
|
|
244
|
+
return _super.prototype.end.apply(_this, __spreadArray([], __read([
|
|
245
|
+
chunk,
|
|
246
|
+
encoding,
|
|
247
|
+
function () {
|
|
248
|
+
_this.log('original request end!');
|
|
249
|
+
callback === null || callback === void 0 ? void 0 : callback();
|
|
250
|
+
},
|
|
251
|
+
].filter(Boolean))));
|
|
260
252
|
});
|
|
253
|
+
return this;
|
|
261
254
|
};
|
|
262
255
|
NodeClientRequest.prototype.emit = function (event) {
|
|
263
256
|
var data = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeClientRequest.js","sourceRoot":"","sources":["../../../src/interceptors/ClientRequest/NodeClientRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAuC;AAEvC,6BAAqD;AACrD,2CAAyC;AACzC,4CAA+D;AAO/D,yCAAyC;AACzC,mEAAiE;AACjE,uFAG8C;AAE9C,2DAAyD;AACzD,yEAAuE;AACvE,iEAA+D;AAC/D,2FAIgD;AAChD,qEAAmE;AASnE;IAAuC,qCAAa;IAuBlD,2BACE,EAA4D,EAC5D,OAA0B;YAD1B,KAAA,aAA4D,EAA3D,GAAG,QAAA,EAAE,cAAc,QAAA,EAAE,QAAQ,QAAA;QADhC,YAIE,kBAAM,cAAc,EAAE,QAAQ,CAAC,SAgBhC;QA9BO,YAAM,GAIT,EAAE,CAAA;QACC,oBAAc,GAAsB,MAAM,CAAA;QAG3C,iBAAW,GAAa,EAAE,CAAA;QAQ/B,KAAI,CAAC,GAAG,GAAG,aAAK,CAAC,UAAQ,cAAc,CAAC,MAAM,SAAI,GAAG,CAAC,IAAM,CAAC,CAAA;QAC7D,KAAI,CAAC,GAAG,CAAC,+BAA+B,EAAE;YACxC,GAAG,KAAA;YACH,cAAc,gBAAA;YACd,QAAQ,UAAA;SACT,CAAC,CAAA;QAEF,KAAI,CAAC,GAAG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AC,uCAAuC,CAAC,CAAA;QAEjD,IAAM,eAAe,GAAG,IAAI,CAAC,UAAU,EAAE,CAAA;QACzC,IAAI,CAAC,GAAG,CAAC,2BAA2B,EAAE,eAAe,CAAC,CAAA;QAEtD,IAAM,OAAO,GAAG,IAAI,aAAO,EAAE,CAAA;;YAC7B,KAAwC,IAAA,KAAA,SAAA,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAA,gBAAA,4BAAE;gBAA9D,IAAA,KAAA,mBAAyB,EAAxB,UAAU,QAAA,EAAE,WAAW,QAAA;gBACjC,IAAI,CAAC,WAAW,EAAE;oBAChB,SAAQ;iBACT;gBAED,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAA;aAC9D;;;;;;;;;QAED,IAAM,iBAAiB,GAAsB;YAC3C,EAAE,EAAE,aAAM,EAAE;YACZ,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,KAAK;YACpC,WAAW,EAAE,MAAM;YACnB,OAAO,SAAA;YACP,IAAI,MAAA;SACL,CAAA;QAED,IAAI,CAAC,GAAG,CAAC,0CAA0C,EAAE,iBAAiB,CAAC,CAAA;QACvE,OAAO,iBAAiB,CAAA;IAC1B,CAAC;IA1VD;;;OAGG;IACI,oCAAkB,GAAG,CAAC,WAAW,EAAE,cAAc,EAAE,YAAY,CAAC,CAAA;IAuVzE,wBAAC;CAAA,AA5VD,CAAuC,oBAAa,GA4VnD;AA5VY,8CAAiB"}
|
|
@@ -4,4 +4,7 @@ export declare const IS_CLONE: unique symbol;
|
|
|
4
4
|
export interface ClonedIncomingMessage extends IncomingMessage {
|
|
5
5
|
[IS_CLONE]: boolean;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Clones a given `http.IncomingMessage` instance.
|
|
9
|
+
*/
|
|
7
10
|
export declare function cloneIncomingMessage(message: IncomingMessage): ClonedIncomingMessage;
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __read = (this && this.__read) || function (o, n) {
|
|
14
3
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
4
|
if (!m) return o;
|
|
@@ -44,20 +33,60 @@ var __values = (this && this.__values) || function(o) {
|
|
|
44
33
|
};
|
|
45
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
35
|
exports.cloneIncomingMessage = exports.IS_CLONE = void 0;
|
|
36
|
+
var http_1 = require("http");
|
|
47
37
|
var stream_1 = require("stream");
|
|
48
38
|
exports.IS_CLONE = Symbol('isClone');
|
|
39
|
+
/**
|
|
40
|
+
* Clones a given `http.IncomingMessage` instance.
|
|
41
|
+
*/
|
|
49
42
|
function cloneIncomingMessage(message) {
|
|
43
|
+
var clone = message.pipe(new stream_1.PassThrough());
|
|
44
|
+
// Inherit all direct "IncomingMessage" properties.
|
|
45
|
+
inheritProperties(message, clone);
|
|
46
|
+
// Deeply inherit the message prototypes (Readable, Stream, EventEmitter, etc.).
|
|
47
|
+
var clonedPrototype = Object.create(http_1.IncomingMessage.prototype);
|
|
48
|
+
getPrototypes(clone).forEach(function (prototype) {
|
|
49
|
+
inheritProperties(prototype, clonedPrototype);
|
|
50
|
+
});
|
|
51
|
+
Object.setPrototypeOf(clone, clonedPrototype);
|
|
52
|
+
Object.defineProperty(clone, exports.IS_CLONE, {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
value: true,
|
|
55
|
+
});
|
|
56
|
+
return clone;
|
|
57
|
+
}
|
|
58
|
+
exports.cloneIncomingMessage = cloneIncomingMessage;
|
|
59
|
+
/**
|
|
60
|
+
* Returns a list of all prototypes the given object extends.
|
|
61
|
+
*/
|
|
62
|
+
function getPrototypes(source) {
|
|
63
|
+
var prototypes = [];
|
|
64
|
+
var current = source;
|
|
65
|
+
while ((current = Object.getPrototypeOf(current))) {
|
|
66
|
+
prototypes.push(current);
|
|
67
|
+
}
|
|
68
|
+
return prototypes;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Inherits a given target object properties and symbols
|
|
72
|
+
* onto the given source object.
|
|
73
|
+
* @param source Object which should acquire properties.
|
|
74
|
+
* @param target Object to inherit the properties from.
|
|
75
|
+
*/
|
|
76
|
+
function inheritProperties(source, target) {
|
|
50
77
|
var e_1, _a;
|
|
51
|
-
var
|
|
52
|
-
var properties = __spreadArray(__spreadArray([], __read(Object.getOwnPropertyNames(message))), __read(Object.getOwnPropertySymbols(message)));
|
|
78
|
+
var properties = __spreadArray(__spreadArray([], __read(Object.getOwnPropertyNames(source))), __read(Object.getOwnPropertySymbols(source)));
|
|
53
79
|
try {
|
|
54
80
|
for (var properties_1 = __values(properties), properties_1_1 = properties_1.next(); !properties_1_1.done; properties_1_1 = properties_1.next()) {
|
|
55
|
-
var
|
|
56
|
-
if (
|
|
81
|
+
var property = properties_1_1.value;
|
|
82
|
+
if (target.hasOwnProperty(property)) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
var descriptor = Object.getOwnPropertyDescriptor(source, property);
|
|
86
|
+
if (!descriptor) {
|
|
57
87
|
continue;
|
|
58
88
|
}
|
|
59
|
-
|
|
60
|
-
Object.defineProperty(stream, propertyName, __assign(__assign({}, propertyDescriptor), { value: message[propertyName] }));
|
|
89
|
+
Object.defineProperty(target, property, descriptor);
|
|
61
90
|
}
|
|
62
91
|
}
|
|
63
92
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -67,11 +96,5 @@ function cloneIncomingMessage(message) {
|
|
|
67
96
|
}
|
|
68
97
|
finally { if (e_1) throw e_1.error; }
|
|
69
98
|
}
|
|
70
|
-
Object.defineProperty(stream, exports.IS_CLONE, {
|
|
71
|
-
enumerable: true,
|
|
72
|
-
value: true,
|
|
73
|
-
});
|
|
74
|
-
return stream;
|
|
75
99
|
}
|
|
76
|
-
exports.cloneIncomingMessage = cloneIncomingMessage;
|
|
77
100
|
//# sourceMappingURL=cloneIncomingMessage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloneIncomingMessage.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/cloneIncomingMessage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cloneIncomingMessage.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/cloneIncomingMessage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAAsC;AACtC,iCAAoC;AAEvB,QAAA,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;AAMzC;;GAEG;AACH,SAAgB,oBAAoB,CAClC,OAAwB;IAExB,IAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,oBAAW,EAAE,CAAC,CAAA;IAE7C,mDAAmD;IACnD,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAEjC,gFAAgF;IAChF,IAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAe,CAAC,SAAS,CAAC,CAAA;IAChE,aAAa,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,UAAC,SAAS;QACrC,iBAAiB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;IACF,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,eAAe,CAAC,CAAA;IAE7C,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,g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BAFhD;;oBAHK,mBAAiB,SAGtB;oBAGK,kBAAkB,GAAG,IAAI,CAAC,SAAS,CAAC,gBAAc,CAAC,CAAA;oBACzD,OAAO,CAAC,OAAO,CAAC,IAAI,CAClB,cAAY,YAAU,CAAC,EAAE,SAAI,kBAAoB,EACjD,UAAC,KAAK;wBACJ,IAAI,KAAK,EAAE;4BACT,OAAM;yBACP;wBAED,IAAI,gBAAc,EAAE;4BAClB,sDAAsD;4BACtD,yEAAyE;4BACzE,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,YAAU,EAAE,6BAAa,CAAC,gBAAc,CAAC,CAAC,CAAA;yBACrE;oBACH,CAAC,CACF,CAAA;;;;;SAEJ,CAAA;IAED,IAAM,OAAO,GAAG;QACd,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAA;IAC/D,CAAC,CAAA;IAED,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAA;IAC1D,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;IAClD,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC7C,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAE5C,OAAO;QACL,EAAE,YAAC,KAAK,EAAE,QAAQ;YAChB,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QACvC,CAAC;KACF,CAAA;AACH,CAAC;AA/DD,oDA+DC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mswjs/interceptors",
|
|
3
3
|
"description": "Low-level HTTP/HTTPS/XHR/fetch request interception library.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.14.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"author": "Artem Zakharchenko",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": ">=
|
|
10
|
+
"node": ">=16.x"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"start": "tsc --build -w",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"clean": "rimraf lib",
|
|
20
20
|
"build": "yarn clean && tsc --build",
|
|
21
21
|
"prepare": "yarn simple-git-hooks init",
|
|
22
|
-
"
|
|
22
|
+
"release": "semantic-release",
|
|
23
|
+
"prepublishOnly": "yarn build && yarn test"
|
|
23
24
|
},
|
|
24
25
|
"files": [
|
|
25
26
|
"lib",
|
|
@@ -36,9 +37,9 @@
|
|
|
36
37
|
"@open-draft/test-server": "^0.2.3",
|
|
37
38
|
"@types/cors": "^2.8.12",
|
|
38
39
|
"@types/express": "^4.17.13",
|
|
39
|
-
"@types/express-rate-limit": "^
|
|
40
|
+
"@types/express-rate-limit": "^6.0.0",
|
|
40
41
|
"@types/jest": "^27.0.3",
|
|
41
|
-
"@types/node": "^
|
|
42
|
+
"@types/node": "^16.11.26",
|
|
42
43
|
"@types/node-fetch": "2.5.12",
|
|
43
44
|
"@types/supertest": "^2.0.11",
|
|
44
45
|
"@types/xmldom": "^0.1.31",
|
|
@@ -47,24 +48,26 @@
|
|
|
47
48
|
"commitizen": "^4.2.4",
|
|
48
49
|
"cors": "^2.8.5",
|
|
49
50
|
"cz-conventional-changelog": "3.3.0",
|
|
50
|
-
"express": "^4.17.
|
|
51
|
-
"express-rate-limit": "^
|
|
51
|
+
"express": "^4.17.3",
|
|
52
|
+
"express-rate-limit": "^6.3.0",
|
|
52
53
|
"got": "^11.8.3",
|
|
53
54
|
"jest": "^27.4.3",
|
|
54
55
|
"node-fetch": "2.6.7",
|
|
55
56
|
"page-with": "^0.5.1",
|
|
56
57
|
"rimraf": "^3.0.2",
|
|
58
|
+
"semantic-release": "^19.0.2",
|
|
57
59
|
"simple-git-hooks": "^2.7.0",
|
|
58
60
|
"superagent": "^6.1.0",
|
|
59
61
|
"supertest": "^6.1.6",
|
|
60
62
|
"ts-jest": "^27.1.1",
|
|
61
|
-
"typescript": "4.3.5"
|
|
63
|
+
"typescript": "4.3.5",
|
|
64
|
+
"wait-for-expect": "^3.0.2"
|
|
62
65
|
},
|
|
63
66
|
"dependencies": {
|
|
64
67
|
"@open-draft/until": "^1.0.3",
|
|
65
68
|
"@xmldom/xmldom": "^0.7.5",
|
|
66
69
|
"debug": "^4.3.3",
|
|
67
|
-
"headers-polyfill": "^3.0.
|
|
70
|
+
"headers-polyfill": "^3.0.4",
|
|
68
71
|
"outvariant": "^1.2.1",
|
|
69
72
|
"strict-event-emitter": "^0.2.0"
|
|
70
73
|
},
|
|
@@ -105,7 +105,7 @@ export class NodeClientRequest extends ClientRequest {
|
|
|
105
105
|
return true
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
end(...args: any): this {
|
|
109
109
|
this.log('end', args)
|
|
110
110
|
|
|
111
111
|
const [chunk, encoding, callback] = normalizeClientRequestEndArgs(...args)
|
|
@@ -116,99 +116,106 @@ export class NodeClientRequest extends ClientRequest {
|
|
|
116
116
|
this.observer.emit('request', isomorphicRequest)
|
|
117
117
|
|
|
118
118
|
this.log('executing response resolver...')
|
|
119
|
-
const [resolverError, mockedResponse] = await until(async () =>
|
|
120
|
-
this.resolver(isomorphicRequest, this.response)
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
// Halt the request whenever the resolver throws an exception.
|
|
124
|
-
if (resolverError) {
|
|
125
|
-
this.log(
|
|
126
|
-
'encountered resolver exception, aborting request...',
|
|
127
|
-
resolverError
|
|
128
|
-
)
|
|
129
|
-
this.emit('error', resolverError)
|
|
130
|
-
this.terminate()
|
|
131
|
-
|
|
132
|
-
return
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (mockedResponse) {
|
|
136
|
-
this.log('received mocked response:', mockedResponse)
|
|
137
|
-
this.responseSource = 'mock'
|
|
138
|
-
|
|
139
|
-
const isomorphicResponse = toIsoResponse(mockedResponse)
|
|
140
|
-
this.respondWith(mockedResponse)
|
|
141
|
-
this.log(
|
|
142
|
-
isomorphicResponse.status,
|
|
143
|
-
isomorphicResponse.statusText,
|
|
144
|
-
isomorphicResponse.body,
|
|
145
|
-
'(MOCKED)'
|
|
146
|
-
)
|
|
147
119
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
120
|
+
// Execute the resolver Promise like a side-effect.
|
|
121
|
+
// Node.js 16 forces "ClientRequest.end" to be synchronous and return "this".
|
|
122
|
+
until(async () => this.resolver(isomorphicRequest, this.response)).then(
|
|
123
|
+
([resolverException, mockedResponse]) => {
|
|
124
|
+
// Halt the request whenever the resolver throws an exception.
|
|
125
|
+
if (resolverException) {
|
|
126
|
+
this.log(
|
|
127
|
+
'encountered resolver exception, aborting request...',
|
|
128
|
+
resolverException
|
|
129
|
+
)
|
|
130
|
+
this.emit('error', resolverException)
|
|
131
|
+
this.terminate()
|
|
132
|
+
|
|
133
|
+
return this
|
|
134
|
+
}
|
|
151
135
|
|
|
152
|
-
|
|
153
|
-
|
|
136
|
+
if (mockedResponse) {
|
|
137
|
+
this.log('received mocked response:', mockedResponse)
|
|
138
|
+
this.responseSource = 'mock'
|
|
154
139
|
|
|
155
|
-
|
|
140
|
+
const isomorphicResponse = toIsoResponse(mockedResponse)
|
|
141
|
+
this.respondWith(mockedResponse)
|
|
142
|
+
this.log(
|
|
143
|
+
isomorphicResponse.status,
|
|
144
|
+
isomorphicResponse.statusText,
|
|
145
|
+
isomorphicResponse.body,
|
|
146
|
+
'(MOCKED)'
|
|
147
|
+
)
|
|
156
148
|
|
|
157
|
-
|
|
158
|
-
// Any errors emitted past this point are not suppressed.
|
|
159
|
-
this.responseSource = 'bypass'
|
|
149
|
+
callback?.()
|
|
160
150
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (this.capturedError) {
|
|
164
|
-
this.emit('error', this.capturedError)
|
|
165
|
-
return
|
|
166
|
-
}
|
|
151
|
+
this.log('emitting the custom "response" event...')
|
|
152
|
+
this.observer.emit('response', isomorphicRequest, isomorphicResponse)
|
|
167
153
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
// in order to prevent the Socket to communicate with a potentially
|
|
171
|
-
// existing server.
|
|
172
|
-
this.log('writing request chunks...', this.chunks)
|
|
173
|
-
for (const { chunk, encoding, callback } of this.chunks) {
|
|
174
|
-
encoding
|
|
175
|
-
? super.write(chunk, encoding, callback)
|
|
176
|
-
: super.write(chunk, callback)
|
|
177
|
-
}
|
|
154
|
+
return this
|
|
155
|
+
}
|
|
178
156
|
|
|
179
|
-
|
|
180
|
-
this.log('original request error:', error)
|
|
181
|
-
})
|
|
157
|
+
this.log('no mocked response found!')
|
|
182
158
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
159
|
+
// Set the response source to "bypass".
|
|
160
|
+
// Any errors emitted past this point are not suppressed.
|
|
161
|
+
this.responseSource = 'bypass'
|
|
186
162
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
status: response.statusCode || 200,
|
|
194
|
-
statusText: response.statusMessage || 'OK',
|
|
195
|
-
headers: objectToHeaders(response.headers),
|
|
196
|
-
body: responseBody,
|
|
197
|
-
})
|
|
198
|
-
})
|
|
163
|
+
// Propagate previously captured errors.
|
|
164
|
+
// For example, a ECONNREFUSED error when connecting to a non-existing host.
|
|
165
|
+
if (this.capturedError) {
|
|
166
|
+
this.emit('error', this.capturedError)
|
|
167
|
+
return this
|
|
168
|
+
}
|
|
199
169
|
|
|
200
|
-
|
|
170
|
+
// Write the request body chunks in the order of ".write()" calls.
|
|
171
|
+
// Note that no request body has been written prior to this point
|
|
172
|
+
// in order to prevent the Socket to communicate with a potentially
|
|
173
|
+
// existing server.
|
|
174
|
+
this.log('writing request chunks...', this.chunks)
|
|
175
|
+
for (const { chunk, encoding, callback } of this.chunks) {
|
|
176
|
+
encoding
|
|
177
|
+
? super.write(chunk, encoding, callback)
|
|
178
|
+
: super.write(chunk, callback)
|
|
179
|
+
}
|
|
201
180
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
() => {
|
|
207
|
-
this.log('original request
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
181
|
+
this.once('error', (error) => {
|
|
182
|
+
this.log('original request error:', error)
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
this.once('abort', () => {
|
|
186
|
+
this.log('original request aborted!')
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
this.once('response-internal', async (response: IncomingMessage) => {
|
|
190
|
+
const responseBody = await getIncomingMessageBody(response)
|
|
191
|
+
this.log(response.statusCode, response.statusMessage, responseBody)
|
|
192
|
+
this.log('original response headers:', response.headers)
|
|
193
|
+
|
|
194
|
+
this.log('emitting the custom "response" event...')
|
|
195
|
+
this.observer.emit('response', isomorphicRequest, {
|
|
196
|
+
status: response.statusCode || 200,
|
|
197
|
+
statusText: response.statusMessage || 'OK',
|
|
198
|
+
headers: objectToHeaders(response.headers),
|
|
199
|
+
body: responseBody,
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
this.log('performing original request...')
|
|
204
|
+
|
|
205
|
+
return super.end(
|
|
206
|
+
...[
|
|
207
|
+
chunk,
|
|
208
|
+
encoding as any,
|
|
209
|
+
() => {
|
|
210
|
+
this.log('original request end!')
|
|
211
|
+
callback?.()
|
|
212
|
+
},
|
|
213
|
+
].filter(Boolean)
|
|
214
|
+
)
|
|
215
|
+
}
|
|
211
216
|
)
|
|
217
|
+
|
|
218
|
+
return this
|
|
212
219
|
}
|
|
213
220
|
|
|
214
221
|
emit(event: string, ...data: any[]) {
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { Socket } from 'net'
|
|
2
2
|
import { IncomingMessage } from 'http'
|
|
3
|
+
import { Stream, Readable, EventEmitter } from 'stream'
|
|
3
4
|
import { cloneIncomingMessage, IS_CLONE } from './cloneIncomingMessage'
|
|
4
5
|
|
|
5
6
|
test('clones a given IncomingMessage', () => {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const clone = cloneIncomingMessage(
|
|
7
|
+
const message = new IncomingMessage(new Socket())
|
|
8
|
+
message.statusCode = 200
|
|
9
|
+
message.statusMessage = 'OK'
|
|
10
|
+
message.headers = { 'x-powered-by': 'msw' }
|
|
11
|
+
const clone = cloneIncomingMessage(message)
|
|
12
|
+
|
|
13
|
+
// Prototypes must be preserved.
|
|
14
|
+
expect(clone).toBeInstanceOf(IncomingMessage)
|
|
15
|
+
expect(clone).toBeInstanceOf(EventEmitter)
|
|
16
|
+
expect(clone).toBeInstanceOf(Stream)
|
|
17
|
+
expect(clone).toBeInstanceOf(Readable)
|
|
11
18
|
|
|
12
19
|
expect(clone.statusCode).toEqual(200)
|
|
13
20
|
expect(clone.statusMessage).toEqual('OK')
|
|
@@ -15,6 +22,4 @@ test('clones a given IncomingMessage', () => {
|
|
|
15
22
|
|
|
16
23
|
// Cloned IncomingMessage must be marked respectively.
|
|
17
24
|
expect(clone[IS_CLONE]).toEqual(true)
|
|
18
|
-
|
|
19
|
-
expect(clone).toHaveProperty('_events')
|
|
20
25
|
})
|
|
@@ -7,35 +7,68 @@ export interface ClonedIncomingMessage extends IncomingMessage {
|
|
|
7
7
|
[IS_CLONE]: boolean
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Clones a given `http.IncomingMessage` instance.
|
|
12
|
+
*/
|
|
10
13
|
export function cloneIncomingMessage(
|
|
11
14
|
message: IncomingMessage
|
|
12
15
|
): ClonedIncomingMessage {
|
|
13
|
-
const
|
|
14
|
-
const properties = [
|
|
15
|
-
...Object.getOwnPropertyNames(message),
|
|
16
|
-
...Object.getOwnPropertySymbols(message),
|
|
17
|
-
] as Array<keyof IncomingMessage>
|
|
18
|
-
|
|
19
|
-
for (const propertyName of properties) {
|
|
20
|
-
if (stream.hasOwnProperty(propertyName)) {
|
|
21
|
-
continue
|
|
22
|
-
}
|
|
16
|
+
const clone = message.pipe(new PassThrough())
|
|
23
17
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
propertyName
|
|
27
|
-
)
|
|
18
|
+
// Inherit all direct "IncomingMessage" properties.
|
|
19
|
+
inheritProperties(message, clone)
|
|
28
20
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
21
|
+
// Deeply inherit the message prototypes (Readable, Stream, EventEmitter, etc.).
|
|
22
|
+
const clonedPrototype = Object.create(IncomingMessage.prototype)
|
|
23
|
+
getPrototypes(clone).forEach((prototype) => {
|
|
24
|
+
inheritProperties(prototype, clonedPrototype)
|
|
25
|
+
})
|
|
26
|
+
Object.setPrototypeOf(clone, clonedPrototype)
|
|
34
27
|
|
|
35
|
-
Object.defineProperty(
|
|
28
|
+
Object.defineProperty(clone, IS_CLONE, {
|
|
36
29
|
enumerable: true,
|
|
37
30
|
value: true,
|
|
38
31
|
})
|
|
39
32
|
|
|
40
|
-
return
|
|
33
|
+
return clone as unknown as ClonedIncomingMessage
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Returns a list of all prototypes the given object extends.
|
|
38
|
+
*/
|
|
39
|
+
function getPrototypes(source: object): object[] {
|
|
40
|
+
const prototypes: object[] = []
|
|
41
|
+
let current = source
|
|
42
|
+
|
|
43
|
+
while ((current = Object.getPrototypeOf(current))) {
|
|
44
|
+
prototypes.push(current)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return prototypes
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Inherits a given target object properties and symbols
|
|
52
|
+
* onto the given source object.
|
|
53
|
+
* @param source Object which should acquire properties.
|
|
54
|
+
* @param target Object to inherit the properties from.
|
|
55
|
+
*/
|
|
56
|
+
function inheritProperties(source: object, target: object): void {
|
|
57
|
+
const properties = [
|
|
58
|
+
...Object.getOwnPropertyNames(source),
|
|
59
|
+
...Object.getOwnPropertySymbols(source),
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
for (const property of properties) {
|
|
63
|
+
if (target.hasOwnProperty(property)) {
|
|
64
|
+
continue
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, property)
|
|
68
|
+
if (!descriptor) {
|
|
69
|
+
continue
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
Object.defineProperty(target, property, descriptor)
|
|
73
|
+
}
|
|
41
74
|
}
|
package/src/remote.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChildProcess
|
|
1
|
+
import { ChildProcess } from 'child_process'
|
|
2
2
|
import { Headers } from 'headers-polyfill'
|
|
3
3
|
import { invariant } from 'outvariant'
|
|
4
4
|
import { StrictEventEmitter } from 'strict-event-emitter'
|
|
@@ -12,8 +12,6 @@ import {
|
|
|
12
12
|
} from './createInterceptor'
|
|
13
13
|
import { toIsoResponse } from './utils/toIsoResponse'
|
|
14
14
|
|
|
15
|
-
type ProcessEventListener = (message: Serializable, ...args: any[]) => void
|
|
16
|
-
|
|
17
15
|
export type CreateRemoteInterceptorOptions = Omit<
|
|
18
16
|
InterceptorOptions,
|
|
19
17
|
'resolver'
|
|
@@ -64,7 +62,7 @@ spawn('node', ['module.js'], { stdio: ['ipc'] })\
|
|
|
64
62
|
)
|
|
65
63
|
}
|
|
66
64
|
|
|
67
|
-
let handleParentMessage:
|
|
65
|
+
let handleParentMessage: NodeJS.MessageListener
|
|
68
66
|
|
|
69
67
|
const interceptor = createInterceptor({
|
|
70
68
|
...options,
|
|
@@ -73,7 +71,7 @@ spawn('node', ['module.js'], { stdio: ['ipc'] })\
|
|
|
73
71
|
process.send?.(`request:${serializedRequest}`)
|
|
74
72
|
|
|
75
73
|
return new Promise((resolve) => {
|
|
76
|
-
handleParentMessage = (message
|
|
74
|
+
handleParentMessage = (message) => {
|
|
77
75
|
if (typeof message !== 'string') {
|
|
78
76
|
return
|
|
79
77
|
}
|
|
@@ -115,7 +113,7 @@ export function createRemoteResolver(
|
|
|
115
113
|
): RemoteResolverApi {
|
|
116
114
|
const observer = new StrictEventEmitter<InterceptorEventsMap>()
|
|
117
115
|
|
|
118
|
-
const handleChildMessage:
|
|
116
|
+
const handleChildMessage: NodeJS.MessageListener = async (message) => {
|
|
119
117
|
if (typeof message !== 'string') {
|
|
120
118
|
return
|
|
121
119
|
}
|