New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

generate-nocks-from-requests

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generate-nocks-from-requests

Automatically generate Nock mocks from requests made with Request

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Generate Nocks from Requests – 0.1.0

Automatically generate Nock mocks from requests made with Request.

Usage

First, let's install it. Since you normally don't want GNFR (too lazy to type "Generate Nocks from Requests"1) installed permanently, we'll install it like this:

npm i generate-nocks-from-requests

Now lets hook it up:

/* ... code */
const request = require('request')
require('generate-nocks-from-requests')(request)
/* ... more code */

Now run you're thing and trigger the requests you want to mock. After you'll probably need to kill the process. Now there should be a mock.js file in the directory you ran the server from. It contains you're nock mocks 🎉.

API

default (Request, Options) => Flush

The default export is a function taking a Request object and Options as a parameter and returns the Flush function.

Options object

The default arguments are as follows:

{
  repeat = 999,
  delay = 200,
  output = 'mocks.js',
  flushOnExit = true
}
  • repeat: Controls the argument that is passed to Nocks #times().
  • delay: Controls the argument passed to Nocks #delay().
  • output: The file to save the mocks to.
  • flushOnExit: Wether or not to flush when the process exits. (see Flush)

Flush () => void

Writes all the buffered mocks to the file defined in options.output. The Flush function is called automatically when the process exits regularly, or it receives one of this signals SIGTERM, SIGHUP, 'SIGBREAK'. To disable this behaviour, set flushOnExit: false.

Footnotes

  1. Yes, I did not type it again, but just copy-pasted it over from the header.

FAQs

Package last updated on 16 Dec 2016

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