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.
Install from npm:
$ npm run install mock-office -g
$ mock-office [--gui]
It exposes:
- REST API:
http://localhost:3060
- GUI:
http://localhost:3070
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
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.
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 are simply server commands e.g. send a http response, start sending web socket messages.
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 |
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 |
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 |
key | type | required | default | description |
---|---|---|---|---|
type | string | yes | - | event type |
params | ajv schema properties object | no | {} | custom params specific to the event type |
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 |
key | type | required | default | description |
---|---|---|---|---|
delay | number | no | 0 | reaction delay in ms |
interval | number | no | 0 | interval in ms |
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.
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
To run tests:
$ npm run test