@r35007/mock-server
Advanced tools
Changelog
v13.0.0
Changelog
v12.1.0
import other useful node packages as follows
const {
MockServer,
express, // express
lodash, // lodash
nanoid, // nanoid
spinner, // ora
pathToRegexp, // path-to-regexp
chalk, // chalk
axios, // axios
watcher, // chokidar.
} = require('@r35007/mock-server');
renamed mockserver.setExpressApp()
to mockserver.createExpressApp()
fixed - MockServer.Destroy()
resets server config to default config which makes us to recreate the mockServer using MockServer.Create()
method.
Now we don't want to recreate MockServer instance after destroy. MockServer.Destroy()
destroys the express server and resets all the data to defaults except server config.
Changelog
v12.0.0
added node packages in MockServer instance
MockServer._
- lodash.MockServer.axios
- axios.MockServer.express
- express.MockServer.chalk
- chalk.MockServer.watcher
- chokidar.MockServer.pathToRegexp
- pathToRegexp.MockServer.nanoid
- nanoid.MockServer.ora
- oraadded setter methods to reset to defaults
mockserver.setDefaults()
- sets default db, injectors, middlewares, store, rewriters, configmockserver.setDefaultData()
- sets default injectors, middlewares, store, configmockserver.setDefaultDb()
- sets default dbmockserver.setDefaultInjectors()
- sets default injectorsmockserver.setDefaultMiddlewares()
- sets default middlewaresmockserver.setDefaultRewriters()
- sets default rewritersmockserver.setDefaultStore()
- sets default storemockserver.setDefaultConfig()
- sets default configadded more methods
mockserver.clearServerAddress()
- sets current port, address, listeningTo, server to undefined
mockserver.setExpressApp()
- create a new express app to the MockServer instance.Changelog
v11.2.0
log
in CLI param and Config
- Helps to added setter logs in console.reply
as alias for send
in create router config methodconst resources = mockServer.resources();
resources.create('/post').send({ name: 'foo', id: 1 });
resources.create('/comment').reply({ name: 'foo', id: 1 }); // reply is alias for send
app.use(resources.router);
Changelog
v11.1.0
headers
in routeConfigs. Now we can add custom response headers in routeConfig
For Example: db.json
{
"/route": {
"_config": true,
"mock": "My Response",
"headers": { "Content-Type": "test/plain" }
}
}
send()
, status()
, headers()
in mockServer.resources().create()
method.
For Example:
const resources = mockServer.resources();
resources.create('/new/route/1').send('My Response').status(200).done();
resources
.create('/new/route/2')
.send('https://jsonplaceholder.typicode.com/posts') // will set to `mock` or `fetch` based on dbMode
.headers({ 'Content-Type': 'application/json' })
.headers('Content-Length', 123)
.done();
app.use(resources.router);
Changelog
v11.0.0
renamed - _globals
to globals
in middlewares.
removed - mockServer.setDb
method. Use mockServer.rewriters
to set rewriters.
removed - mockServer.setRewriters
method. Use mockServer.resources
to set Db.
updated - mockServer.resources
will now return { create, router}
.
updated - res.locals.getDb
accepts a routePath as a param.
Type:
getDb(routePath?: string | string[]): ValidTypes.RouteConfig | ValidTypes.Db;
added - mockServer.resources().create
. Helps to create new route with config and mocks.
For Example: server.js
const resources = mockServer.resources();
resources
.create('/new/route', (req, res, next) => {
next();
})
.mock('My Response')
.delay(2000)
.done();
app.use(resources.router);