0.0.12 • Published 1 year ago

@crafts/mock-server v0.0.12

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Mock Server

Zero config, simple mock server! Keep the mocks close within your code.

Features

  1. Simple way to create mock. Example.
  2. Pass blob (mock files pattern) option for custom mock paths.
  3. Proxy to actual server using -p or --proxy. All unmatched requested will be sent to proxy.
  4. Out of the box watch method, if any new file is created/changed within the watch path, server will register them.
  5. Create mocks with dynamic URL for eg. /org/:orgId/projects/
  6. Custom status code and delay.
  7. Disable specific mock using disabled option in mock.json.

Usage

Install it

npm i @crafts/mock-server

Add files

Add JSON files ending with .mock.json, anywhere in repo as show in example

Run the server

npx @crafts/mock-server

Set the base URL

Point at http://localhost:4000

Options available

Optiondescriptiondefault
blobPattern to match the mocks/**/*.mock.json
proxyOriginal/actual server address--
rootsoruce dir for searching mocksprocess.cwd() Path from where script is ran

How to write mocks

Writing mocks is very easy, for real. Create a json file matching the search pattern (by default: /**/*.mock.json).

Example:

{
  "mocks": [
    {
      "url": "/a",
      "method": "PATCH",
      "response": { "a": 2 },
      "status": 201,
      "delay": 500,
      "disabled": false
    }
  ]
}

Options for mock

PropstypeRequired
urlstringtrue
methodstringtrue
responseobjecttrue
delaynumberfalse
statusnumberfalse
disabledbooleanfalse

UI

Mock server comes with UI (beta) for better experiance.

Screenshot 2023-02-05 at 10 23 36 PM Screenshot 2023-02-05 at 10 23 45 PM Screenshot 2023-02-05 at 10 23 59 PM

Coming soon

Note: Mock server is in beta, things will break but should not fall apart.

Please follow the board for live updates

https://github.com/users/mukuljainx/projects/5