This repository has been archived by the owner on Aug 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (66 loc) · 1.7 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict'
// **Github:** https://github.com/toajs/toa-morgan
//
// modified from https://github.com/expressjs/morgan/blob/master/test/morgan.js
// **License:** MIT
const Toa = require('toa')
const tman = require('tman')
const assert = require('assert')
const request = require('supertest')
const logging = require('..')
tman.suite('toa-logging', function () {
tman.it('default logging', function * () {
let app = new Toa()
let res = null
app.use(logging({
consume: function (log) {
assert.ok(log.start > 0)
assert.ok(log.time >= 0)
assert.ok(log.ip)
assert.ok(log.method)
assert.ok(log.url)
assert.ok(log.protocol)
assert.ok(log.userAgent)
res = log
}
}))
app.use(function () {
this.body = 'ok'
})
yield request(app.listen())
.get('/')
.expect(200)
assert.ok(res instanceof logging.Log)
assert.ok(res.method)
})
tman.it('custom logging', function * () {
let app = new Toa()
let res = null
app.use(logging({
init: function (log) {
assert.ok(log instanceof logging.Log)
log.test = true
},
consume: function (log) {
assert.ok(log instanceof logging.Log)
assert.ok(log.start > 0)
assert.ok(log.time >= 0)
assert.ok(log.ip)
assert.ok(log.method)
assert.ok(log.url)
assert.ok(log.protocol)
assert.ok(log.userAgent)
assert.ok(log.test === true)
res = log
}
}))
app.use(function () {
this.body = 'ok'
})
yield request(app.listen())
.get('/')
.expect(200)
assert.ok(res instanceof logging.Log)
assert.ok(res.test === true)
})
})