Skip to content

Latest commit

 

History

History
76 lines (60 loc) · 3 KB

README.md

File metadata and controls

76 lines (60 loc) · 3 KB

Mockizen

CI codecov BCH compliance Bugs Code Smells Duplicated Lines (%) Maintainability Rating Dependabot Status

Mockizen is a minimal mock http server that can run anywhere and exposes predefined endpoints. Built with node webframework Express. Mockizen docker image is built on top of Node Alpine image and has 40 Mb image size when compressed.

How To Use

Check out Sample Mock OAuth Server

Here's the docker command

docker run -p  9155:8080 -v  {DIR_CONTAINS_SCENARIONS_JSON_AND_OTHER_MOCK_FILES}:/opt/app/mocks nazmialtun/mockizen:latest

Mockizen reads routes from scenarios.json file. First create scenarios.json file. Here is a sample :

{
  "routes": {
    "/live": {
      "get": 200
    },
    "/api/v1/user": {
      "get": "user-get.js",
      "post": "user-post.js",
      "delete": 202
    },
    "/userlist": {
      "get": "users.json"
    },
    "/some-image.png": {
      "get": "path/route-to-image.png"
    },
    "/v1/:production-id": {
      "post": "production.js",
      "/details": {
        "get": "production-details.js"
      }
    }
  }
}

For more details about routing please take a look at express routing guide

There are three ways to mock an endpoint:

  1. Declaring HTTP status code. (e.g "get" : 200) : Will return status code with empty or dummy body.
  2. Static file/content (e.g "get" : "image.png" ) : Will return static file
  3. Javascript file (e.g "post":"user.js" ) : Will execute javascript file. Javascript file should be in following format ;
module.exports = function (req, res) {
  // Read request
  // ....
  // Set response
};

How About Third Party NPM Packages ?

Third party npm packages are supported. Make sure packages.json that contains npm packages used by mock js file is placed in the same directory with scenarios.json.

Contribution

Feel free to contribute by creating a pull request