diff --git a/src/interceptors/ClientRequest/MockHttpSocket.ts b/src/interceptors/ClientRequest/MockHttpSocket.ts index 656b6ac0..b21863f4 100644 --- a/src/interceptors/ClientRequest/MockHttpSocket.ts +++ b/src/interceptors/ClientRequest/MockHttpSocket.ts @@ -336,8 +336,12 @@ export class MockHttpSocket extends MockSocket { // One Socket instance can only handle one request at a time. if (canHaveBody) { this.requestStream = new Readable({ - // Dummy implementation. We control the queue in the onRequestBody\End functions - read: () => {} + /** + * @note Provide the `read()` method so a `Readable` could be + * used as the actual request body (the stream calls "read()"). + * We control the queue in the onRequestBody/End functions. + */ + read: () => {}, }) } @@ -376,9 +380,7 @@ export class MockHttpSocket extends MockSocket { 'Failed to write to a request stream: stream does not exist' ) - if (this.requestStream.push(chunk)) { - process.nextTick(() => this.emit('drain')) - } + this.requestStream.push(chunk) } private onRequestEnd(): void { @@ -386,7 +388,6 @@ export class MockHttpSocket extends MockSocket { if (this.requestStream) { this.requestStream.push(null) } - process.nextTick(() => this.emit('drain')) } private onResponseStart: ResponseHeadersCompleteCallback = ( diff --git a/src/interceptors/Socket/MockSocket.ts b/src/interceptors/Socket/MockSocket.ts index d35976c9..3dc31fe7 100644 --- a/src/interceptors/Socket/MockSocket.ts +++ b/src/interceptors/Socket/MockSocket.ts @@ -34,7 +34,7 @@ export class MockSocket extends net.Socket { public write(...args: Array): boolean { const [chunk, encoding, callback] = normalizeWriteArgs(args as WriteArgs) this.options.write(chunk, encoding, callback) - return false + return true } public end(...args: Array) {