dynamock
is a dynamic mock/fixture server designed for functional testing.
yarn add dynamock -D
# or NPM
npm install dynamock --save-dev
# dynamock PORT [HOST]
dynamock 3001
WIP
WIP
WIP
Using the configuration is optional. However it gives the ability of reusing redundant data across requests and simplifying fixtures setup.
Responses
- Status 200 - OK
{
"headers": "{object} - Dictionary of headers (object) by name (string)",
"query": "{object} - Dictionary of query (object) by name (string)",
"cookies": "{object} - Dictionary of cookies (object) by name (string)"
}
Example:
{
"headers": {},
"query": {},
"cookies": {}
}
Request
- Body
{
"headers": "{object} [default={}] - Dictionary of headers (object) by name (string)",
"query": "{object} [default={}] - Dictionary of query (object) by name (string)",
"cookies": "{object} [default={}] - Dictionary of cookies (object) by name (string)"
}
Example:
{
"headers": {
"apiBearer": {
"Authorization": "Bearer xyz"
}
}
}
Responses
- Status 200 - OK
{
"headers": "{object}",
"query": "{object}",
"cookies": "{object}"
}
Example:
{
"headers": {
"captcha": {
"X-CAPTCHA-TOKEN": "fake"
},
"cors": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "*"
}
},
"query": {
"campaign": {
"utm_source": "x",
"utm_campaign": "y"
}
},
"cookies": {
"anonymousUser": {
"PHPSESSID": "x"
},
"loggedInUser": {
"PHPSESSID": "y"
}
}
}
- Status 400 - BAD REQUEST
Wrong configuration format
Responses
- Status 204 - NO CONTENT
The fixtures are composed of:
- request data to match the incoming requests
- response data when a match occurred
Request
- Body
{
"request": {
"path": "{string} - Http path to match requests, use wildcard '*' to match all",
"method": "{string} - Http method to match requests, case insensitive, use wildcard '*' to match all",
"headers": "{object|array} [default={}] - Headers to match requests",
"query": "{object|array} [default={}] - Query to match requests",
"cookies": "{object|array} [default={}] - Cookies to match requests",
"body": "{object} [default=``] - Body to match requests",
"options": {
"headers": {
"strict": "{boolean} [default=false] - Strictly match headers"
},
"cookies": {
"strict": "{boolean} [default=false] - Strictly match cookies"
},
"query": {
"strict": "{boolean} [default=false] - Strictly match query"
},
"body": {
"strict": "{boolean} [default=false] - Strictly match body"
}
}
},
"response": {
"status": "{number} [default=200] - Response status code",
"headers": "{object|array} [default={}] - Response headers",
"cookies": "{object|array} [default={}] - Response cookies",
"body": "{string|object|array} [default=``] - Body to response",
"filepath": "{string} [default=``] - Filepath to serve with auto mime-types",
"options": {
"delay": "{number} [default=0] - Delay the response with a number of milliseconds",
"lifetime": "{number} [default=1] - Number of times the fixture can be consumed before getting removed, use 0 for unlimited consumption"
}
},
"responses": "{array} [default=[]] - Array of responses"
}
Examples:
{
"request": {
"path": "/pandas",
"method": "get"
},
"response": {
"body": [{ "id": "1" }, { "id": "2" }]
}
}
{
"request": {
"path": "/cdn/images/fennec.jpg",
"method": "get"
},
"response": {
"filepath": "/absolute/path/tofennec.jpg",
"options": {
"delay": 1000
}
}
}
{
"request": {
"path": "/heros",
"method": "POST",
"body": {
"name": "po",
"type": "panda"
},
"options": {
"body": {
"strict": true
}
}
},
"response": {
"body": {
"id": "1",
"name": "po",
"type": "panda"
}
}
}
{
"request": {
"path": "*",
"method": "OPTIONS"
},
"response": {
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "*"
},
"body": ""
}
}
{
"request": {
"path": "/",
"method": "get"
},
"responses": [
{
"body": "first return"
},
{
"body": "second return"
}
]
}
Responses
- Status 200 - OK
{
"id": "{string}"
}
Example:
{
"id": "38ed32e9fb0a1e5c7cb1b6f0ff43f6060d8b4508"
}
- Status 400 - BAD REQUEST
The configuration is not valid
- Status 409 - CONFLICT
Route {METHOD} ${PATH} is already registered.
It is meant to setup multiple fixtures at once.
Request
- Body
[
{
"request": {
"path": "{string} - Http path to match requests, use wildcard '*' to match all",
"method": "{string} - Http method to match requests, case insensitive, use wildcard '*' to match all",
"headers": "{object|array} [default={}] - Headers to match requests",
"query": "{object|array} [default={}] - Query to match requests",
"cookies": "{object|array} [default={}] - Cookies to match requests",
"body": "{object} [default=``] - Body to match requests",
"options": {
"headers": {
"strict": "{boolean} [default=false] - Strictly match headers"
},
"cookies": {
"strict": "{boolean} [default=false] - Strictly match cookies"
},
"query": {
"strict": "{boolean} [default=false] - Strictly match query"
},
"body": {
"strict": "{boolean} [default=false] - Strictly match body"
}
}
},
"response": {
"status": "{number} [default=200] - Response status code",
"headers": "{object|array} [default={}] - Response headers",
"cookies": "{object|array} [default={}] - Response cookies",
"body": "{string|object|array} [default=``] - Body response",
"filepath": "{string} [default=``] - Filepath to serve with auto mime-types",
"options": {
"delay": "{number} [default=0] - Delay the response with a number of milliseconds",
"lifetime": "{number} [default=1] - Number of times the fixture can be consumed before getting removed, use 0 for unlimited consumption"
}
},
"responses": "{array} [default=[]] - Array of responses"
}
]
Examples:
[
{
"request": {
"path": "/pandas",
"method": "get"
},
"response": {
"body": [{ "id": "1" }, { "id": "2" }]
}
},
{
"request": {
"path": "/cdn/images/fennec.jpg",
"method": "get"
},
"response": {
"filepath": "/absolute/path/tofennec.jpg"
}
}
]
Responses
- Status 200 - OK
[
{
"id": "{string}"
}
]
Example:
[
{
"id": "38ed32e9fb0a1e5c7cb1b6f0ff43f6060d8b4508"
},
{
"id": "086c67ef89fd832deeae33b209e6e8ecc6b32003"
}
]
- Status 400 - BAD REQUEST
The fixture is not valid
- Status 409 - CONFLICT
Another fixture with the same request is already registered
Request
- Params
{
"id": "{string}"
}
Example:
DELETE /___fixtures/38ed32e9fb0a1e5c7cb1b6f0ff43f6060d8b4508
Responses
- Status 204 - NO CONTENT
Responses
- Status 204 - NO CONTENT