Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mbellman/stop-mocking-me
Mock your services.
https://github.com/mbellman/stop-mocking-me
Last synced: 3 days ago
JSON representation
Mock your services.
- Host: GitHub
- URL: https://github.com/mbellman/stop-mocking-me
- Owner: mbellman
- License: mit
- Created: 2019-11-07T03:42:15.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-11T12:22:29.000Z (almost 2 years ago)
- Last Synced: 2024-04-29T17:46:06.356Z (7 months ago)
- Language: TypeScript
- Size: 48.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# stop-mocking-me
Mock your services.## Usage examples
`mock-routes.js`
```
module.exports = {
'/api/user': {
GET: './mocks/api/user.json'
},
'/api/account': {
GET: './mocks/api/account-get.json',
POST: './mocks/api/account-update.json
},
'/api/page': {
GET: {
path: './mocks/api/page.js',
delay: 500,
status: 200
}
}
];
````mocks/api/page.js`
```
module.exports = (req, res) => {
// ...
};
````server.js`
```
const express = require('express');
const app = express();// Just pass any valid express app and your routes.
createMockServer(app, require('./mock-routes'));
```## API
#### `createMockServer(app: Express.Application, routes: MockRoutesMap);`
```
type MockRoutesMap = Record;type MockRouteConfig = Record;
type RequestMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
type RequestHandler = (req: Express.Request, res: Express.Response) => any;
interface MockRequestConfig {
/**
* A mock data file import path, or a request handler function.
*/
serve: string | RequestHandler;
/**
* An optional response status code. Defaults to 200.
*/
status?: number;
/**
* An optional response delay. Defaults to 0.
*/
delay?: number;
/**
* Determines whether the mock data for a given route/request method
* is cached, i.e. does not change on file changes. Defaults to false,
* enabling mock responses to be updated without a dev server restart.
*/
cached?: boolean;
}
```