@mswjs/interceptors 0.13.6 → 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 -106
- package/lib/interceptors/ClientRequest/NodeClientRequest.js.map +1 -1
- package/lib/remote.js.map +1 -1
- package/package.json +9 -7
- package/src/interceptors/ClientRequest/NodeClientRequest.ts +89 -84
- 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,119 +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
|
-
// in order to prevent the Socket to communicate with a potentially
|
|
208
|
-
// existing server.
|
|
209
|
-
this.log('writing request chunks...', this.chunks);
|
|
210
|
-
try {
|
|
211
|
-
for (_c = __values(this.chunks), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
212
|
-
_e = _d.value, chunk_1 = _e.chunk, encoding_1 = _e.encoding, callback_1 = _e.callback;
|
|
213
|
-
encoding_1
|
|
214
|
-
? _super.prototype.write.call(this, chunk_1, encoding_1, callback_1)
|
|
215
|
-
: _super.prototype.write.call(this, chunk_1, callback_1);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
219
|
-
finally {
|
|
220
|
-
try {
|
|
221
|
-
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
222
|
-
}
|
|
223
|
-
finally { if (e_1) throw e_1.error; }
|
|
224
|
-
}
|
|
225
|
-
this.once('error', function (error) {
|
|
226
|
-
_this.log('original request error:', error);
|
|
227
|
-
});
|
|
228
|
-
this.once('abort', function () {
|
|
229
|
-
_this.log('original request aborted!');
|
|
230
|
-
});
|
|
231
|
-
this.once('response-internal', function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
232
|
-
var responseBody;
|
|
233
|
-
return __generator(this, function (_a) {
|
|
234
|
-
switch (_a.label) {
|
|
235
|
-
case 0: return [4 /*yield*/, getIncomingMessageBody_1.getIncomingMessageBody(response)];
|
|
236
|
-
case 1:
|
|
237
|
-
responseBody = _a.sent();
|
|
238
|
-
this.log(response.statusCode, response.statusMessage, responseBody);
|
|
239
|
-
this.log('original response headers:', response.headers);
|
|
240
|
-
this.log('emitting the custom "response" event...');
|
|
241
|
-
this.observer.emit('response', isomorphicRequest, {
|
|
242
|
-
status: response.statusCode || 200,
|
|
243
|
-
statusText: response.statusMessage || 'OK',
|
|
244
|
-
headers: lib_1.objectToHeaders(response.headers),
|
|
245
|
-
body: responseBody,
|
|
246
|
-
});
|
|
247
|
-
return [2 /*return*/];
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}); });
|
|
251
|
-
this.log('performing original request...');
|
|
252
|
-
return [2 /*return*/, _super.prototype.end.apply(this, __spreadArray([], __read([
|
|
253
|
-
chunk,
|
|
254
|
-
encoding,
|
|
255
|
-
function () {
|
|
256
|
-
_this.log('original request end!');
|
|
257
|
-
callback === null || callback === void 0 ? void 0 : callback();
|
|
258
|
-
},
|
|
259
|
-
].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);
|
|
260
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);
|
|
261
219
|
});
|
|
220
|
+
_this.once('abort', function () {
|
|
221
|
+
_this.log('original request aborted!');
|
|
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))));
|
|
262
252
|
});
|
|
253
|
+
return this;
|
|
263
254
|
};
|
|
264
255
|
NodeClientRequest.prototype.emit = function (event) {
|
|
265
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,GAAG,GAAG,CAAA;QACd,KAAI,CAAC,OAAO,GAAG,cAAc,CAAA;QAC7B,KAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;QAChC,KAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA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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"}
|
package/lib/remote.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote.js","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qDAA0C;AAC1C,yCAAsC;AACtC,6DAAyD;AACzD,yDAO4B;AAC5B,uDAAqD;
|
|
1
|
+
{"version":3,"file":"remote.js","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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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,13 +48,14 @@
|
|
|
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",
|
|
@@ -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,101 +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
|
-
|
|
151
|
-
|
|
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
|
+
}
|
|
152
135
|
|
|
153
|
-
|
|
154
|
-
|
|
136
|
+
if (mockedResponse) {
|
|
137
|
+
this.log('received mocked response:', mockedResponse)
|
|
138
|
+
this.responseSource = 'mock'
|
|
155
139
|
|
|
156
|
-
|
|
140
|
+
const isomorphicResponse = toIsoResponse(mockedResponse)
|
|
141
|
+
this.respondWith(mockedResponse)
|
|
142
|
+
this.log(
|
|
143
|
+
isomorphicResponse.status,
|
|
144
|
+
isomorphicResponse.statusText,
|
|
145
|
+
isomorphicResponse.body,
|
|
146
|
+
'(MOCKED)'
|
|
147
|
+
)
|
|
157
148
|
|
|
158
|
-
|
|
159
|
-
// Any errors emitted past this point are not suppressed.
|
|
160
|
-
this.responseSource = 'bypass'
|
|
149
|
+
callback?.()
|
|
161
150
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (this.capturedError) {
|
|
165
|
-
this.emit('error', this.capturedError)
|
|
166
|
-
return
|
|
167
|
-
}
|
|
151
|
+
this.log('emitting the custom "response" event...')
|
|
152
|
+
this.observer.emit('response', isomorphicRequest, isomorphicResponse)
|
|
168
153
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
// in order to prevent the Socket to communicate with a potentially
|
|
172
|
-
// existing server.
|
|
173
|
-
this.log('writing request chunks...', this.chunks)
|
|
174
|
-
for (const { chunk, encoding, callback } of this.chunks) {
|
|
175
|
-
encoding
|
|
176
|
-
? super.write(chunk, encoding, callback)
|
|
177
|
-
: super.write(chunk, callback)
|
|
178
|
-
}
|
|
154
|
+
return this
|
|
155
|
+
}
|
|
179
156
|
|
|
180
|
-
|
|
181
|
-
this.log('original request error:', error)
|
|
182
|
-
})
|
|
157
|
+
this.log('no mocked response found!')
|
|
183
158
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
159
|
+
// Set the response source to "bypass".
|
|
160
|
+
// Any errors emitted past this point are not suppressed.
|
|
161
|
+
this.responseSource = 'bypass'
|
|
187
162
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
this.observer.emit('response', isomorphicRequest, {
|
|
195
|
-
status: response.statusCode || 200,
|
|
196
|
-
statusText: response.statusMessage || 'OK',
|
|
197
|
-
headers: objectToHeaders(response.headers),
|
|
198
|
-
body: responseBody,
|
|
199
|
-
})
|
|
200
|
-
})
|
|
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
|
+
}
|
|
201
169
|
|
|
202
|
-
|
|
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
|
+
}
|
|
203
180
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
() => {
|
|
209
|
-
this.log('original request
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
+
}
|
|
213
216
|
)
|
|
217
|
+
|
|
218
|
+
return this
|
|
214
219
|
}
|
|
215
220
|
|
|
216
221
|
emit(event: string, ...data: any[]) {
|
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
|
}
|