fix tests
This commit is contained in:
@ -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()
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
test/test.js
18
test/test.js
@ -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()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user