Exciting release!Introducing "safe npm". Learn more
Socket
Log inDemoInstall

serverless-offline-http-mock

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Issues
File Explorer

Advanced tools

serverless-offline-http-mock

This is a plugin for the serverless framework that provides the ability to create mock responses to HTTP(S) requests.

    1.0.0latest
    GitHub

Version published
Maintainers
1
Weekly downloads
591
decreased by-30.22%

Weekly downloads

Changelog

Source

[1.0.0] - 2022-08-22

Changed

  • Added a flag to enable/disable the mocks #35

Readme

Source

serverless-offline-http-mock

Travis CI Build Status

Overview

This is a plugin for the serverless framework that provides the ability to create mock responses to HTTP(S) requests. This is useful when developing integration against an API spec that doesn't yet exist. This plugin uses nock to provide mock responses. It supports mock requests for:

Requirements

An existing serverless framework project.

Installation

npm install serverless-offline-http-mock

OR

yarn add serverless-offline-http-mock

Upgrade to v1.0.0

Please note that if you installed a version of this prior to v1.0.0, you will need to follow step #2 below and add a truthy serverless-offline-http-mock-enabled value in order for your mocks to be loaded.

Usage

  1. Within the serverless.yml file, enable the plugin by placing an serverless-offline-http-mock entry in the plugins section. If using Serverless Offline, make sure it is placed above the serverless-offline plugin

  2. Create a serverless-offline-http-mock-enabled entry in the custom section with a truthy (true, 1, etc) or falsy value (false, 0, etc). You can also use environment variables (for example, ${env:MOCK_ENABLED}).

  3. Create a serverless-offline-http-mock entry in the custom section.

  4. For each host, create an entry containing hostname, a list of JS files to load, and an optional directory. See serverless.yml example below.

  5. In each JS file, export a function that accepts the nock library and hostname as arguments. Within that function, implement nock to handle the HTTP(S) requests. See example.js example below.

Example

serverless.yml:

... custom: serverless-offline-http-mock-enabled: 1 serverless-offline-http-mock: - hostname: http://www.example.com directory: 'mocks' # Optional mocks: - example.js plugins: - serverless-offline-http-mock # Note how this comes before serverless-offline - serverless-offline

mocks/example.js:

const mocks = (nock, hostname) => nock(hostname) .persist() .get('/') .reply(200, 'success!'); module.exports = mocks;

Development

yarn test

Keywords

FAQs

Last updated on 22 Aug 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc