logger common test

This commit is contained in:
Lloyd Brookes
2015-11-10 21:50:56 +00:00
parent c7a6bd15b6
commit 4edc00ca48
4 changed files with 49 additions and 7 deletions

View File

@ -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())
})