-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
57 lines (51 loc) · 1.36 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
import test from 'ava'
import sinon from 'sinon'
import { Readable } from 'stream'
import createTransport, { logProcessorFactory } from './index.js'
test('build transport', async t => {
const logger = sinon.spy()
const createLogger = sinon.stub().returns(logger)
const build = sinon.spy()
const logProcessor = () => {}
const logProcessorFactorySpy = sinon.stub().returns(logProcessor)
const loggerOpts = {
serverUrl: 'http://localhost:5341'
}
createTransport({
loggerOpts,
messageTemplate: '{message}',
createLogger,
build,
logProcessorFactory: logProcessorFactorySpy
})
t.true(createLogger.calledOnceWith(loggerOpts))
t.true(logProcessorFactorySpy.calledOnceWith(logger, '{message}'))
t.true(build.calledOnceWith(logProcessor))
})
test('logProcessorFactory', async t => {
const logger = {
emit: sinon.spy()
}
const time = 1651855435039
const timestamp = new Date(1651855435039)
const message = 'a log message'
const messageTemplate = '{message}'
const stack = {}
const logProcessor = logProcessorFactory(logger, messageTemplate)
const source = Readable.from([{
time,
level: 30,
msg: message,
stack
}])
await logProcessor(source)
t.true(logger.emit.calledOnceWith({
timestamp,
level: 'INFO',
messageTemplate,
properties: {
message
},
exception: stack
}))
})