Record and playback HTTP requests
This is built to make testing against third party services a breeze. No longer will your test suite fail because an external service is down.
Install the module with:
npm install eight-track
// Start up a basic applciationvar express = ;var eightTrack = ;var request = ;;// Create a server using a `eight-track` middleware to the original;// Hits original server, triggering a `console.log('Pinged!')` and 'Hello World!' response;// Hits saved response but still receieves 'Hello World!' response;
eightTrack as its
Middleware creator for new
eightTrack's. This is not a constructor.
Object- Container for parameters
String|Object- URL of a server to proxy to
String- Path to load/save HTTP responses
Function- Function to adjust
request'ssave location signature
function (info)and can either mutate the
infoor return a fresh object
infowill have the following properties
String- HTTP version received from
Object- Headers received by
Object- Trailers received by
String- HTTP method that was used (e.g.
String- Pathname that
Buffer- Buffered body that was written to
multipart/form-datacan be found below)
eightTrack returns a middleware with the signature
function (req, res)
// Example of string url;// Example of object url;
If you need to buffer the data before passing it off to
eight-track that is supported as well.
The requirement is that you record the data as a
multipart/form-data- Ignore randomly generated boundaries and consolidate similar
Forward an incoming HTTP request in a
http.IncomingMessage- Inbound request to an HTTP server (e.g. from
Function- Callback function with
(err, res, body)signature
Error- HTTP error if any occurred (e.g.
Object- Container that looks like an HTTP object but simiplified due to saving to disk
String- HTTP version received from external server response (e.g.
Object- Headers received by response
Object- Trailers received by response
Number- Status code received from external server response
Buffer- Buffered body that was written to response
Buffer- Sugar variable for
eight-track can talk to servers that are behind a specific path
// Start up a server that echoes our path;// Create a server using a `eight-track` middleware to the original;// Logs `/hello/world`, concatenated result of `/hello` and `/world` pathss;
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via grunt and test via
Copyright (c) 2014 Uber
Licensed under the MIT license.