@mswjs/interceptors 0.17.6 → 0.18.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.
Files changed (114) hide show
  1. package/README.md +49 -47
  2. package/lib/Interceptor.js +4 -4
  3. package/lib/Interceptor.js.map +1 -1
  4. package/lib/RemoteHttpInterceptor.d.ts +15 -0
  5. package/lib/RemoteHttpInterceptor.js +86 -56
  6. package/lib/RemoteHttpInterceptor.js.map +1 -1
  7. package/lib/glossary.d.ts +3 -14
  8. package/lib/glossary.js.map +1 -1
  9. package/lib/index.d.ts +0 -2
  10. package/lib/index.js +0 -2
  11. package/lib/index.js.map +1 -1
  12. package/lib/interceptors/ClientRequest/NodeClientRequest.d.ts +13 -5
  13. package/lib/interceptors/ClientRequest/NodeClientRequest.js +179 -166
  14. package/lib/interceptors/ClientRequest/NodeClientRequest.js.map +1 -1
  15. package/lib/interceptors/ClientRequest/http.get.js +9 -5
  16. package/lib/interceptors/ClientRequest/http.get.js.map +1 -1
  17. package/lib/interceptors/ClientRequest/http.request.js +10 -6
  18. package/lib/interceptors/ClientRequest/http.request.js.map +1 -1
  19. package/lib/interceptors/ClientRequest/index.d.ts +2 -5
  20. package/lib/interceptors/ClientRequest/index.js +2 -13
  21. package/lib/interceptors/ClientRequest/index.js.map +1 -1
  22. package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js +9 -5
  23. package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js.map +1 -1
  24. package/lib/interceptors/ClientRequest/utils/createRequest.d.ts +6 -0
  25. package/lib/interceptors/ClientRequest/utils/createRequest.js +52 -0
  26. package/lib/interceptors/ClientRequest/utils/createRequest.js.map +1 -0
  27. package/lib/interceptors/ClientRequest/utils/createResponse.d.ts +8 -0
  28. package/lib/interceptors/ClientRequest/utils/createResponse.js +24 -0
  29. package/lib/interceptors/ClientRequest/utils/createResponse.js.map +1 -0
  30. package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js +1 -1
  31. package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js.map +1 -1
  32. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js +8 -8
  33. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js.map +1 -1
  34. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.d.ts +1 -1
  35. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js +1 -1
  36. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js.map +1 -1
  37. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.d.ts +6 -10
  38. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js +203 -143
  39. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js.map +1 -1
  40. package/lib/interceptors/XMLHttpRequest/index.d.ts +2 -2
  41. package/lib/interceptors/XMLHttpRequest/index.js +2 -2
  42. package/lib/interceptors/XMLHttpRequest/index.js.map +1 -1
  43. package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.d.ts +4 -0
  44. package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js +14 -0
  45. package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js.map +1 -0
  46. package/lib/interceptors/XMLHttpRequest/utils/createResponse.d.ts +2 -0
  47. package/lib/interceptors/XMLHttpRequest/utils/createResponse.js +14 -0
  48. package/lib/interceptors/XMLHttpRequest/utils/createResponse.js.map +1 -0
  49. package/lib/interceptors/fetch/index.js +24 -81
  50. package/lib/interceptors/fetch/index.js.map +1 -1
  51. package/lib/utils/AsyncEventEmitter.js +12 -8
  52. package/lib/utils/AsyncEventEmitter.js.map +1 -1
  53. package/lib/utils/RequestWithCredentials.d.ts +7 -0
  54. package/lib/utils/RequestWithCredentials.js +20 -0
  55. package/lib/utils/RequestWithCredentials.js.map +1 -0
  56. package/lib/utils/bufferUtils.d.ts +7 -2
  57. package/lib/utils/bufferUtils.js +10 -6
  58. package/lib/utils/bufferUtils.js.map +1 -1
  59. package/lib/utils/parseJson.d.ts +1 -1
  60. package/lib/utils/toInteractiveRequest.d.ts +7 -0
  61. package/lib/utils/toInteractiveRequest.js +20 -0
  62. package/lib/utils/toInteractiveRequest.js.map +1 -0
  63. package/package.json +3 -2
  64. package/src/RemoteHttpInterceptor.ts +84 -34
  65. package/src/glossary.ts +5 -18
  66. package/src/index.ts +0 -2
  67. package/src/interceptors/ClientRequest/NodeClientRequest.test.ts +17 -23
  68. package/src/interceptors/ClientRequest/NodeClientRequest.ts +177 -153
  69. package/src/interceptors/ClientRequest/index.test.ts +5 -3
  70. package/src/interceptors/ClientRequest/index.ts +2 -26
  71. package/src/interceptors/ClientRequest/utils/createRequest.test.ts +61 -0
  72. package/src/interceptors/ClientRequest/utils/createRequest.ts +32 -0
  73. package/src/interceptors/ClientRequest/utils/createResponse.test.ts +24 -0
  74. package/src/interceptors/ClientRequest/utils/createResponse.ts +22 -0
  75. package/src/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.ts +1 -1
  76. package/src/interceptors/XMLHttpRequest/XMLHttpRequestOverride.ts +234 -174
  77. package/src/interceptors/XMLHttpRequest/index.ts +3 -2
  78. package/src/interceptors/XMLHttpRequest/utils/concatArrayBuffer.ts +12 -0
  79. package/src/interceptors/XMLHttpRequest/utils/concateArrayBuffer.test.ts +14 -0
  80. package/src/interceptors/XMLHttpRequest/utils/createResponse.ts +13 -0
  81. package/src/interceptors/fetch/index.ts +30 -69
  82. package/src/utils/RequestWithCredentials.ts +21 -0
  83. package/src/utils/bufferUtils.ts +10 -5
  84. package/src/utils/parseJson.ts +1 -1
  85. package/src/utils/toInteractiveRequest.ts +29 -0
  86. package/lib/InteractiveIsomorphicRequest.d.ts +0 -7
  87. package/lib/InteractiveIsomorphicRequest.js +0 -37
  88. package/lib/InteractiveIsomorphicRequest.js.map +0 -1
  89. package/lib/IsomorphicRequest.d.ts +0 -24
  90. package/lib/IsomorphicRequest.js +0 -107
  91. package/lib/IsomorphicRequest.js.map +0 -1
  92. package/lib/interceptors/ClientRequest/utils/bodyBufferToString.d.ts +0 -2
  93. package/lib/interceptors/ClientRequest/utils/bodyBufferToString.js +0 -11
  94. package/lib/interceptors/ClientRequest/utils/bodyBufferToString.js.map +0 -1
  95. package/lib/interceptors/ClientRequest/utils/concatChunkToBuffer.d.ts +0 -2
  96. package/lib/interceptors/ClientRequest/utils/concatChunkToBuffer.js +0 -11
  97. package/lib/interceptors/ClientRequest/utils/concatChunkToBuffer.js.map +0 -1
  98. package/lib/interceptors/XMLHttpRequest/utils/bufferFrom.d.ts +0 -5
  99. package/lib/interceptors/XMLHttpRequest/utils/bufferFrom.js +0 -20
  100. package/lib/interceptors/XMLHttpRequest/utils/bufferFrom.js.map +0 -1
  101. package/lib/utils/toIsoResponse.d.ts +0 -5
  102. package/lib/utils/toIsoResponse.js +0 -18
  103. package/lib/utils/toIsoResponse.js.map +0 -1
  104. package/src/InteractiveIsomorphicRequest.ts +0 -24
  105. package/src/IsomorphicRequest.test.ts +0 -106
  106. package/src/IsomorphicRequest.ts +0 -86
  107. package/src/interceptors/ClientRequest/utils/bodyBufferToString.test.ts +0 -16
  108. package/src/interceptors/ClientRequest/utils/bodyBufferToString.ts +0 -7
  109. package/src/interceptors/ClientRequest/utils/concatChunkToBuffer.test.ts +0 -13
  110. package/src/interceptors/ClientRequest/utils/concatChunkToBuffer.ts +0 -10
  111. package/src/interceptors/XMLHttpRequest/utils/bufferFrom.test.ts +0 -11
  112. package/src/interceptors/XMLHttpRequest/utils/bufferFrom.ts +0 -16
  113. package/src/utils/toIsoResponse.test.ts +0 -39
  114. package/src/utils/toIsoResponse.ts +0 -14
package/README.md CHANGED
@@ -53,7 +53,7 @@ class NodeClientRequest extends ClientRequest {
53
53
  async end(...args) {
54
54
  // Check if there's a mocked response for this request.
55
55
  // You control this in the "resolver" function.
56
- const mockedResponse = await resolver(isomorphicRequest)
56
+ const mockedResponse = await resolver(request)
57
57
 
58
58
  // If there is a mocked response, use it to respond to this
59
59
  // request, finalizing it afterward as if it received that
@@ -81,9 +81,9 @@ This library extends (or patches, where applicable) the following native modules
81
81
  - `XMLHttpRequest`
82
82
  - `fetch`
83
83
 
84
- Once extended, it intercepts and normalizes all requests to the _isomorphic request instances_. The isomorphic request is an abstract representation of the request coming from different sources (`ClientRequest`, `XMLHttpRequest`, `window.Request`, etc.) that allows us to handle such requests in the same, unified manner.
84
+ Once extended, it intercepts and normalizes all requests to the Fetch API `Request` instances. This way, no matter the request source (`http.ClientRequest`, `XMLHttpRequest`, `window.Request`, etc), you always get a specification-compliant request instance to work with.
85
85
 
86
- You can respond to an isomorphic request using an _isomorphic response_. In a similar way, the isomorphic response is a representation of the response to use for different requests. Responding to requests differs substantially when using modules like `http` or `XMLHttpRequest`. This library takes the responsibility for coercing isomorphic responses into appropriate responses depending on the request module automatically.
86
+ You can respond to the intercepted request by constructing a Fetch API Response instance. Instead of designing custom abstractions, this library respects the Fetch API specification and takes the responsibility to coerce a single response declaration to the appropriate response formats based on the request-issuing modules (like `http.OutgoingMessage` to respond to `http.ClientRequest`, or updating `XMLHttpRequest` response-related properties).
87
87
 
88
88
  ## What this library doesn't do
89
89
 
@@ -116,19 +116,14 @@ interceptor.apply()
116
116
 
117
117
  // Listen to any "http.ClientRequest" being dispatched,
118
118
  // and log its method and full URL.
119
- interceptor.on('request', (request) => {
120
- console.log(request.method, request.url.href)
119
+ interceptor.on('request', (request, requestId) => {
120
+ console.log(request.method, request.url)
121
121
  })
122
122
 
123
123
  // Listen to any responses sent to "http.ClientRequest".
124
124
  // Note that this listener is read-only and cannot affect responses.
125
125
  interceptor.on('response', (response, request) => {
126
- console.log(
127
- 'response to %s %s was:',
128
- request.method,
129
- request.url.href,
130
- response
131
- )
126
+ console.log('response to %s %s was:', request.method, request.url, response)
132
127
  })
133
128
  ```
134
129
 
@@ -203,39 +198,38 @@ interceptor.on('request', listener)
203
198
 
204
199
  ## Introspecting requests
205
200
 
206
- All HTTP request interceptors emit a "request" event. In the listener to this event, they expose an isomorphic `request` instance—a normalized representation of the captured request.
201
+ All HTTP request interceptors emit a "request" event. In the listener to this event, they expose a `request` reference, which is a [Fetch API Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) instance.
207
202
 
208
- > There are many ways to describe a request in Node.js, that's why this library exposes you a custom request instance that abstracts those details away from you, making request listeners uniform.
203
+ > There are many ways to describe a request in Node.js but this library coerces different request definitions to a single specification-compliant `Request` instance to make the handling consistent.
209
204
 
210
205
  ```js
211
- interceptor.on('reqest', (request) => {})
206
+ interceptor.on('reqest', (request, requestId) => {
207
+ console.log(request.method, request.url)
208
+ })
212
209
  ```
213
210
 
214
- The exposed `request` partially implements Fetch API [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) specification, containing the following properties and methods:
211
+ Since the exposed `request` instance implements the Fetch API specification, you can operate with it just as you do with the regular browser request. For example, this is how you would read the request body as JSON:
215
212
 
216
- ```ts
217
- interface IsomorphicRequest {
218
- id: string
219
- url: URL
220
- method: string
221
- headers: Headers
222
- credentials: 'omit' | 'same-origin' | 'include'
223
- bodyUsed: boolean
224
- clone(): IsomorphicRequest
225
- arrayBuffer(): Promise<ArrayBuffer>
226
- text(): Promise<string>
227
- json(): Promise<Record<string, unknown>>
228
- }
213
+ ```js
214
+ interceptor.on('request', async (request, requestId) => {
215
+ const json = await request.clone().json()
216
+ })
229
217
  ```
230
218
 
231
- For example, this is how you would read a JSON request body:
219
+ > **Do not forget to clone the request before reading its body!**
220
+
221
+ ## Modifying requests
222
+
223
+ Request representations are readonly. You can, however, mutate the intercepted request's headers in the "request" listener:
232
224
 
233
225
  ```js
234
- interceptor.on('request', async (request) => {
235
- const json = await request.json()
226
+ interceptor.on('request', (request) => {
227
+ request.headers.set('X-My-Header', 'true')
236
228
  })
237
229
  ```
238
230
 
231
+ > This restriction is done so that the library wouldn't have to unnecessarily synchronize the actual request instance and its Fetch API request representation. As of now, this library is not meant to be used as a full-scale proxy.
232
+
239
233
  ## Mocking responses
240
234
 
241
235
  Although this library can be used purely for request introspection purposes, you can also affect request resolution by responding to any intercepted request within the "request" event.
@@ -243,21 +237,29 @@ Although this library can be used purely for request introspection purposes, you
243
237
  Use the `request.respondWith()` method to respond to a request with a mocked response:
244
238
 
245
239
  ```js
246
- interceptor.on('request', (request) => {
247
- request.respondWith({
248
- status: 200,
249
- statusText: 'OK',
250
- headers: {
251
- 'Content-Type': 'application/json',
252
- },
253
- body: JSON.stringify({
254
- firstName: 'John',
255
- lastName: 'Maverick',
256
- }),
257
- })
240
+ interceptor.on('request', (request, requestId) => {
241
+ request.respondWith(
242
+ new Response(
243
+ JSON.stringify({
244
+ firstName: 'John',
245
+ lastName: 'Maverick',
246
+ }),
247
+ {
248
+ status: 201,
249
+ statusText: 'Created',
250
+ headers: {
251
+ 'Content-Type': 'application/json',
252
+ },
253
+ }
254
+ )
255
+ )
258
256
  })
259
257
  ```
260
258
 
259
+ > We use Fetch API `Response` class as the middleground for mocked response definition. This library then coerces the response instance to the appropriate response format (e.g. to `http.OutgoingMessage` in the case of `http.ClientRequest`).
260
+
261
+ **The `Response` class is built-in in since Node.js 18. Use a Fetch API-compatible polyfill, like `node-fetch`, for older versions of Node.js.`**
262
+
261
263
  Note that a single request _can only be handled once_. You may want to introduce conditional logic, like routing, in your request listener but it's generally advised to use a higher-level library like [Mock Service Worker](https://github.com/mswjs/msw) that does request matching for you.
262
264
 
263
265
  Requests must be responded to within the same tick as the request listener. This means you cannot respond to a request using `setTimeout`, as this will delegate the callback to the next tick. If you wish to introduce asynchronous side-effects in the listener, consider making it an `async` function, awaiting any side-effects you need.
@@ -265,9 +267,9 @@ Requests must be responded to within the same tick as the request listener. This
265
267
  ```js
266
268
  // Respond to all requests with a 500 response
267
269
  // delayed by 500ms.
268
- interceptor.on('request', async (request) => {
270
+ interceptor.on('request', async (request, requestId) => {
269
271
  await sleep(500)
270
- request.respondWith({ status: 500 })
272
+ request.respondWith(new Response(null, { status: 500 }))
271
273
  })
272
274
  ```
273
275
 
@@ -310,7 +312,7 @@ const interceptor = new BatchInterceptor({
310
312
 
311
313
  interceptor.apply()
312
314
 
313
- interceptor.on('request', (request) => {
315
+ interceptor.on('request', (request, requestId) => {
314
316
  // Inspect the intercepted "request".
315
317
  // Optionally, return a mocked response.
316
318
  })
@@ -358,7 +360,7 @@ const resolver = new RemoteHttpResolver({
358
360
  process: appProcess,
359
361
  })
360
362
 
361
- resolver.on('request', (request) => {
363
+ resolver.on('request', (request, requestId) => {
362
364
  // Optionally, return a mocked response
363
365
  // for a request that occurred in the "appProcess".
364
366
  })
@@ -44,7 +44,7 @@ var Interceptor = /** @class */ (function () {
44
44
  this.readyState = InterceptorReadyState.IDLE;
45
45
  this.emitter = new AsyncEventEmitter_1.AsyncEventEmitter();
46
46
  this.subscriptions = [];
47
- this.log = debug_1.debug(symbol.description);
47
+ this.log = (0, debug_1.debug)(symbol.description);
48
48
  // Do not limit the maximum number of listeners
49
49
  // so not to limit the maximum amount of parallel events emitted.
50
50
  this.emitter.setMaxListeners(0);
@@ -99,7 +99,7 @@ var Interceptor = /** @class */ (function () {
99
99
  log('removed proxied "%s" listener!', event);
100
100
  });
101
101
  };
102
- nextTick_1.nextTick(function () {
102
+ (0, nextTick_1.nextTick)(function () {
103
103
  _this.readyState = InterceptorReadyState.APPLIED;
104
104
  });
105
105
  return;
@@ -109,7 +109,7 @@ var Interceptor = /** @class */ (function () {
109
109
  this.setup();
110
110
  // Store the newly applied interceptor instance globally.
111
111
  this.setInstance();
112
- nextTick_1.nextTick(function () {
112
+ (0, nextTick_1.nextTick)(function () {
113
113
  _this.readyState = InterceptorReadyState.APPLIED;
114
114
  });
115
115
  };
@@ -173,7 +173,7 @@ var Interceptor = /** @class */ (function () {
173
173
  }
174
174
  this.emitter.deactivate();
175
175
  log('destroyed the listener!');
176
- nextTick_1.nextTick(function () {
176
+ (0, nextTick_1.nextTick)(function () {
177
177
  _this.readyState = InterceptorReadyState.DISPOSED;
178
178
  });
179
179
  };
@@ -1 +1 @@
1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AI,CAAC,MAAM,CAAC,CAAA;QACnD,IAAI,CAAC,GAAG,CAAC,4BAA4B,EAAE,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,0CAAE,IAAI,CAAC,CAAA;QACnE,OAAO,QAAQ,CAAA;IACjB,CAAC;IAEO,iCAAW,GAAnB;QACE,eAAe,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAClC,IAAI,CAAC,GAAG,CAAC,sBAAsB,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IAC3D,CAAC;IAEO,mCAAa,GAArB;QACE,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC/B,IAAI,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IAC/D,CAAC;IACH,kBAAC;AAAD,CAAC,AA9LD,IA8LC;AA9LY,kCAAW"}
@@ -1,10 +1,25 @@
1
1
  /// <reference types="node" />
2
2
  import { ChildProcess } from 'child_process';
3
+ import { HeadersObject } from 'headers-polyfill';
3
4
  import { HttpRequestEventMap } from './glossary';
4
5
  import { Interceptor } from './Interceptor';
5
6
  import { BatchInterceptor } from './BatchInterceptor';
6
7
  import { ClientRequestInterceptor } from './interceptors/ClientRequest';
7
8
  import { XMLHttpRequestInterceptor } from './interceptors/XMLHttpRequest';
9
+ export interface SerializedRequest {
10
+ id: string;
11
+ url: string;
12
+ method: string;
13
+ headers: HeadersObject;
14
+ credentials: RequestCredentials;
15
+ body: string;
16
+ }
17
+ export interface SerializedResponse {
18
+ status: number;
19
+ statusText: string;
20
+ headers: HeadersObject;
21
+ body: string;
22
+ }
8
23
  export declare class RemoteHttpInterceptor extends BatchInterceptor<[
9
24
  ClientRequestInterceptor,
10
25
  XMLHttpRequestInterceptor
@@ -14,17 +14,6 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
17
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
18
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
19
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -79,15 +68,14 @@ var __read = (this && this.__read) || function (o, n) {
79
68
  };
80
69
  Object.defineProperty(exports, "__esModule", { value: true });
81
70
  exports.RemoteHttpResolver = exports.requestReviver = exports.RemoteHttpInterceptor = void 0;
71
+ var web_fetch_1 = require("@remix-run/web-fetch");
82
72
  var headers_polyfill_1 = require("headers-polyfill");
83
73
  var Interceptor_1 = require("./Interceptor");
84
74
  var BatchInterceptor_1 = require("./BatchInterceptor");
85
75
  var ClientRequest_1 = require("./interceptors/ClientRequest");
86
76
  var XMLHttpRequest_1 = require("./interceptors/XMLHttpRequest");
87
- var toIsoResponse_1 = require("./utils/toIsoResponse");
88
- var IsomorphicRequest_1 = require("./IsomorphicRequest");
89
- var bufferFrom_1 = require("./interceptors/XMLHttpRequest/utils/bufferFrom");
90
- var InteractiveIsomorphicRequest_1 = require("./InteractiveIsomorphicRequest");
77
+ var toInteractiveRequest_1 = require("./utils/toInteractiveRequest");
78
+ var RequestWithCredentials_1 = require("./utils/RequestWithCredentials");
91
79
  var RemoteHttpInterceptor = /** @class */ (function (_super) {
92
80
  __extends(RemoteHttpInterceptor, _super);
93
81
  function RemoteHttpInterceptor() {
@@ -103,33 +91,59 @@ var RemoteHttpInterceptor = /** @class */ (function (_super) {
103
91
  var _this = this;
104
92
  _super.prototype.setup.call(this);
105
93
  var handleParentMessage;
106
- this.on('request', function (request) { return __awaiter(_this, void 0, void 0, function () {
107
- var serializedRequest, responsePromise;
108
- var _a;
109
- return __generator(this, function (_b) {
110
- serializedRequest = JSON.stringify(request);
111
- this.log('sent serialized request to the child:', serializedRequest);
112
- (_a = process.send) === null || _a === void 0 ? void 0 : _a.call(process, "request:" + serializedRequest);
113
- responsePromise = new Promise(function (resolve) {
114
- handleParentMessage = function (message) {
115
- if (typeof message !== 'string') {
116
- return resolve();
117
- }
118
- if (message.startsWith("response:" + request.id)) {
119
- var _a = __read(message.match(/^response:.+?:(.+)$/) || [], 2), serializedResponse = _a[1];
120
- if (!serializedResponse) {
121
- return resolve();
122
- }
123
- var mockedResponse = JSON.parse(serializedResponse);
124
- request.respondWith(mockedResponse);
125
- resolve();
126
- }
127
- };
128
- });
129
- // Listen for the mocked response message from the parent.
130
- this.log('add "message" listener to the parent process', handleParentMessage);
131
- process.addListener('message', handleParentMessage);
132
- return [2 /*return*/, responsePromise];
94
+ this.on('request', function (request, requestId) { return __awaiter(_this, void 0, void 0, function () {
95
+ var serializedRequest, _a, _b, _c, responsePromise;
96
+ var _d;
97
+ var _e;
98
+ return __generator(this, function (_f) {
99
+ switch (_f.label) {
100
+ case 0:
101
+ _b = (_a = JSON).stringify;
102
+ _d = {
103
+ id: requestId,
104
+ method: request.method,
105
+ url: request.url,
106
+ headers: (0, headers_polyfill_1.headersToObject)(request.headers),
107
+ credentials: request.credentials
108
+ };
109
+ if (!['GET', 'HEAD'].includes(request.method)) return [3 /*break*/, 1];
110
+ _c = null;
111
+ return [3 /*break*/, 3];
112
+ case 1: return [4 /*yield*/, request.text()];
113
+ case 2:
114
+ _c = _f.sent();
115
+ _f.label = 3;
116
+ case 3:
117
+ serializedRequest = _b.apply(_a, [(_d.body = _c,
118
+ _d)]);
119
+ this.log('sent serialized request to the child:', serializedRequest);
120
+ (_e = process.send) === null || _e === void 0 ? void 0 : _e.call(process, "request:" + serializedRequest);
121
+ responsePromise = new Promise(function (resolve) {
122
+ handleParentMessage = function (message) {
123
+ if (typeof message !== 'string') {
124
+ return resolve();
125
+ }
126
+ if (message.startsWith("response:" + requestId)) {
127
+ var _a = __read(message.match(/^response:.+?:(.+)$/) || [], 2), serializedResponse = _a[1];
128
+ if (!serializedResponse) {
129
+ return resolve();
130
+ }
131
+ var responseInit = JSON.parse(serializedResponse);
132
+ var mockedResponse = new web_fetch_1.Response(responseInit.body, {
133
+ status: responseInit.status,
134
+ statusText: responseInit.statusText,
135
+ headers: new headers_polyfill_1.Headers(responseInit.headers),
136
+ });
137
+ request.respondWith(mockedResponse);
138
+ resolve();
139
+ }
140
+ };
141
+ });
142
+ // Listen for the mocked response message from the parent.
143
+ this.log('add "message" listener to the parent process', handleParentMessage);
144
+ process.addListener('message', handleParentMessage);
145
+ return [2 /*return*/, responsePromise];
146
+ }
133
147
  });
134
148
  }); });
135
149
  this.subscriptions.push(function () {
@@ -161,7 +175,7 @@ var RemoteHttpResolver = /** @class */ (function (_super) {
161
175
  var _this = this;
162
176
  var log = this.log.extend('setup');
163
177
  var handleChildMessage = function (message) { return __awaiter(_this, void 0, void 0, function () {
164
- var _a, serializedRequest, requestJson, body, isomorphicRequest, interactiveIsomorphicRequest, _b, mockedResponse, serializedResponse;
178
+ var _a, serializedRequest, requestJson, capturedRequest, interactiveRequest, _b, mockedResponse, responseClone, responseText, serializedResponse;
165
179
  var _this = this;
166
180
  return __generator(this, function (_c) {
167
181
  switch (_c.label) {
@@ -177,30 +191,46 @@ var RemoteHttpResolver = /** @class */ (function (_super) {
177
191
  }
178
192
  requestJson = JSON.parse(serializedRequest, requestReviver);
179
193
  log('parsed intercepted request', requestJson);
180
- body = bufferFrom_1.bufferFrom(requestJson.body);
181
- isomorphicRequest = new IsomorphicRequest_1.IsomorphicRequest(requestJson.url, __assign(__assign({}, requestJson), { body: body.buffer }));
182
- interactiveIsomorphicRequest = new InteractiveIsomorphicRequest_1.InteractiveIsomorphicRequest(isomorphicRequest);
183
- this.emitter.emit('request', interactiveIsomorphicRequest);
194
+ capturedRequest = (0, RequestWithCredentials_1.createRequestWithCredentials)(requestJson.url, {
195
+ method: requestJson.method,
196
+ headers: new headers_polyfill_1.Headers(requestJson.headers),
197
+ credentials: requestJson.credentials,
198
+ body: requestJson.body,
199
+ });
200
+ interactiveRequest = (0, toInteractiveRequest_1.toInteractiveRequest)(capturedRequest);
201
+ this.emitter.emit('request', interactiveRequest, requestJson.id);
184
202
  return [4 /*yield*/, this.emitter.untilIdle('request', function (_a) {
185
- var _b = __read(_a.args, 1), request = _b[0];
186
- return request.id === interactiveIsomorphicRequest.id;
203
+ var _b = __read(_a.args, 2), pendingRequestId = _b[1];
204
+ return pendingRequestId === requestJson.id;
187
205
  })];
188
206
  case 1:
189
207
  _c.sent();
190
- return [4 /*yield*/, interactiveIsomorphicRequest.respondWith.invoked()];
208
+ return [4 /*yield*/, interactiveRequest.respondWith.invoked()];
191
209
  case 2:
192
210
  _b = __read.apply(void 0, [_c.sent(), 1]), mockedResponse = _b[0];
211
+ if (!mockedResponse) {
212
+ return [2 /*return*/];
213
+ }
193
214
  log('event.respondWith called with:', mockedResponse);
194
- serializedResponse = JSON.stringify(mockedResponse);
215
+ responseClone = mockedResponse.clone();
216
+ return [4 /*yield*/, mockedResponse.text()
217
+ // Send the mocked response to the child process.
218
+ ];
219
+ case 3:
220
+ responseText = _c.sent();
221
+ serializedResponse = JSON.stringify({
222
+ status: mockedResponse.status,
223
+ statusText: mockedResponse.statusText,
224
+ headers: (0, headers_polyfill_1.headersToObject)(mockedResponse.headers),
225
+ body: responseText,
226
+ });
195
227
  this.process.send("response:" + requestJson.id + ":" + serializedResponse, function (error) {
196
228
  if (error) {
197
229
  return;
198
230
  }
199
- if (mockedResponse) {
200
- // Emit an optimistic "response" event at this point,
201
- // not to rely on the back-and-forth signaling for the sake of the event.
202
- _this.emitter.emit('response', isomorphicRequest, toIsoResponse_1.toIsoResponse(mockedResponse));
203
- }
231
+ // Emit an optimistic "response" event at this point,
232
+ // not to rely on the back-and-forth signaling for the sake of the event.
233
+ _this.emitter.emit('response', responseClone, capturedRequest, requestJson.id);
204
234
  });
205
235
  log('sent serialized mocked response to the parent:', serializedResponse);
206
236
  return [2 /*return*/];
@@ -1 +1 @@
1
- {"version":3,"file":"RemoteHttpInterceptor.js","sourceRoot":"","sources":["../src/RemoteHttpInterceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qDAA0C;AAE1C,6CAA2C;AAC3C,uDAAqD;AACrD,8DAAuE;AACvE,gEAAyE;AACzE,uDAAqD;AACrD,yDAAuD;AACvD,6EAA2E;AAC3E,+EAA6E;AAE7E;IAA2C,yCAE1C;IACC;eACE,kBAAM;YACJ,IAAI,EAAE,oBAAoB;YAC1B,YAAY,EAAE;gBACZ,IAAI,wCAAwB,EAAE;gBAC9B,IAAI,0CAAyB,EAAE;aAChC;SACF,CAAC;IACJ,CAAC;IAES,qCAAK,GAAf;QAAA,iBA+CC;QA9CC,iBAAM,KAAK,WAAE,CAAA;QAEb,IAAI,mBAA2C,CAAA;QAE/C,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,UAAO,OAAO;;;;gBAGzB,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;gBAEjD,IAAI,CAAC,GAAG,CAAC,uCAAuC,EAAE,iBAAiB,CAAC,CAAA;gBACpE,MAAA,OAAO,CAAC,IAAI,+CAAZ,OAAO,EAAQ,aAAW,iBAAmB,CAAC,CAAA;gBAExC,eAAe,GAAG,IAAI,OAAO,CAAO,UAAC,OAAO;oBAChD,mBAAmB,GAAG,UAAC,OAAO;wBAC5B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;4BAC/B,OAAO,OAAO,EAAE,CAAA;yBACjB;wBAED,IAAI,OAAO,CAAC,UAAU,CAAC,cAAY,OAAO,CAAC,EAAI,CAAC,EAAE;4BAC1C,IAAA,KAAA,OACJ,OAAO,CAAC,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AAM;6BACP;4BAED,qDAAqD;4BACrD,yEAAyE;4BACzE,KAAI,CAAC,OAAO,CAAC,IAAI,CACf,UAAU,EACV,aAAa,EACb,eAAe,EACf,WAAW,CAAC,EAAE,CACf,CAAA;wBACH,CAAC,CACF,CAAA;wBAED,GAAG,CAAC,gDAAgD,EAAE,kBAAkB,CAAC,CAAA;;;;aAC1E,CAAA;QAED,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACtB,KAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAA;YAC1D,GAAG,CAAC,wDAAwD,CAAC,CAAA;QAC/D,CAAC,CAAC,CAAA;QAEF,GAAG,CAAC,kDAAkD,CAAC,CAAA;QACvD,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAA;QAEvD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,cAAM,OAAA,KAAI,CAAC,OAAO,EAAE,EAAd,CAAc,CAAC,CAAA;QAChD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,cAAM,OAAA,KAAI,CAAC,OAAO,EAAE,EAAd,CAAc,CAAC,CAAA;IACjD,CAAC;IA/FM,yBAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAA;IAgG3C,yBAAC;CAAA,AAjGD,CAAwC,yBAAW,GAiGlD;AAjGY,gDAAkB"}
package/lib/glossary.d.ts CHANGED
@@ -1,18 +1,7 @@
1
- import type { HeadersObject, Headers } from 'headers-polyfill';
2
- import type { InteractiveIsomorphicRequest } from './InteractiveIsomorphicRequest';
3
- import type { IsomorphicRequest } from './IsomorphicRequest';
1
+ import type { InteractiveRequest } from './utils/toInteractiveRequest';
4
2
  export declare const IS_PATCHED_MODULE: unique symbol;
5
3
  export declare type RequestCredentials = 'omit' | 'include' | 'same-origin';
6
- export interface IsomorphicResponse {
7
- status: number;
8
- statusText: string;
9
- headers: Headers;
10
- body?: string;
11
- }
12
- export interface MockedResponse extends Omit<Partial<IsomorphicResponse>, 'headers'> {
13
- headers?: HeadersObject;
14
- }
15
4
  export declare type HttpRequestEventMap = {
16
- request(request: InteractiveIsomorphicRequest): Promise<void> | void;
17
- response(request: IsomorphicRequest, response: IsomorphicResponse): Promise<void> | void;
5
+ request(request: InteractiveRequest, requestId: string): Promise<void> | void;
6
+ response(response: Response, request: Request, requestId: string): Promise<void> | void;
18
7
  };
@@ -1 +1 @@
1
- {"version":3,"file":"glossary.js","sourceRoot":"","sources":["../src/glossary.ts"],"names":[],"mappings":";;;AAIa,QAAA,iBAAiB,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAA"}
1
+ {"version":3,"file":"glossary.js","sourceRoot":"","sources":["../src/glossary.ts"],"names":[],"mappings":";;;AAEa,QAAA,iBAAiB,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAA"}
package/lib/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  export * from './glossary';
2
2
  export * from './Interceptor';
3
3
  export * from './BatchInterceptor';
4
- export * from './IsomorphicRequest';
5
- export * from './InteractiveIsomorphicRequest';
6
4
  export { getCleanUrl } from './utils/getCleanUrl';
7
5
  export { encodeBuffer, decodeBuffer } from './utils/bufferUtils';
package/lib/index.js CHANGED
@@ -14,8 +14,6 @@ exports.decodeBuffer = exports.encodeBuffer = exports.getCleanUrl = void 0;
14
14
  __exportStar(require("./glossary"), exports);
15
15
  __exportStar(require("./Interceptor"), exports);
16
16
  __exportStar(require("./BatchInterceptor"), exports);
17
- __exportStar(require("./IsomorphicRequest"), exports);
18
- __exportStar(require("./InteractiveIsomorphicRequest"), exports);
19
17
  /* Utils */
20
18
  var getCleanUrl_1 = require("./utils/getCleanUrl");
21
19
  Object.defineProperty(exports, "getCleanUrl", { enumerable: true, get: function () { return getCleanUrl_1.getCleanUrl; } });
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,gDAA6B;AAC7B,qDAAkC;AAClC,sDAAmC;AACnC,iEAA8C;AAE9C,WAAW;AACX,mDAAiD;AAAxC,0GAAA,WAAW,OAAA;AACpB,mDAAgE;AAAvD,2GAAA,YAAY,OAAA;AAAE,2GAAA,YAAY,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,gDAA6B;AAC7B,qDAAkC;AAElC,WAAW;AACX,mDAAiD;AAAxC,0GAAA,WAAW,OAAA;AACpB,mDAAgE;AAAvD,2GAAA,YAAY,OAAA;AAAE,2GAAA,YAAY,OAAA"}
@@ -15,24 +15,32 @@ export declare class NodeClientRequest extends ClientRequest {
15
15
  * using the "mock" response source.
16
16
  */
17
17
  static suppressErrorCodes: string[];
18
- private url;
19
- private options;
20
18
  private response;
21
19
  private emitter;
22
20
  private log;
23
21
  private chunks;
24
22
  private responseSource;
25
23
  private capturedError?;
26
- requestBody: Buffer[];
24
+ url: URL;
25
+ requestBuffer: Buffer | null;
27
26
  constructor([url, requestOptions, callback]: NormalizedClientRequestArgs, options: NodeClientOptions);
27
+ private writeRequestBodyChunk;
28
28
  write(...args: ClientRequestWriteArgs): boolean;
29
29
  end(...args: any): this;
30
30
  emit(event: string, ...data: any[]): boolean;
31
+ /**
32
+ * Performs the intercepted request as-is.
33
+ * Replays the captured request body chunks,
34
+ * still emits the internal events, and wraps
35
+ * up the request with `super.end()`.
36
+ */
37
+ private passthrough;
38
+ /**
39
+ * Responds to this request instance using a mocked response.
40
+ */
31
41
  private respondWith;
32
42
  /**
33
43
  * Terminates a pending request.
34
44
  */
35
45
  private terminate;
36
- private getRequestBody;
37
- private toIsomorphicRequest;
38
46
  }