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

@mesosphere/mockserver

Package Overview
Dependencies
Maintainers
13
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mesosphere/mockserver

A mockserver that allows you to mock XHR, long-polling XHR, server sent events and websocket connections

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
13
Created
Source

Mockserver

Usage

We provide two interfaces, a CLI for the fast and easy way to interact with the mock server and a programmatic API to give you the control over everything.

CLI

The CLI is entirely controlled via environment variables, here are the ones you may configure

  • PROXY_HOST_PORT (required): determine where to send the requests no mock matches against to. E.g. "my-service.com:2342"
  • MOCK_SEARCH_EXPRESSION (required): glob to specify where to search for mocks. E.g. "./*/-mock.js"
  • PORT (optional): port of the mockserver

Your mocks should be defined in Javascript files as named export:

// The name is important!
export const mocks = [
  {
    id: "my-first-mock",
    request: (req, res) => {
      // Same interface as express middlewares
      res.status(200);
    }
  }
];

Please note that we import these files at start time of the mockserver.

API

import mockserver from "mockserver";
// Every option is required
const { port, close } = await mockserver({
  port: 0, // zero means "choose your own"
  proxyHost: "my-service",
  proxyPort: 42,
  mocks: [
    {
      id: "my-first-mock",
      request: (req, res) => {
        // Same interface as express middlewares
        res.status(200);
      }
    }
  ]
});

Development

  • Installation: npm install
  • Start production server: npm start
  • Start development server: npm run watch

Testing

Please run npm test

Keywords

FAQs

Package last updated on 04 Jan 2019

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