-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
117 lines (88 loc) · 2.22 KB
/
test.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import test from 'tape'
import logger from './index.js'
test((t) => {
const buf = []
const log = logger('myservice', (e) => buf.push(e))
log('level 1')
const sublog = log.create('downstream')
sublog('level 2 A')
sublog('level 2 B')
t.deepEqual(buf, [
['myservice', 'level 1'],
['myservice', 'downstream', 'level 2 A'],
['myservice', 'downstream', 'level 2 B'],
])
t.end()
})
test('Queue namespaced data until `out` is set', (t) => {
const log = logger('myservice')
log('level 1 A')
const sublog = log.create('downstream')
sublog('level 2 A')
sublog('level 2 B')
const buf = []
log.out((e) => buf.push(e))
log('level 1 B')
sublog('level 2 C')
sublog.create('origin')('level 3 A')
t.deepEqual(buf, [
['myservice', 'level 1 A'],
['myservice', 'downstream', 'level 2 A'],
['myservice', 'downstream', 'level 2 B'],
['myservice', 'level 1 B'],
['myservice', 'downstream', 'level 2 C'],
['myservice', 'downstream', 'origin', 'level 3 A'],
])
t.end()
})
test('Rerouting `out`', (t) => {
const log = logger('myservice')
log('level 1 A')
const sublog = log.create('downstream')
sublog('level 2 A')
const buf = []
log.out((e) => buf.push(e))
log('level 1 B')
const buf2 = []
log.out((e) => buf2.push(e))
log('level 1 C')
sublog('level 2 B')
log('level 1 D')
t.deepEqual(buf, [
['myservice', 'level 1 A'],
['myservice', 'downstream', 'level 2 A'],
['myservice', 'level 1 B'],
])
t.deepEqual(buf2, [
['myservice', 'level 1 C'],
['myservice', 'downstream', 'level 2 B'],
['myservice', 'level 1 D'],
])
t.end()
})
test('Queue data while `out` is detached', (t) => {
const log = logger('myservice')
log('level 1 A')
const sublog = log.create('downstream')
sublog('level 2 A')
sublog('level 2 B')
const buf = []
log.out((e) => buf.push(e))
log.out(null)
log('level 1 B')
sublog('level 2 C')
sublog.create('origin')('level 3 A')
const buf2 = []
log.out((e) => buf2.push(e))
t.deepEqual(buf, [
['myservice', 'level 1 A'],
['myservice', 'downstream', 'level 2 A'],
['myservice', 'downstream', 'level 2 B'],
])
t.deepEqual(buf2, [
['myservice', 'level 1 B'],
['myservice', 'downstream', 'level 2 C'],
['myservice', 'downstream', 'origin', 'level 3 A'],
])
t.end()
})