Node VCR
Record HTTP interactions The Node Way™. This repository is basically a clone of flickr/yakbak and is also based on ijpiantanida/talkback.
Installation
$ npm install node-vcr --save-dev
Code Documentation
Please refer to the github wiki page
Usage
The main idea behind testing HTTP clients with node-vcr is:
- Make your client's target host configurable
- Set up a node-vcr server locally to proxy the target host
- Point your client at the node-vcr server.
Then develop or run your tests. If a recorded HTTP request is found on disk, it will be played back instead of hitting the target host. If no recorded request is found, the request will be forwarded to the target host and recorded to disk (or return 404).
const crypto = const http = const nodeVcr = const path = const _ = const proxyTarget = 'https://api.github.com/users/mbaertschi/orgs'const dirname = pathconst port = 8888 const hash = { const action = `_` const content = body const md5sum = crypto return `_`} const handler = const server = httpserver
Options
Name | Type | Description | Default |
---|---|---|---|
host | String | The proxy target to tape | |
dirname | String | The tapes directory | ./tapes/ |
noRecord | Boolean | If true, requests will return a 404 error if the tape doesn't exist | false |
maxRedirects | Number | Number of max http redirects. 0 means no redirects | 5 |
tapeRequestBody | Boolean | If enabled the request body will be written to tape | false |
ignoreHeaders | Array | Headers which must not be written down to tape (req and res) | [ ] |
hash | Function | Provide your own IncomingMessage hash function of the signature function (req, body) |
see source |
reload | Boolean | If true, node-vcr will reload (delete and record) required tape | false |
refresh | Boolean | If true, node-vcr will refresh required tape | false |
Examples
Some examples and its results can be found in the folder under ./examples.
Tech-Stack
- nodemon development mode
- jest test environment
- jsdoc documentation
- npm-check for dependencies check
- pre-commit for pre git commit hooks
- babel to compile to es2015
Scripts
# start development mode with nodemon yarn dev# run tests with jest yarn test# start continous integration testing with jest yarn ci# generate the jsdoc documentation yarn jsdoc# run eslint yarn lint# check for dependendies updates yarn deps# build with babel yarn build
License
MIT