update tests

This commit is contained in:
Lloyd Brookes
2016-06-20 01:02:51 +01:00
parent 343399c1d9
commit 71b2f4dcb4
27 changed files with 371 additions and 367 deletions

View File

@ -30,7 +30,7 @@ class LocalWebServer extends MiddlewareStack {
app.on('error', err => {
if (options['log-format']) {
console.error(ansi.format(err.message, 'red'))
console.error(ansi.format(err.stack, 'red'))
}
})

View File

@ -82,8 +82,7 @@ class MiddlewareStack extends Array {
debug('forbid', forbidList.join(', '))
return function blacklist (ctx, next) {
if (forbidList.some(expression => pathToRegexp(expression).test(ctx.path))) {
const http = require('http')
ctx.throw(403, http.STATUS_CODES[403])
ctx.status = 403
} else {
return next()
}
@ -115,7 +114,7 @@ class MiddlewareStack extends Array {
}
/* mime-type overrides */
addMimeType (mime) {
addMimeOverride (mime) {
this.push({
middleware: function (cliOptions) {
mime = cliOptions.mime || mime
@ -229,8 +228,12 @@ class MiddlewareStack extends Array {
debug('SPA', spa)
return _.get('*', function spaMw (ctx, route, next) {
const root = path.resolve(cliOptions.directory || process.cwd())
debug(`SPA request. Route: ${route}, isAsset: ${assetTest.test(route)}`)
return send(ctx, assetTest.test(route) ? route : spa, { root: root }).then(next)
if (ctx.accepts('text/html') && !assetTest.test(route)) {
debug(`SPA request. Route: ${route}, isAsset: ${assetTest.test(route)}`)
return send(ctx, spa, { root: root }).then(next)
} else {
return send(ctx, route, { root: root }).then(next)
}
})
}
}

View File

@ -83,7 +83,7 @@ function mockResponses (route, targets) {
target = targets.find(target => !target.request)
}
debug(`mock path: ${ctx.path} target: ${target.name || 'unnamed'}`)
debug(`mock path: ${ctx.path} target: ${target && target.name || 'unnamed'}`)
if (target) {
if (t.isFunction(target.response)) {