|
|
@ -78,7 +78,7 @@ function mime (mimeTypes) { |
|
|
|
|
|
|
|
function mockResponses (route, targets) { |
|
|
|
targets = arrayify(targets) |
|
|
|
debug('mock route: %s, targets: %s', route, targets.length); |
|
|
|
debug('mock route: %s, targets: %s', route, targets.length) |
|
|
|
const pathRe = pathToRegexp(route) |
|
|
|
|
|
|
|
return function mockResponse (ctx, next) { |
|
|
@ -103,13 +103,12 @@ function mockResponses (route, targets) { |
|
|
|
if (target) { |
|
|
|
if (t.isFunction(target.response)) { |
|
|
|
const pathMatches = ctx.path.match(pathRe).slice(1) |
|
|
|
return target.response.apply(null, [ctx].concat(pathMatches)) |
|
|
|
return target.response.apply(null, [ctx].concat(pathMatches)) |
|
|
|
} else if (t.isPlainObject(target.response)) { |
|
|
|
Object.assign(ctx.response, target.response) |
|
|
|
} else { |
|
|
|
throw new Error(`Invalid response: ${JSON.stringify(target.response)}`) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
return next() |
|
|
|