fix tests

This commit is contained in:
Lloyd Brookes
2016-07-14 23:00:46 +01:00
parent aca27a275c
commit 60e3608d62
4 changed files with 33 additions and 23 deletions

View File

@ -2,4 +2,4 @@
'use strict' 'use strict'
const LocalWebServer = require('../') const LocalWebServer = require('../')
const ws = new LocalWebServer() const ws = new LocalWebServer()
const server = ws.getServer() ws.getServer()

View File

@ -61,7 +61,7 @@ class LocalWebServer {
let options = {} let options = {}
const allOptionDefinitions = cli.optionDefinitions.concat(middlewareOptionDefinitions) const allOptionDefinitions = cli.optionDefinitions.concat(middlewareOptionDefinitions)
if (!initOptions.ignoreCli) { if (!initOptions.testMode) {
try { try {
options = commandLineArgs(allOptionDefinitions) options = commandLineArgs(allOptionDefinitions)
} catch (err) { } catch (err) {
@ -90,16 +90,12 @@ class LocalWebServer {
*/ */
this.options = options this.options = options
if (options.verbose) { stackModules
stackModules .filter(mw => mw.on)
.filter(mw => mw.on) .forEach(mw => {
.forEach(mw => mw.on('verbose', onVerbose)) mw.on('verbose', this.onVerbose.bind(this))
} mw.on('debug', this.onDebug.bind(this))
if (options.debug) { })
stackModules
.filter(mw => mw.on)
.forEach(mw => mw.on('debug', onDebug))
}
/* --config */ /* --config */
if (options.config) { if (options.config) {
@ -168,12 +164,16 @@ class LocalWebServer {
const tableLayout = require('table-layout') const tableLayout = require('table-layout')
server.listen(options.port, function () { server
const ipList = getIPList() .listen(options.port)
.map(iface => `[underline]{${server.isHttps ? 'https' : 'http'}://${iface.address}:${options.port}}`) .on('listening', function () {
.join(', ') if (options.testMode) return
console.error(ansi.format('Serving at', 'bold'), ansi.format(ipList)) const ipList = getIPList()
}) .map(iface => `[underline]{${server.isHttps ? 'https' : 'http'}://${iface.address}:${options.port}}`)
.join(', ')
console.error(ansi.format('Serving at', 'bold'), ansi.format(ipList))
})
.on('listening', onListening)
return server return server
} }

View File

@ -56,7 +56,7 @@
"jsdoc-to-markdown": "^1.3.6", "jsdoc-to-markdown": "^1.3.6",
"koa-cache-control": "^1.0.0", "koa-cache-control": "^1.0.0",
"koa-livereload": "~0.2.0", "koa-livereload": "~0.2.0",
"req-then": "~0.2.4", "req-then": "~0.3.3",
"tape": "^4.6.0" "tape": "^4.6.0"
} }
} }

View File

@ -10,13 +10,16 @@ test('stack', function (t) {
const ws = new LocalWebServer({ const ws = new LocalWebServer({
stack: [ path.resolve(__dirname, 'test-middleware.js') ], stack: [ path.resolve(__dirname, 'test-middleware.js') ],
port: 8100, port: 8100,
ignoreCli: true testMode: true
}) })
const server = ws.getServer(() => { const server = ws.getServer(() => {
return request('http://localhost:8100/') return request('http://localhost:8100/')
.then(c.checkResponse(t, 200, /1234512345/)) .then(c.checkResponse(t, 200, /1234512345/))
.then(server.close.bind(server)) .then(server.close.bind(server))
.catch(c.fail(t)) .catch(err => {
t.fail(err.message)
server.close()
})
}) })
}) })
@ -26,11 +29,18 @@ test('https', function (t) {
stack: [ path.resolve(__dirname, 'test-middleware.js') ], stack: [ path.resolve(__dirname, 'test-middleware.js') ],
https: true, https: true,
port: 8100, port: 8100,
ignoreCli: true testMode: true
}) })
const url = require('url')
const reqOptions = url.parse('https://localhost:8100/')
reqOptions.rejectUnauthorized = false
const server = ws.getServer(() => { const server = ws.getServer(() => {
return request('https://localhost:8100/') return request(reqOptions)
.then(c.checkResponse(t, 200, /1234512345/)) .then(c.checkResponse(t, 200, /1234512345/))
.then(server.close.bind(server)) .then(server.close.bind(server))
.catch(err => {
t.fail(err.message)
server.close()
})
}) })
}) })