socket-recorder
Record and log all communication over sockets.
Patching Socket
When using SocketRecorder, net.Socket needs to be patched before anything else
extends or creates a Socket in order for that to be recorded. Patching can be
done by either calling patch()
or by assigning record
:
; // automatically patches when retrieving the record method:const record = ; // net Socket can also be unpatched:;
Basic usage
const record = ; // basic recording of process.stdout; // or use it as a Promise;
Response from console.log
:
events: request: 'Hello, world!\n' created_at: 14894603147533242 request: 'Goodbye, world!\n' created_at: 14894603147534758 source: 'stdout'
More advanced responses
const record = ;const express = ; // recording of an HTTP transactionconst app = ;app;const server = app;
Response from HTTP transaction:
events: request: 'GET / HTTP/1.1\r\nHost: localhost:8888\r\nConnection: close\r\n\r\n' created_at: 14894605456201575 response: 'HTTP/1.1 200 OK\r\nX-Powered-By: Express\r\nContent-length: 13\r\nDate: Tue, 14 Mar 2017 03:02:25 GMT\r\nConnection: close\r\n\r\nHello, world!' created_at: 14894605456280654 connection: host: 'localhost' port: '8888' source: 'tcp'