Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fetch-vcr

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-vcr

Stop mocking HTTP Requests. Just record and then play them back

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5K
decreased by-10.75%
Maintainers
1
Weekly downloads
 
Created
Source

fetch-vcr

Stop mocking HTTP Requests. Just record and then play them back. See vcr/vcr for the main idea.

Usage

The basics are:

  1. turn on cache mode
  2. run your tests

This will record (and load) all the HTTP responses into the ./_fixtures/ directory.

And when you run the steps again, no network traffic happens.

How do I set this up?

// import fetch from 'fetch';
import fetch from 'fetch-vcr';

// Configure what mode this VCR is in (playback, recording, cache)
// and where the recordings should be loaded/saved to.
fetch.configure({
  mode: 'record',
  fixturePath: __dirname + '/_fixtures'
})

fetch('http://openstax.org')
.then(response => {
  response.text()
  .then(text => {
    console.log(text)
  })
})

What are the different modes?

  • playback: (default) only uses the local fixture files
  • cache: tries to use the fixture and if not found then it is fetched and then saved (useful when adding new tests)
  • record: forces files to be written (useful for regenerating all the fixtures)
  • erase: deletes the fixture corresponding to the request

How can I set the VCR mode?

You can set the mode either by:

  • setting the VCR_MODE=record environment variable
  • explicitly running fetch.configure({mode: 'record'})

How can I use this in a browser?

Currently you can record HTTP requests in NodeJS and play them back in the browser.

To play them back in a browser, just run fetchVCR.configure({fixturePath: './path/to/_fixtures'}) and fetchVCR will use that path to load the files via AJAX requests.

Keywords

FAQs

Package last updated on 14 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc