npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-vcr

v2.3.4

Published

Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests

Downloads

157

Readme

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:

  1. Make your client's target host configurable
  2. Set up a node-vcr server locally to proxy the target host
  3. 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 = require('crypto')
const http = require('http')
const nodeVcr = require('node-vcr')
const path = require('path')
const _ = require('lodash')

const proxyTarget = 'https://api.github.com/users/mbaertschi/orgs'
const dirname = path.join(__dirname, 'playback')
const port = 8888

const hash = (req, body) => {
  const action = `${req.method.toLowerCase()}_${_.last(req.url.split('/'))}`
  const content = body.toString()
  const md5sum = crypto.createHash('md5')

  return `${action}_${md5sum.update(content).digest('hex')}`
}

const handler = nodeVcr(proxyTarget, {
  dirname,
  hash
})

const server = http.createServer(handler)
server.listen(port)

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

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