Skip to content

Commit 0185600

Browse files
committed
Updated test
1 parent aa90001 commit 0185600

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

loggers/morgan/test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict'
2+
3+
const test = require('ava')
4+
const sget = require('simple-get')
5+
const validator = require('is-my-json-valid')
6+
const express = require('express')
7+
const morgan = require('morgan')
8+
const stoppable = require('stoppable')
9+
const split = require('split2')
10+
const ecsFormat = require('./')
11+
12+
const validate = validator(require('../../utils/schema.json'))
13+
14+
test.cb('Should produce valid ecs logs', t => {
15+
t.plan(2)
16+
17+
const stream = split(JSON.parse).on('data', line => {
18+
t.true(validate(line))
19+
})
20+
21+
const app = express()
22+
app.use(morgan(ecsFormat(), { stream }))
23+
app.use('/', (req, res) => {
24+
res.end('ok')
25+
})
26+
27+
const server = stoppable(app.listen(0, () => {
28+
const body = JSON.stringify({ hello: 'world' })
29+
sget({
30+
method: 'POST',
31+
url: `http://localhost:${server.address().port}?foo=bar`,
32+
body,
33+
headers: {
34+
'user-agent': 'cool-agent',
35+
'content-type': 'application/json',
36+
'content-length': Buffer.byteLength(body)
37+
}
38+
}, (err, res) => {
39+
t.falsy(err)
40+
server.stop()
41+
t.end()
42+
})
43+
}))
44+
})

0 commit comments

Comments
 (0)