fix tests
This commit is contained in:
@ -2,4 +2,4 @@
|
||||
'use strict'
|
||||
const LocalWebServer = require('../')
|
||||
const ws = new LocalWebServer()
|
||||
const server = ws.getServer()
|
||||
ws.getServer()
|
||||
|
@ -61,7 +61,7 @@ class LocalWebServer {
|
||||
|
||||
let options = {}
|
||||
const allOptionDefinitions = cli.optionDefinitions.concat(middlewareOptionDefinitions)
|
||||
if (!initOptions.ignoreCli) {
|
||||
if (!initOptions.testMode) {
|
||||
try {
|
||||
options = commandLineArgs(allOptionDefinitions)
|
||||
} catch (err) {
|
||||
@ -90,16 +90,12 @@ class LocalWebServer {
|
||||
*/
|
||||
this.options = options
|
||||
|
||||
if (options.verbose) {
|
||||
stackModules
|
||||
.filter(mw => mw.on)
|
||||
.forEach(mw => mw.on('verbose', onVerbose))
|
||||
}
|
||||
if (options.debug) {
|
||||
stackModules
|
||||
.filter(mw => mw.on)
|
||||
.forEach(mw => mw.on('debug', onDebug))
|
||||
}
|
||||
stackModules
|
||||
.filter(mw => mw.on)
|
||||
.forEach(mw => {
|
||||
mw.on('verbose', this.onVerbose.bind(this))
|
||||
mw.on('debug', this.onDebug.bind(this))
|
||||
})
|
||||
|
||||
/* --config */
|
||||
if (options.config) {
|
||||
@ -168,12 +164,16 @@ class LocalWebServer {
|
||||
|
||||
const tableLayout = require('table-layout')
|
||||
|
||||
server.listen(options.port, function () {
|
||||
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))
|
||||
})
|
||||
server
|
||||
.listen(options.port)
|
||||
.on('listening', function () {
|
||||
if (options.testMode) return
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@
|
||||
"jsdoc-to-markdown": "^1.3.6",
|
||||
"koa-cache-control": "^1.0.0",
|
||||
"koa-livereload": "~0.2.0",
|
||||
"req-then": "~0.2.4",
|
||||
"req-then": "~0.3.3",
|
||||
"tape": "^4.6.0"
|
||||
}
|
||||
}
|
||||
|
18
test/test.js
18
test/test.js
@ -10,13 +10,16 @@ test('stack', function (t) {
|
||||
const ws = new LocalWebServer({
|
||||
stack: [ path.resolve(__dirname, 'test-middleware.js') ],
|
||||
port: 8100,
|
||||
ignoreCli: true
|
||||
testMode: true
|
||||
})
|
||||
const server = ws.getServer(() => {
|
||||
return request('http://localhost:8100/')
|
||||
.then(c.checkResponse(t, 200, /1234512345/))
|
||||
.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') ],
|
||||
https: true,
|
||||
port: 8100,
|
||||
ignoreCli: true
|
||||
testMode: true
|
||||
})
|
||||
const url = require('url')
|
||||
const reqOptions = url.parse('https://localhost:8100/')
|
||||
reqOptions.rejectUnauthorized = false
|
||||
const server = ws.getServer(() => {
|
||||
return request('https://localhost:8100/')
|
||||
return request(reqOptions)
|
||||
.then(c.checkResponse(t, 200, /1234512345/))
|
||||
.then(server.close.bind(server))
|
||||
.catch(err => {
|
||||
t.fail(err.message)
|
||||
server.close()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user