Skip to content

Commit

Permalink
fix(MockSocket): return true from .write()
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Mar 21, 2024
1 parent 1419337 commit 8503ed7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/interceptors/ClientRequest/MockHttpSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class MockHttpSocket extends MockSocket {
if (canHaveBody) {
this.requestStream = new Readable({
// Dummy implementation. We control the queue in the onRequestBody\End functions
read: () => {}
read: () => {},
})
}

Expand Down Expand Up @@ -376,17 +376,14 @@ 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 {
// Request end can be called for requests without body.
if (this.requestStream) {
this.requestStream.push(null)
}
process.nextTick(() => this.emit('drain'))
}

private onResponseStart: ResponseHeadersCompleteCallback = (
Expand Down
2 changes: 1 addition & 1 deletion src/interceptors/Socket/MockSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class MockSocket extends net.Socket {
public write(...args: Array<unknown>): boolean {
const [chunk, encoding, callback] = normalizeWriteArgs(args as WriteArgs)
this.options.write(chunk, encoding, callback)
return false
return true
}

public end(...args: Array<unknown>) {
Expand Down

0 comments on commit 8503ed7

Please sign in to comment.