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

serverless-offline-http-mock

v1.0.0

Published

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

Downloads

3,250

Readme

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