pino-testkit 10.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nojekyll +0 -0
- package/.prettierignore +1 -0
- package/CNAME +1 -0
- package/CONTRIBUTING.md +30 -0
- package/LICENSE +21 -0
- package/README.md +175 -0
- package/SECURITY.md +87 -0
- package/benchmarks/basic.bench.js +95 -0
- package/benchmarks/child-child.bench.js +52 -0
- package/benchmarks/child-creation.bench.js +73 -0
- package/benchmarks/child.bench.js +62 -0
- package/benchmarks/deep-object.bench.js +88 -0
- package/benchmarks/formatters.bench.js +50 -0
- package/benchmarks/internal/custom-levels.js +67 -0
- package/benchmarks/internal/just-pino-heavy.bench.js +76 -0
- package/benchmarks/internal/just-pino.bench.js +182 -0
- package/benchmarks/internal/parent-vs-child.bench.js +75 -0
- package/benchmarks/internal/redact.bench.js +86 -0
- package/benchmarks/long-string.bench.js +81 -0
- package/benchmarks/multi-arg.bench.js +193 -0
- package/benchmarks/multistream.js +98 -0
- package/benchmarks/object.bench.js +82 -0
- package/benchmarks/utils/generate-benchmark-doc.js +36 -0
- package/benchmarks/utils/runbench.js +138 -0
- package/benchmarks/utils/wrap-log-level.js +55 -0
- package/bin.js +6 -0
- package/browser.js +547 -0
- package/build/sync-version.js +25 -0
- package/docs/api.md +1593 -0
- package/docs/asynchronous.md +40 -0
- package/docs/benchmarks.md +55 -0
- package/docs/browser.md +278 -0
- package/docs/bundling.md +40 -0
- package/docs/child-loggers.md +95 -0
- package/docs/diagnostics.md +16 -0
- package/docs/ecosystem.md +86 -0
- package/docs/help.md +345 -0
- package/docs/lts.md +64 -0
- package/docs/pretty.md +35 -0
- package/docs/redaction.md +135 -0
- package/docs/transports.md +1376 -0
- package/docs/web.md +309 -0
- package/eslint.config.js +28 -0
- package/examples/basic.js +43 -0
- package/examples/transport.js +68 -0
- package/favicon.ico +0 -0
- package/file.js +12 -0
- package/inc-version.sh +42 -0
- package/index.html +55 -0
- package/lib/caller.js +30 -0
- package/lib/constants.js +28 -0
- package/lib/contract.js +8 -0
- package/lib/deprecations.js +8 -0
- package/lib/levels.js +241 -0
- package/lib/meta.js +3 -0
- package/lib/multistream.js +203 -0
- package/lib/proto.js +256 -0
- package/lib/redaction.js +114 -0
- package/lib/symbols.js +74 -0
- package/lib/time.js +39 -0
- package/lib/tools.js +427 -0
- package/lib/transport-stream.js +56 -0
- package/lib/transport.js +289 -0
- package/lib/worker.js +194 -0
- package/package.json +119 -0
- package/pino.d.ts +908 -0
- package/pino.js +240 -0
- package/test/basic.test.js +886 -0
- package/test/broken-pipe.test.js +59 -0
- package/test/browser-child.test.js +132 -0
- package/test/browser-disabled.test.js +87 -0
- package/test/browser-early-console-freeze.test.js +12 -0
- package/test/browser-is-level-enabled.test.js +101 -0
- package/test/browser-levels.test.js +241 -0
- package/test/browser-serializers.test.js +352 -0
- package/test/browser-timestamp.test.js +88 -0
- package/test/browser-transmit.test.js +417 -0
- package/test/browser.test.js +698 -0
- package/test/complex-objects.test.js +36 -0
- package/test/crlf.test.js +34 -0
- package/test/custom-levels.test.js +267 -0
- package/test/diagnostics.test.js +107 -0
- package/test/error-key.test.js +37 -0
- package/test/error.test.js +403 -0
- package/test/escaping.test.js +93 -0
- package/test/esm/esm.mjs +14 -0
- package/test/esm/index.test.js +21 -0
- package/test/esm/named-exports.mjs +29 -0
- package/test/exit.test.js +79 -0
- package/test/fixtures/broken-pipe/basic.js +9 -0
- package/test/fixtures/broken-pipe/destination.js +10 -0
- package/test/fixtures/broken-pipe/syncfalse.js +12 -0
- package/test/fixtures/console-transport.js +13 -0
- package/test/fixtures/crashing-transport.js +13 -0
- package/test/fixtures/default-exit.js +8 -0
- package/test/fixtures/destination-exit.js +8 -0
- package/test/fixtures/eval/index.js +13 -0
- package/test/fixtures/eval/node_modules/14-files.js +3 -0
- package/test/fixtures/eval/node_modules/2-files.js +3 -0
- package/test/fixtures/eval/node_modules/file1.js +5 -0
- package/test/fixtures/eval/node_modules/file10.js +5 -0
- package/test/fixtures/eval/node_modules/file11.js +5 -0
- package/test/fixtures/eval/node_modules/file12.js +5 -0
- package/test/fixtures/eval/node_modules/file13.js +5 -0
- package/test/fixtures/eval/node_modules/file14.js +11 -0
- package/test/fixtures/eval/node_modules/file2.js +5 -0
- package/test/fixtures/eval/node_modules/file3.js +5 -0
- package/test/fixtures/eval/node_modules/file4.js +5 -0
- package/test/fixtures/eval/node_modules/file5.js +5 -0
- package/test/fixtures/eval/node_modules/file6.js +5 -0
- package/test/fixtures/eval/node_modules/file7.js +5 -0
- package/test/fixtures/eval/node_modules/file8.js +5 -0
- package/test/fixtures/eval/node_modules/file9.js +5 -0
- package/test/fixtures/noop-transport.js +10 -0
- package/test/fixtures/pretty/null-prototype.js +8 -0
- package/test/fixtures/stdout-hack-protection.js +11 -0
- package/test/fixtures/syncfalse-child.js +6 -0
- package/test/fixtures/syncfalse-exit.js +9 -0
- package/test/fixtures/syncfalse-flush-exit.js +10 -0
- package/test/fixtures/syncfalse.js +6 -0
- package/test/fixtures/syntax-error-esm.mjs +2 -0
- package/test/fixtures/to-file-transport-with-transform.js +20 -0
- package/test/fixtures/to-file-transport.js +13 -0
- package/test/fixtures/to-file-transport.mjs +8 -0
- package/test/fixtures/transport/index.js +12 -0
- package/test/fixtures/transport/package.json +5 -0
- package/test/fixtures/transport-exit-immediately-with-async-dest.js +16 -0
- package/test/fixtures/transport-exit-immediately.js +11 -0
- package/test/fixtures/transport-exit-on-ready.js +12 -0
- package/test/fixtures/transport-invalid-node-options.js +26 -0
- package/test/fixtures/transport-main.js +9 -0
- package/test/fixtures/transport-many-lines.js +29 -0
- package/test/fixtures/transport-preload-main.mjs +13 -0
- package/test/fixtures/transport-preload.mjs +13 -0
- package/test/fixtures/transport-string-stdout.js +9 -0
- package/test/fixtures/transport-transform.js +21 -0
- package/test/fixtures/transport-uses-pino-config.js +33 -0
- package/test/fixtures/transport-with-on-exit.js +12 -0
- package/test/fixtures/transport-worker-data.js +19 -0
- package/test/fixtures/transport-worker-name.js +24 -0
- package/test/fixtures/transport-worker.js +15 -0
- package/test/fixtures/transport-wrong-export-type.js +3 -0
- package/test/fixtures/ts/to-file-transport-native.mts +15 -0
- package/test/fixtures/ts/to-file-transport-with-transform.ts +18 -0
- package/test/fixtures/ts/to-file-transport.ts +11 -0
- package/test/fixtures/ts/transpile.cjs +36 -0
- package/test/fixtures/ts/transport-exit-immediately-with-async-dest.ts +15 -0
- package/test/fixtures/ts/transport-exit-immediately.ts +10 -0
- package/test/fixtures/ts/transport-exit-on-ready.ts +11 -0
- package/test/fixtures/ts/transport-main.ts +8 -0
- package/test/fixtures/ts/transport-string-stdout.ts +8 -0
- package/test/fixtures/ts/transport-worker.ts +14 -0
- package/test/formatters.test.js +364 -0
- package/test/helper.d.ts +4 -0
- package/test/helper.js +155 -0
- package/test/hooks.test.js +114 -0
- package/test/http.test.js +214 -0
- package/test/internals/version.test.js +17 -0
- package/test/is-level-enabled.test.js +179 -0
- package/test/jest/basic.spec.js +10 -0
- package/test/levels.test.js +810 -0
- package/test/metadata.test.js +120 -0
- package/test/mixin-merge-strategy.test.js +57 -0
- package/test/mixin.test.js +241 -0
- package/test/multistream.test.js +729 -0
- package/test/redact.test.js +893 -0
- package/test/serializers.test.js +257 -0
- package/test/stdout-protection.test.js +41 -0
- package/test/syncfalse.test.js +186 -0
- package/test/timestamp-nano.test.js +37 -0
- package/test/timestamp.test.js +124 -0
- package/test/transport/big.test.js +42 -0
- package/test/transport/bundlers-support.test.js +99 -0
- package/test/transport/caller.test.js +24 -0
- package/test/transport/core.test.js +733 -0
- package/test/transport/core.transpiled.test.ts +114 -0
- package/test/transport/crash.test.js +36 -0
- package/test/transport/module-link.test.js +241 -0
- package/test/transport/native-type-stripping.test.mjs +151 -0
- package/test/transport/node-options.test.js +116 -0
- package/test/transport/pipeline.test.js +137 -0
- package/test/transport/preload.test.js +54 -0
- package/test/transport/repl.test.js +15 -0
- package/test/transport/sync-false.test.js +67 -0
- package/test/transport/sync-true.test.js +57 -0
- package/test/transport/targets.test.js +48 -0
- package/test/transport/uses-pino-config.test.js +166 -0
- package/test/transport-stream.test.js +40 -0
- package/test/types/pino-import.test-d.cts +30 -0
- package/test/types/pino-multistream.test-d.ts +28 -0
- package/test/types/pino-top-export.test-d.ts +34 -0
- package/test/types/pino-transport.test-d.ts +156 -0
- package/test/types/pino-type-only.test-d.ts +75 -0
- package/test/types/pino.test-d.ts +683 -0
- package/test/types/pino.ts +91 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const test = require('node:test')
|
|
4
|
+
const os = require('node:os')
|
|
5
|
+
const tspl = require('@matteo.collina/tspl')
|
|
6
|
+
|
|
7
|
+
const pino = require('../')
|
|
8
|
+
|
|
9
|
+
const { pid } = process
|
|
10
|
+
const hostname = os.hostname()
|
|
11
|
+
|
|
12
|
+
test('metadata works', async (t) => {
|
|
13
|
+
const plan = tspl(t, { plan: 7 })
|
|
14
|
+
const now = Date.now()
|
|
15
|
+
const instance = pino({}, {
|
|
16
|
+
[Symbol.for('pino.metadata')]: true,
|
|
17
|
+
write (chunk) {
|
|
18
|
+
plan.equal(instance, this.lastLogger)
|
|
19
|
+
plan.equal(30, this.lastLevel)
|
|
20
|
+
plan.equal('a msg', this.lastMsg)
|
|
21
|
+
plan.ok(Number(this.lastTime) >= now)
|
|
22
|
+
plan.deepEqual(this.lastObj, { hello: 'world' })
|
|
23
|
+
const result = JSON.parse(chunk)
|
|
24
|
+
plan.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
25
|
+
delete result.time
|
|
26
|
+
plan.deepEqual(result, {
|
|
27
|
+
pid,
|
|
28
|
+
hostname,
|
|
29
|
+
level: 30,
|
|
30
|
+
hello: 'world',
|
|
31
|
+
msg: 'a msg'
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
instance.info({ hello: 'world' }, 'a msg')
|
|
37
|
+
|
|
38
|
+
await plan
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('child loggers works', async (t) => {
|
|
42
|
+
const plan = tspl(t, { plan: 6 })
|
|
43
|
+
const instance = pino({}, {
|
|
44
|
+
[Symbol.for('pino.metadata')]: true,
|
|
45
|
+
write (chunk) {
|
|
46
|
+
plan.equal(child, this.lastLogger)
|
|
47
|
+
plan.equal(30, this.lastLevel)
|
|
48
|
+
plan.equal('a msg', this.lastMsg)
|
|
49
|
+
plan.deepEqual(this.lastObj, { from: 'child' })
|
|
50
|
+
const result = JSON.parse(chunk)
|
|
51
|
+
plan.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
52
|
+
delete result.time
|
|
53
|
+
plan.deepEqual(result, {
|
|
54
|
+
pid,
|
|
55
|
+
hostname,
|
|
56
|
+
level: 30,
|
|
57
|
+
hello: 'world',
|
|
58
|
+
from: 'child',
|
|
59
|
+
msg: 'a msg'
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const child = instance.child({ hello: 'world' })
|
|
65
|
+
child.info({ from: 'child' }, 'a msg')
|
|
66
|
+
|
|
67
|
+
await plan
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('without object', async (t) => {
|
|
71
|
+
const plan = tspl(t, { plan: 6 })
|
|
72
|
+
const instance = pino({}, {
|
|
73
|
+
[Symbol.for('pino.metadata')]: true,
|
|
74
|
+
write (chunk) {
|
|
75
|
+
plan.equal(instance, this.lastLogger)
|
|
76
|
+
plan.equal(30, this.lastLevel)
|
|
77
|
+
plan.equal('a msg', this.lastMsg)
|
|
78
|
+
plan.deepEqual({ }, this.lastObj)
|
|
79
|
+
const result = JSON.parse(chunk)
|
|
80
|
+
plan.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
81
|
+
delete result.time
|
|
82
|
+
plan.deepEqual(result, {
|
|
83
|
+
pid,
|
|
84
|
+
hostname,
|
|
85
|
+
level: 30,
|
|
86
|
+
msg: 'a msg'
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
instance.info('a msg')
|
|
92
|
+
|
|
93
|
+
await plan
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('without msg', async (t) => {
|
|
97
|
+
const plan = tspl(t, { plan: 6 })
|
|
98
|
+
const instance = pino({}, {
|
|
99
|
+
[Symbol.for('pino.metadata')]: true,
|
|
100
|
+
write (chunk) {
|
|
101
|
+
plan.equal(instance, this.lastLogger)
|
|
102
|
+
plan.equal(30, this.lastLevel)
|
|
103
|
+
plan.equal(undefined, this.lastMsg)
|
|
104
|
+
plan.deepEqual({ hello: 'world' }, this.lastObj)
|
|
105
|
+
const result = JSON.parse(chunk)
|
|
106
|
+
plan.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
107
|
+
delete result.time
|
|
108
|
+
plan.deepEqual(result, {
|
|
109
|
+
pid,
|
|
110
|
+
hostname,
|
|
111
|
+
level: 30,
|
|
112
|
+
hello: 'world'
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
instance.info({ hello: 'world' })
|
|
118
|
+
|
|
119
|
+
await plan
|
|
120
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const test = require('node:test')
|
|
4
|
+
const assert = require('node:assert')
|
|
5
|
+
|
|
6
|
+
const { sink, once } = require('./helper')
|
|
7
|
+
const pino = require('../')
|
|
8
|
+
|
|
9
|
+
const level = 50
|
|
10
|
+
const name = 'error'
|
|
11
|
+
|
|
12
|
+
test('default merge strategy', async () => {
|
|
13
|
+
const stream = sink()
|
|
14
|
+
const instance = pino({
|
|
15
|
+
base: {},
|
|
16
|
+
mixin () {
|
|
17
|
+
return { tag: 'k8s' }
|
|
18
|
+
}
|
|
19
|
+
}, stream)
|
|
20
|
+
instance.level = name
|
|
21
|
+
instance[name]({
|
|
22
|
+
tag: 'local'
|
|
23
|
+
}, 'test')
|
|
24
|
+
const result = await once(stream, 'data')
|
|
25
|
+
assert.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
26
|
+
delete result.time
|
|
27
|
+
assert.deepEqual(result, {
|
|
28
|
+
level,
|
|
29
|
+
msg: 'test',
|
|
30
|
+
tag: 'local'
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('custom merge strategy with mixin priority', async () => {
|
|
35
|
+
const stream = sink()
|
|
36
|
+
const instance = pino({
|
|
37
|
+
base: {},
|
|
38
|
+
mixin () {
|
|
39
|
+
return { tag: 'k8s' }
|
|
40
|
+
},
|
|
41
|
+
mixinMergeStrategy (mergeObject, mixinObject) {
|
|
42
|
+
return Object.assign(mergeObject, mixinObject)
|
|
43
|
+
}
|
|
44
|
+
}, stream)
|
|
45
|
+
instance.level = name
|
|
46
|
+
instance[name]({
|
|
47
|
+
tag: 'local'
|
|
48
|
+
}, 'test')
|
|
49
|
+
const result = await once(stream, 'data')
|
|
50
|
+
assert.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
51
|
+
delete result.time
|
|
52
|
+
assert.deepEqual(result, {
|
|
53
|
+
level,
|
|
54
|
+
msg: 'test',
|
|
55
|
+
tag: 'k8s'
|
|
56
|
+
})
|
|
57
|
+
})
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const test = require('node:test')
|
|
4
|
+
const assert = require('node:assert')
|
|
5
|
+
const os = require('node:os')
|
|
6
|
+
const tspl = require('@matteo.collina/tspl')
|
|
7
|
+
|
|
8
|
+
const { sink, once } = require('./helper')
|
|
9
|
+
const pino = require('../')
|
|
10
|
+
|
|
11
|
+
const { pid } = process
|
|
12
|
+
const hostname = os.hostname()
|
|
13
|
+
const level = 50
|
|
14
|
+
const name = 'error'
|
|
15
|
+
|
|
16
|
+
test('mixin object is included', async () => {
|
|
17
|
+
let n = 0
|
|
18
|
+
const stream = sink()
|
|
19
|
+
const instance = pino({
|
|
20
|
+
mixin () {
|
|
21
|
+
return { hello: ++n }
|
|
22
|
+
}
|
|
23
|
+
}, stream)
|
|
24
|
+
instance.level = name
|
|
25
|
+
instance[name]('test')
|
|
26
|
+
const result = await once(stream, 'data')
|
|
27
|
+
assert.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
28
|
+
delete result.time
|
|
29
|
+
assert.deepEqual(result, {
|
|
30
|
+
pid,
|
|
31
|
+
hostname,
|
|
32
|
+
level,
|
|
33
|
+
msg: 'test',
|
|
34
|
+
hello: 1
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('mixin object is new every time', async (t) => {
|
|
39
|
+
const plan = tspl(t, { plan: 6 })
|
|
40
|
+
|
|
41
|
+
let n = 0
|
|
42
|
+
const stream = sink()
|
|
43
|
+
const instance = pino({
|
|
44
|
+
mixin () {
|
|
45
|
+
return { hello: n }
|
|
46
|
+
}
|
|
47
|
+
}, stream)
|
|
48
|
+
instance.level = name
|
|
49
|
+
|
|
50
|
+
while (++n < 4) {
|
|
51
|
+
const msg = `test #${n}`
|
|
52
|
+
stream.pause()
|
|
53
|
+
instance[name](msg)
|
|
54
|
+
stream.resume()
|
|
55
|
+
const result = await once(stream, 'data')
|
|
56
|
+
plan.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
57
|
+
delete result.time
|
|
58
|
+
plan.deepEqual(result, {
|
|
59
|
+
pid,
|
|
60
|
+
hostname,
|
|
61
|
+
level,
|
|
62
|
+
msg,
|
|
63
|
+
hello: n
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
await plan
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('mixin object is not called if below log level', async () => {
|
|
71
|
+
const stream = sink()
|
|
72
|
+
const instance = pino({
|
|
73
|
+
mixin () {
|
|
74
|
+
throw Error('should not call mixin function')
|
|
75
|
+
}
|
|
76
|
+
}, stream)
|
|
77
|
+
instance.level = 'error'
|
|
78
|
+
instance.info('test')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('mixin object + logged object', async () => {
|
|
82
|
+
const stream = sink()
|
|
83
|
+
const instance = pino({
|
|
84
|
+
mixin () {
|
|
85
|
+
return { foo: 1, bar: 2 }
|
|
86
|
+
}
|
|
87
|
+
}, stream)
|
|
88
|
+
instance.level = name
|
|
89
|
+
instance[name]({ bar: 3, baz: 4 })
|
|
90
|
+
const result = await once(stream, 'data')
|
|
91
|
+
assert.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
92
|
+
delete result.time
|
|
93
|
+
assert.deepEqual(result, {
|
|
94
|
+
pid,
|
|
95
|
+
hostname,
|
|
96
|
+
level,
|
|
97
|
+
foo: 1,
|
|
98
|
+
bar: 3,
|
|
99
|
+
baz: 4
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('mixin not a function', async () => {
|
|
104
|
+
const stream = sink()
|
|
105
|
+
assert.throws(function () {
|
|
106
|
+
pino({ mixin: 'not a function' }, stream)
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test('mixin can use context', async (t) => {
|
|
111
|
+
const plan = tspl(t, { plan: 3 })
|
|
112
|
+
const stream = sink()
|
|
113
|
+
const instance = pino({
|
|
114
|
+
mixin (context) {
|
|
115
|
+
plan.ok(context !== null, 'context should be defined')
|
|
116
|
+
plan.ok(context !== undefined, 'context should be defined')
|
|
117
|
+
plan.deepEqual(context, {
|
|
118
|
+
message: '123',
|
|
119
|
+
stack: 'stack'
|
|
120
|
+
})
|
|
121
|
+
return Object.assign({
|
|
122
|
+
error: context.message,
|
|
123
|
+
stack: context.stack
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
}, stream)
|
|
127
|
+
instance.level = name
|
|
128
|
+
instance[name]({
|
|
129
|
+
message: '123',
|
|
130
|
+
stack: 'stack'
|
|
131
|
+
}, 'test')
|
|
132
|
+
|
|
133
|
+
await plan
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('mixin works without context', async (t) => {
|
|
137
|
+
const plan = tspl(t, { plan: 3 })
|
|
138
|
+
const stream = sink()
|
|
139
|
+
const instance = pino({
|
|
140
|
+
mixin (context) {
|
|
141
|
+
plan.ok(context !== null, 'context is still defined w/o passing mergeObject')
|
|
142
|
+
plan.ok(context !== undefined, 'context is still defined w/o passing mergeObject')
|
|
143
|
+
plan.deepEqual(context, {})
|
|
144
|
+
return {
|
|
145
|
+
something: true
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}, stream)
|
|
149
|
+
instance.level = name
|
|
150
|
+
instance[name]('test')
|
|
151
|
+
|
|
152
|
+
await plan
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
test('mixin can use level number', async (t) => {
|
|
156
|
+
const plan = tspl(t, { plan: 3 })
|
|
157
|
+
const stream = sink()
|
|
158
|
+
const instance = pino({
|
|
159
|
+
mixin (context, num) {
|
|
160
|
+
plan.ok(num !== null, 'level should be defined')
|
|
161
|
+
plan.ok(num !== undefined, 'level should be defined')
|
|
162
|
+
plan.deepEqual(num, level)
|
|
163
|
+
return Object.assign({
|
|
164
|
+
error: context.message,
|
|
165
|
+
stack: context.stack
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
}, stream)
|
|
169
|
+
instance.level = name
|
|
170
|
+
instance[name]({
|
|
171
|
+
message: '123',
|
|
172
|
+
stack: 'stack'
|
|
173
|
+
}, 'test')
|
|
174
|
+
|
|
175
|
+
await plan
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
test('mixin receives logger as third parameter', async (t) => {
|
|
179
|
+
const plan = tspl(t, { plan: 3 })
|
|
180
|
+
const stream = sink()
|
|
181
|
+
const instance = pino({
|
|
182
|
+
mixin (context, num, logger) {
|
|
183
|
+
plan.ok(logger !== null, 'logger should be defined')
|
|
184
|
+
plan.ok(logger !== undefined, 'logger should be defined')
|
|
185
|
+
plan.deepEqual(logger, instance)
|
|
186
|
+
return { ...context, num }
|
|
187
|
+
}
|
|
188
|
+
}, stream)
|
|
189
|
+
instance.level = name
|
|
190
|
+
instance[name]({
|
|
191
|
+
message: '123'
|
|
192
|
+
}, 'test')
|
|
193
|
+
|
|
194
|
+
await plan
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
test('mixin receives child logger', async (t) => {
|
|
198
|
+
const plan = tspl(t, { plan: 3 })
|
|
199
|
+
const stream = sink()
|
|
200
|
+
let child = null
|
|
201
|
+
const instance = pino({
|
|
202
|
+
mixin (context, num, logger) {
|
|
203
|
+
plan.ok(logger !== null, 'logger should be defined')
|
|
204
|
+
plan.ok(logger !== undefined, 'logger should be defined')
|
|
205
|
+
plan.deepEqual(logger.expected, child.expected)
|
|
206
|
+
return { ...context, num }
|
|
207
|
+
}
|
|
208
|
+
}, stream)
|
|
209
|
+
instance.level = name
|
|
210
|
+
instance.expected = false
|
|
211
|
+
child = instance.child({})
|
|
212
|
+
child.expected = true
|
|
213
|
+
child[name]({
|
|
214
|
+
message: '123'
|
|
215
|
+
}, 'test')
|
|
216
|
+
|
|
217
|
+
await plan
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
test('mixin receives logger even if child exists', async (t) => {
|
|
221
|
+
const plan = tspl(t, { plan: 3 })
|
|
222
|
+
const stream = sink()
|
|
223
|
+
let child = null
|
|
224
|
+
const instance = pino({
|
|
225
|
+
mixin (context, num, logger) {
|
|
226
|
+
plan.ok(logger !== null, 'logger should be defined')
|
|
227
|
+
plan.ok(logger !== undefined, 'logger should be defined')
|
|
228
|
+
plan.deepEqual(logger.expected, instance.expected)
|
|
229
|
+
return { ...context, num }
|
|
230
|
+
}
|
|
231
|
+
}, stream)
|
|
232
|
+
instance.level = name
|
|
233
|
+
instance.expected = false
|
|
234
|
+
child = instance.child({})
|
|
235
|
+
child.expected = true
|
|
236
|
+
instance[name]({
|
|
237
|
+
message: '123'
|
|
238
|
+
}, 'test')
|
|
239
|
+
|
|
240
|
+
await plan
|
|
241
|
+
})
|