mocks v2
This commit is contained in:
@ -44,7 +44,8 @@ function localWebServer (options) {
|
||||
mime: {},
|
||||
forbid: [],
|
||||
rewrite: [],
|
||||
verbose: false
|
||||
verbose: false,
|
||||
mocks: []
|
||||
}, options)
|
||||
|
||||
if (options.verbose) {
|
||||
@ -106,7 +107,7 @@ function localWebServer (options) {
|
||||
app.use(mw.blacklist(options.forbid))
|
||||
}
|
||||
|
||||
/* Cache */
|
||||
/* cache */
|
||||
if (!options['no-cache']) {
|
||||
const conditional = require('koa-conditional-get')
|
||||
const etag = require('koa-etag')
|
||||
@ -144,7 +145,21 @@ function localWebServer (options) {
|
||||
}
|
||||
|
||||
/* Mock Responses */
|
||||
app.use(mw.mockResponses({ root: options.static.root }))
|
||||
options.mocks.forEach(mock => {
|
||||
if (mock.module) {
|
||||
mock.targets = require(path.join(options.static.root, mock.module))
|
||||
}
|
||||
|
||||
if (mock.targets) {
|
||||
app.use(mw.mockResponses(mock.route, mock.targets))
|
||||
} else if (mock.response) {
|
||||
mock.target = {
|
||||
request: mock.request,
|
||||
response: mock.response
|
||||
}
|
||||
app.use(mw.mockResponses(mock.route, mock.target))
|
||||
}
|
||||
})
|
||||
|
||||
/* serve static files */
|
||||
if (options.static.root) {
|
||||
|
Reference in New Issue
Block a user