|
@ -78,7 +78,7 @@ function mime (mimeTypes) { |
|
|
|
|
|
|
|
|
function mockResponses (route, targets) { |
|
|
function mockResponses (route, targets) { |
|
|
targets = arrayify(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) |
|
|
const pathRe = pathToRegexp(route) |
|
|
|
|
|
|
|
|
return function mockResponse (ctx, next) { |
|
|
return function mockResponse (ctx, next) { |
|
@ -103,13 +103,12 @@ function mockResponses (route, targets) { |
|
|
if (target) { |
|
|
if (target) { |
|
|
if (t.isFunction(target.response)) { |
|
|
if (t.isFunction(target.response)) { |
|
|
const pathMatches = ctx.path.match(pathRe).slice(1) |
|
|
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)) { |
|
|
} else if (t.isPlainObject(target.response)) { |
|
|
Object.assign(ctx.response, target.response) |
|
|
Object.assign(ctx.response, target.response) |
|
|
} else { |
|
|
} else { |
|
|
throw new Error(`Invalid response: ${JSON.stringify(target.response)}`) |
|
|
throw new Error(`Invalid response: ${JSON.stringify(target.response)}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
return next() |
|
|
return next() |
|
|