Code Monkey home page Code Monkey logo

mock-office's Introduction

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.
  • Use GUI or REST to manage servers.

Table of contents:

  1. Installation
  2. Usage
  3. Introduction
    1. Behaviours
    2. Events
    3. Reactions
  4. Adding server
  5. Adding behaviour
    1. Behaviour configuration
    2. Event configuration
    3. Reaction configuration
  6. Fallback mode
  7. Development
  8. Test

Instalation

Install from npm:

$ npm run install mock-office -g

Usage

$ mock-office [--gui]

It exposes:

  • REST API: http://localhost:3060
  • GUI: http://localhost:3070

Introduction

Mock Office works like respository of mock servers. Idea was to have one common interface for spawning and managing HTTP and Web Socket servers.

You have two ways to interact with it.

  • REST API
  • GUI

Behaviours

Mocks are done by adding behaviours to servers. Behaviour is simply pair of event and reactions. Every type of server has its own accepted event types and reactions.

Events

When something happens(e.g. incoming request, client connected to server) server generates event objects which are being compared with behaviour event requirements and if match succeeds then reactions trigger.

Reactions

Reactions are simply server commands e.g. send a http response, start sending web socket messages.

Adding server

POST /add-server

key type required default description
name string yes - identify your server
type string yes - server type, it can be 'http' or 'ws'
port number no 3000 listening port
fallbackUrl string no '' if provided it triggers fallback mode

Adding behaviours

POST /add-behaviour

key type required default description
serverId string yes - the server id to which we want to add the behavior
behaviour object yes - behaviour config object

Behaviour options

key type required default description
event event config object yes - object describing event which must happen to trigger reactions, see event types and they params for specific servers
reactions array of reaction config object yes - list of reaction configs

Event options

key type required default description
type string yes - event type
params ajv schema properties object no {} custom params specific to the event type

Reaction options

key type required default description
type string yes - reaction type
params ajv schema properties object no {} custom params specific to the event type
schedule schedule config object no {} schedule params e.g. delay, interval

Schedule options

key type required default description
delay number no 0 reaction delay in ms
interval number no 0 interval in ms

Fallback mode

Fallback mode let you use your real API while mocking some endpoints not ready yet. This is done by mock server proxying request to fallback API when it can't find behaviour. Nevertheless when in fallback mode you can cover existing endpoints with mocked counterparts.

Development

To start app development clone repo first and then:

$ npm i
$ npm run watch # runs webpack dev-server for GUI development
$ npm run serve-app # runs node app
$ npm run serve-app-with-gui # runs node app with GUI events server required for GUI being updated

Test

To run tests:

$ npm run test

mock-office's People

Contributors

clxandstuff avatar

Watchers

 avatar  avatar  avatar

Forkers

wand3r

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.