wand3r / mock-office

Tool for running mock servers with ease

Home Page:https://github.com/xclix/mock-office

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mock Office

travis build status npm version Coverage Status

Tool for running mock servers locally to faciliate frontend development.

  • Create and run multiple HTTP and Web Socket servers instantly.
  • Cover complex scenarios, including delays, backend error responses, custom headers etc.
  • Run it locally or on shared resources, CI.

Table of contents:

  1. Installation
  2. Usage
  3. Adding expectations
  4. Test

Instalation

Install from npm:

$ npm run install mock-office -g

Usage

$ mock-office [server type] [parameters]

CLI parameters:

server type - http or ws

--src, -s - path to file with mocks

--port, -p - port to listen (default 3000)

Adding expectations

Admin REST server starts along with mock server on port (server port + 1).

POST /expectation

Http server

Example:

{
    "request": {
        // matchers
    },
    "response": {
        // params
    }
}

Request matchers:

  • headers - Object - key-value pairs of HTTP headers

  • method - String - HTTP method

  • path - String - url path

Response parameters:

  • headers - Object - key-value pairs of HTTP headers

  • status - Number - HTTP status code

  • body - String - stringified body content

  • delay - Number - delay time in ms

Web socket server

{
    "event": "connection",
    // or
    "event": "incomingMessage",
    "incomingMessage": {
        // matchers
    }
    "messages": [
        {
            //params
        },
        // more messages...
    ]
}

connection matchers

// no matchers at the moment

incomingMessage matchers:

  • body - String - message body

message parameters:

  • delay - Number - delay time in ms

  • interval - Number - interval time in ms

  • body - String - plain text body content

Test

To run tests:

$ npm test

About

Tool for running mock servers with ease

https://github.com/xclix/mock-office

License:Creative Commons Zero v1.0 Universal


Languages

Language:JavaScript 87.8%Language:CSS 12.1%Language:HTML 0.1%