logger common test
This commit is contained in:
24
test/test.js
24
test/test.js
@ -3,6 +3,7 @@ const test = require('tape')
|
||||
const request = require('req-then')
|
||||
const localWebServer = require('../')
|
||||
const http = require('http')
|
||||
const PassThrough = require('stream').PassThrough
|
||||
|
||||
test('static', function (t) {
|
||||
t.plan(1)
|
||||
@ -42,3 +43,26 @@ test('serve-index', function (t) {
|
||||
})
|
||||
.then(() => server.close())
|
||||
})
|
||||
|
||||
test('log: common', function (t) {
|
||||
t.plan(1)
|
||||
const stream = PassThrough()
|
||||
|
||||
stream.on('readable', () => {
|
||||
let chunk = stream.read()
|
||||
if (chunk) t.ok(/GET/.test(chunk.toString()))
|
||||
})
|
||||
|
||||
const app = localWebServer({
|
||||
logger: {
|
||||
format: 'common',
|
||||
options: {
|
||||
stream: stream
|
||||
}
|
||||
}
|
||||
})
|
||||
const server = http.createServer(app.callback())
|
||||
server.listen(8100)
|
||||
request('http://localhost:8100/')
|
||||
.then(() => server.close())
|
||||
})
|
||||
|
Reference in New Issue
Block a user