vite-plugin-purify 0.0.1-security → 2.3.4
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.
Potentially problematic release.
This version of vite-plugin-purify might be problematic. Click here for more details.
- package/.eslintignore +2 -0
- package/.eslintrc +8 -0
- package/.github/dependabot.yml +13 -0
- package/.github/workflows/bench.yml +61 -0
- package/.github/workflows/ci.yml +88 -0
- package/.github/workflows/lock-threads.yml +30 -0
- package/.github/workflows/target-main.yml +23 -0
- package/.nojekyll +0 -0
- package/.prettierignore +1 -0
- package/.taprc.yaml +8 -0
- package/CNAME +1 -0
- package/CONTRIBUTING.md +30 -0
- package/LICENSE +21 -0
- package/README.md +159 -3
- package/SECURITY.md +68 -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 +484 -0
- package/build/sync-version.js +10 -0
- package/docs/api.md +1487 -0
- package/docs/asynchronous.md +40 -0
- package/docs/benchmarks.md +55 -0
- package/docs/browser.md +227 -0
- package/docs/bundling.md +40 -0
- package/docs/child-loggers.md +95 -0
- package/docs/ecosystem.md +84 -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 +1238 -0
- package/docs/web.md +269 -0
- package/docsify/sidebar.md +26 -0
- package/examples/basic.js +43 -0
- package/examples/transport.js +68 -0
- package/favicon-16x16.png +0 -0
- package/favicon-32x32.png +0 -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/deprecations.js +8 -0
- package/lib/levels.js +241 -0
- package/lib/meta.js +3 -0
- package/lib/multistream.js +188 -0
- package/lib/proto.js +234 -0
- package/lib/redaction.js +118 -0
- package/lib/symbols.js +74 -0
- package/lib/time.js +11 -0
- package/lib/tools.js +394 -0
- package/lib/transport-stream.js +56 -0
- package/lib/transport.js +167 -0
- package/lib/worker.js +194 -0
- package/lib/writer.js +42 -0
- package/logs-buffer - Shortcut.lnk +0 -0
- package/package.json +117 -3
- package/pino-banner.png +0 -0
- package/pino-logo-hire.png +0 -0
- package/pino-tree.png +0 -0
- package/pino.d.ts +889 -0
- package/pino.js +236 -0
- package/pretty-demo.png +0 -0
- package/test/basic.test.js +874 -0
- package/test/broken-pipe.test.js +57 -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-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 +659 -0
- package/test/complex-objects.test.js +34 -0
- package/test/crlf.test.js +32 -0
- package/test/custom-levels.test.js +253 -0
- package/test/error.test.js +398 -0
- package/test/errorKey.test.js +34 -0
- package/test/escaping.test.js +91 -0
- package/test/esm/esm.mjs +12 -0
- package/test/esm/index.test.js +34 -0
- package/test/esm/named-exports.mjs +27 -0
- package/test/exit.test.js +77 -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/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-main.js +9 -0
- package/test/fixtures/transport-many-lines.js +29 -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.js +15 -0
- package/test/fixtures/transport-wrong-export-type.js +3 -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 +355 -0
- package/test/helper.d.ts +4 -0
- package/test/helper.js +128 -0
- package/test/hooks.test.js +118 -0
- package/test/http.test.js +242 -0
- package/test/internals/version.test.js +15 -0
- package/test/is-level-enabled.test.js +185 -0
- package/test/jest/basic.spec.js +10 -0
- package/test/levels.test.js +772 -0
- package/test/metadata.test.js +106 -0
- package/test/mixin-merge-strategy.test.js +55 -0
- package/test/mixin.test.js +218 -0
- package/test/multistream.test.js +673 -0
- package/test/pkg/index.js +46 -0
- package/test/pkg/pkg.config.json +17 -0
- package/test/pkg/pkg.test.js +56 -0
- package/test/redact.test.js +847 -0
- package/test/serializers.test.js +253 -0
- package/test/stdout-protection.test.js +39 -0
- package/test/syncfalse.test.js +188 -0
- package/test/timestamp.test.js +121 -0
- package/test/transport/big.test.js +43 -0
- package/test/transport/bundlers-support.test.js +97 -0
- package/test/transport/caller.test.js +23 -0
- package/test/transport/core.test.js +644 -0
- package/test/transport/core.test.ts +236 -0
- package/test/transport/core.transpiled.test.ts +112 -0
- package/test/transport/module-link.test.js +239 -0
- package/test/transport/pipeline.test.js +135 -0
- package/test/transport/repl.test.js +14 -0
- package/test/transport/syncTrue.test.js +55 -0
- package/test/transport/syncfalse.test.js +68 -0
- package/test/transport/targets.test.js +44 -0
- package/test/transport/uses-pino-config.test.js +167 -0
- package/test/transport-stream.test.js +26 -0
- package/test/types/pino-import.test-d.ts +29 -0
- package/test/types/pino-multistream.test-d.ts +28 -0
- package/test/types/pino-top-export.test-d.ts +35 -0
- package/test/types/pino-transport.test-d.ts +145 -0
- package/test/types/pino-type-only.test-d.ts +64 -0
- package/test/types/pino.test-d.ts +468 -0
- package/test/types/pino.ts +78 -0
- package/tsconfig.json +14 -0
@@ -0,0 +1,874 @@
|
|
1
|
+
'use strict'
|
2
|
+
const os = require('node:os')
|
3
|
+
const { readFileSync } = require('node:fs')
|
4
|
+
const { test } = require('tap')
|
5
|
+
const { sink, check, once, watchFileCreated, file } = require('./helper')
|
6
|
+
const pino = require('../')
|
7
|
+
const { version } = require('../package.json')
|
8
|
+
const { pid } = process
|
9
|
+
const hostname = os.hostname()
|
10
|
+
|
11
|
+
test('pino version is exposed on export', async ({ equal }) => {
|
12
|
+
equal(pino.version, version)
|
13
|
+
})
|
14
|
+
|
15
|
+
test('pino version is exposed on instance', async ({ equal }) => {
|
16
|
+
const instance = pino()
|
17
|
+
equal(instance.version, version)
|
18
|
+
})
|
19
|
+
|
20
|
+
test('child instance exposes pino version', async ({ equal }) => {
|
21
|
+
const child = pino().child({ foo: 'bar' })
|
22
|
+
equal(child.version, version)
|
23
|
+
})
|
24
|
+
|
25
|
+
test('bindings are exposed on every instance', async ({ same }) => {
|
26
|
+
const instance = pino()
|
27
|
+
same(instance.bindings(), {})
|
28
|
+
})
|
29
|
+
|
30
|
+
test('bindings contain the name and the child bindings', async ({ same }) => {
|
31
|
+
const instance = pino({ name: 'basicTest', level: 'info' }).child({ foo: 'bar' }).child({ a: 2 })
|
32
|
+
same(instance.bindings(), { name: 'basicTest', foo: 'bar', a: 2 })
|
33
|
+
})
|
34
|
+
|
35
|
+
test('set bindings on instance', async ({ same }) => {
|
36
|
+
const instance = pino({ name: 'basicTest', level: 'info' })
|
37
|
+
instance.setBindings({ foo: 'bar' })
|
38
|
+
same(instance.bindings(), { name: 'basicTest', foo: 'bar' })
|
39
|
+
})
|
40
|
+
|
41
|
+
test('newly set bindings overwrite old bindings', async ({ same }) => {
|
42
|
+
const instance = pino({ name: 'basicTest', level: 'info', base: { foo: 'bar' } })
|
43
|
+
instance.setBindings({ foo: 'baz' })
|
44
|
+
same(instance.bindings(), { name: 'basicTest', foo: 'baz' })
|
45
|
+
})
|
46
|
+
|
47
|
+
test('set bindings on child instance', async ({ same }) => {
|
48
|
+
const child = pino({ name: 'basicTest', level: 'info' }).child({})
|
49
|
+
child.setBindings({ foo: 'bar' })
|
50
|
+
same(child.bindings(), { name: 'basicTest', foo: 'bar' })
|
51
|
+
})
|
52
|
+
|
53
|
+
test('child should have bindings set by parent', async ({ same }) => {
|
54
|
+
const instance = pino({ name: 'basicTest', level: 'info' })
|
55
|
+
instance.setBindings({ foo: 'bar' })
|
56
|
+
const child = instance.child({})
|
57
|
+
same(child.bindings(), { name: 'basicTest', foo: 'bar' })
|
58
|
+
})
|
59
|
+
|
60
|
+
test('child should not share bindings of parent set after child creation', async ({ same }) => {
|
61
|
+
const instance = pino({ name: 'basicTest', level: 'info' })
|
62
|
+
const child = instance.child({})
|
63
|
+
instance.setBindings({ foo: 'bar' })
|
64
|
+
same(instance.bindings(), { name: 'basicTest', foo: 'bar' })
|
65
|
+
same(child.bindings(), { name: 'basicTest' })
|
66
|
+
})
|
67
|
+
|
68
|
+
function levelTest (name, level) {
|
69
|
+
test(`${name} logs as ${level}`, async ({ equal }) => {
|
70
|
+
const stream = sink()
|
71
|
+
const instance = pino(stream)
|
72
|
+
instance.level = name
|
73
|
+
instance[name]('hello world')
|
74
|
+
check(equal, await once(stream, 'data'), level, 'hello world')
|
75
|
+
})
|
76
|
+
|
77
|
+
test(`passing objects at level ${name}`, async ({ equal, same }) => {
|
78
|
+
const stream = sink()
|
79
|
+
const instance = pino(stream)
|
80
|
+
instance.level = name
|
81
|
+
const obj = { hello: 'world' }
|
82
|
+
instance[name](obj)
|
83
|
+
|
84
|
+
const result = await once(stream, 'data')
|
85
|
+
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
|
86
|
+
equal(result.pid, pid)
|
87
|
+
equal(result.hostname, hostname)
|
88
|
+
equal(result.level, level)
|
89
|
+
equal(result.hello, 'world')
|
90
|
+
same(Object.keys(obj), ['hello'])
|
91
|
+
})
|
92
|
+
|
93
|
+
test(`passing an object and a string at level ${name}`, async ({ equal, same }) => {
|
94
|
+
const stream = sink()
|
95
|
+
const instance = pino(stream)
|
96
|
+
instance.level = name
|
97
|
+
const obj = { hello: 'world' }
|
98
|
+
instance[name](obj, 'a string')
|
99
|
+
const result = await once(stream, 'data')
|
100
|
+
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
|
101
|
+
delete result.time
|
102
|
+
same(result, {
|
103
|
+
pid,
|
104
|
+
hostname,
|
105
|
+
level,
|
106
|
+
msg: 'a string',
|
107
|
+
hello: 'world'
|
108
|
+
})
|
109
|
+
same(Object.keys(obj), ['hello'])
|
110
|
+
})
|
111
|
+
|
112
|
+
test(`passing a undefined and a string at level ${name}`, async ({ equal, same }) => {
|
113
|
+
const stream = sink()
|
114
|
+
const instance = pino(stream)
|
115
|
+
instance.level = name
|
116
|
+
instance[name](undefined, 'a string')
|
117
|
+
const result = await once(stream, 'data')
|
118
|
+
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
|
119
|
+
delete result.time
|
120
|
+
same(result, {
|
121
|
+
pid,
|
122
|
+
hostname,
|
123
|
+
level,
|
124
|
+
msg: 'a string'
|
125
|
+
})
|
126
|
+
})
|
127
|
+
|
128
|
+
test(`overriding object key by string at level ${name}`, async ({ equal, same }) => {
|
129
|
+
const stream = sink()
|
130
|
+
const instance = pino(stream)
|
131
|
+
instance.level = name
|
132
|
+
instance[name]({ hello: 'world', msg: 'object' }, 'string')
|
133
|
+
const result = await once(stream, 'data')
|
134
|
+
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
|
135
|
+
delete result.time
|
136
|
+
same(result, {
|
137
|
+
pid,
|
138
|
+
hostname,
|
139
|
+
level,
|
140
|
+
msg: 'string',
|
141
|
+
hello: 'world'
|
142
|
+
})
|
143
|
+
})
|
144
|
+
|
145
|
+
test(`formatting logs as ${name}`, async ({ equal }) => {
|
146
|
+
const stream = sink()
|
147
|
+
const instance = pino(stream)
|
148
|
+
instance.level = name
|
149
|
+
instance[name]('hello %d', 42)
|
150
|
+
const result = await once(stream, 'data')
|
151
|
+
check(equal, result, level, 'hello 42')
|
152
|
+
})
|
153
|
+
|
154
|
+
test(`formatting a symbol at level ${name}`, async ({ equal }) => {
|
155
|
+
const stream = sink()
|
156
|
+
const instance = pino(stream)
|
157
|
+
instance.level = name
|
158
|
+
|
159
|
+
const sym = Symbol('foo')
|
160
|
+
instance[name]('hello %s', sym)
|
161
|
+
|
162
|
+
const result = await once(stream, 'data')
|
163
|
+
|
164
|
+
check(equal, result, level, 'hello Symbol(foo)')
|
165
|
+
})
|
166
|
+
|
167
|
+
test(`passing error with a serializer at level ${name}`, async ({ equal, same }) => {
|
168
|
+
const stream = sink()
|
169
|
+
const err = new Error('myerror')
|
170
|
+
const instance = pino({
|
171
|
+
serializers: {
|
172
|
+
err: pino.stdSerializers.err
|
173
|
+
}
|
174
|
+
}, stream)
|
175
|
+
instance.level = name
|
176
|
+
instance[name]({ err })
|
177
|
+
const result = await once(stream, 'data')
|
178
|
+
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
|
179
|
+
delete result.time
|
180
|
+
same(result, {
|
181
|
+
pid,
|
182
|
+
hostname,
|
183
|
+
level,
|
184
|
+
err: {
|
185
|
+
type: 'Error',
|
186
|
+
message: err.message,
|
187
|
+
stack: err.stack
|
188
|
+
},
|
189
|
+
msg: err.message
|
190
|
+
})
|
191
|
+
})
|
192
|
+
|
193
|
+
test(`child logger for level ${name}`, async ({ equal, same }) => {
|
194
|
+
const stream = sink()
|
195
|
+
const instance = pino(stream)
|
196
|
+
instance.level = name
|
197
|
+
const child = instance.child({ hello: 'world' })
|
198
|
+
child[name]('hello world')
|
199
|
+
const result = await once(stream, 'data')
|
200
|
+
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
|
201
|
+
delete result.time
|
202
|
+
same(result, {
|
203
|
+
pid,
|
204
|
+
hostname,
|
205
|
+
level,
|
206
|
+
msg: 'hello world',
|
207
|
+
hello: 'world'
|
208
|
+
})
|
209
|
+
})
|
210
|
+
}
|
211
|
+
|
212
|
+
levelTest('fatal', 60)
|
213
|
+
levelTest('error', 50)
|
214
|
+
levelTest('warn', 40)
|
215
|
+
levelTest('info', 30)
|
216
|
+
levelTest('debug', 20)
|
217
|
+
levelTest('trace', 10)
|
218
|
+
|
219
|
+
test('serializers can return undefined to strip field', async ({ equal }) => {
|
220
|
+
const stream = sink()
|
221
|
+
const instance = pino({
|
222
|
+
serializers: {
|
223
|
+
test () { return undefined }
|
224
|
+
}
|
225
|
+
}, stream)
|
226
|
+
|
227
|
+
instance.info({ test: 'sensitive info' })
|
228
|
+
const result = await once(stream, 'data')
|
229
|
+
equal('test' in result, false)
|
230
|
+
})
|
231
|
+
|
232
|
+
test('streams receive a message event with PINO_CONFIG', ({ match, end }) => {
|
233
|
+
const stream = sink()
|
234
|
+
stream.once('message', (message) => {
|
235
|
+
match(message, {
|
236
|
+
code: 'PINO_CONFIG',
|
237
|
+
config: {
|
238
|
+
errorKey: 'err',
|
239
|
+
levels: {
|
240
|
+
labels: {
|
241
|
+
10: 'trace',
|
242
|
+
20: 'debug',
|
243
|
+
30: 'info',
|
244
|
+
40: 'warn',
|
245
|
+
50: 'error',
|
246
|
+
60: 'fatal'
|
247
|
+
},
|
248
|
+
values: {
|
249
|
+
debug: 20,
|
250
|
+
error: 50,
|
251
|
+
fatal: 60,
|
252
|
+
info: 30,
|
253
|
+
trace: 10,
|
254
|
+
warn: 40
|
255
|
+
}
|
256
|
+
},
|
257
|
+
messageKey: 'msg'
|
258
|
+
}
|
259
|
+
})
|
260
|
+
end()
|
261
|
+
})
|
262
|
+
pino(stream)
|
263
|
+
})
|
264
|
+
|
265
|
+
test('does not explode with a circular ref', async ({ doesNotThrow }) => {
|
266
|
+
const stream = sink()
|
267
|
+
const instance = pino(stream)
|
268
|
+
const b = {}
|
269
|
+
const a = {
|
270
|
+
hello: b
|
271
|
+
}
|
272
|
+
b.a = a // circular ref
|
273
|
+
doesNotThrow(() => instance.info(a))
|
274
|
+
})
|
275
|
+
|
276
|
+
test('set the name', async ({ equal, same }) => {
|
277
|
+
const stream = sink()
|
278
|
+
const instance = pino({
|
279
|
+
name: 'hello'
|
280
|
+
}, stream)
|
281
|
+
instance.fatal('this is fatal')
|
282
|
+
const result = await once(stream, 'data')
|
283
|
+
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
|
284
|
+
delete result.time
|
285
|
+
same(result, {
|
286
|
+
pid,
|
287
|
+
hostname,
|
288
|
+
level: 60,
|
289
|
+
name: 'hello',
|
290
|
+
msg: 'this is fatal'
|
291
|
+
})
|
292
|
+
})
|
293
|
+
|
294
|
+
test('set the messageKey', async ({ equal, same }) => {
|
295
|
+
const stream = sink()
|
296
|
+
const message = 'hello world'
|
297
|
+
const messageKey = 'fooMessage'
|
298
|
+
const instance = pino({
|
299
|
+
messageKey
|
300
|
+
}, stream)
|
301
|
+
instance.info(message)
|
302
|
+
const result = await once(stream, 'data')
|
303
|
+
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
|
304
|
+
delete result.time
|
305
|
+
same(result, {
|
306
|
+
pid,
|
307
|
+
hostname,
|
308
|
+
level: 30,
|
309
|
+
fooMessage: message
|
310
|
+
})
|
311
|
+
})
|
312
|
+
|
313
|
+
test('set the nestedKey', async ({ equal, same }) => {
|
314
|
+
const stream = sink()
|
315
|
+
const object = { hello: 'world' }
|
316
|
+
const nestedKey = 'stuff'
|
317
|
+
const instance = pino({
|
318
|
+
nestedKey
|
319
|
+
}, stream)
|
320
|
+
instance.info(object)
|
321
|
+
const result = await once(stream, 'data')
|
322
|
+
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
|
323
|
+
delete result.time
|
324
|
+
same(result, {
|
325
|
+
pid,
|
326
|
+
hostname,
|
327
|
+
level: 30,
|
328
|
+
stuff: object
|
329
|
+
})
|
330
|
+
})
|
331
|
+
|
332
|
+
test('set undefined properties', async ({ equal, same }) => {
|
333
|
+
const stream = sink()
|
334
|
+
const instance = pino(stream)
|
335
|
+
instance.info({ hello: 'world', property: undefined })
|
336
|
+
const result = await once(stream, 'data')
|
337
|
+
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
|
338
|
+
delete result.time
|
339
|
+
same(result, {
|
340
|
+
pid,
|
341
|
+
hostname,
|
342
|
+
level: 30,
|
343
|
+
hello: 'world'
|
344
|
+
})
|
345
|
+
})
|
346
|
+
|
347
|
+
test('prototype properties are not logged', async ({ equal }) => {
|
348
|
+
const stream = sink()
|
349
|
+
const instance = pino(stream)
|
350
|
+
instance.info(Object.create({ hello: 'world' }))
|
351
|
+
const { hello } = await once(stream, 'data')
|
352
|
+
equal(hello, undefined)
|
353
|
+
})
|
354
|
+
|
355
|
+
test('set the base', async ({ equal, same }) => {
|
356
|
+
const stream = sink()
|
357
|
+
const instance = pino({
|
358
|
+
base: {
|
359
|
+
a: 'b'
|
360
|
+
}
|
361
|
+
}, stream)
|
362
|
+
|
363
|
+
instance.fatal('this is fatal')
|
364
|
+
const result = await once(stream, 'data')
|
365
|
+
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
|
366
|
+
delete result.time
|
367
|
+
same(result, {
|
368
|
+
a: 'b',
|
369
|
+
level: 60,
|
370
|
+
msg: 'this is fatal'
|
371
|
+
})
|
372
|
+
})
|
373
|
+
|
374
|
+
test('set the base to null', async ({ equal, same }) => {
|
375
|
+
const stream = sink()
|
376
|
+
const instance = pino({
|
377
|
+
base: null
|
378
|
+
}, stream)
|
379
|
+
instance.fatal('this is fatal')
|
380
|
+
const result = await once(stream, 'data')
|
381
|
+
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
|
382
|
+
delete result.time
|
383
|
+
same(result, {
|
384
|
+
level: 60,
|
385
|
+
msg: 'this is fatal'
|
386
|
+
})
|
387
|
+
})
|
388
|
+
|
389
|
+
test('set the base to null and use a formatter', async ({ equal, same }) => {
|
390
|
+
const stream = sink()
|
391
|
+
const instance = pino({
|
392
|
+
base: null,
|
393
|
+
formatters: {
|
394
|
+
log (input) {
|
395
|
+
return Object.assign({}, input, { additionalMessage: 'using pino' })
|
396
|
+
}
|
397
|
+
}
|
398
|
+
}, stream)
|
399
|
+
instance.fatal('this is fatal too')
|
400
|
+
const result = await once(stream, 'data')
|
401
|
+
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
|
402
|
+
delete result.time
|
403
|
+
same(result, {
|
404
|
+
level: 60,
|
405
|
+
msg: 'this is fatal too',
|
406
|
+
additionalMessage: 'using pino'
|
407
|
+
})
|
408
|
+
})
|
409
|
+
|
410
|
+
test('throw if creating child without bindings', async ({ equal, fail }) => {
|
411
|
+
const stream = sink()
|
412
|
+
const instance = pino(stream)
|
413
|
+
try {
|
414
|
+
instance.child()
|
415
|
+
fail('it should throw')
|
416
|
+
} catch (err) {
|
417
|
+
equal(err.message, 'missing bindings for child Pino')
|
418
|
+
}
|
419
|
+
})
|
420
|
+
|
421
|
+
test('correctly escapes msg strings with stray double quote at end', async ({ same }) => {
|
422
|
+
const stream = sink()
|
423
|
+
const instance = pino({
|
424
|
+
name: 'hello'
|
425
|
+
}, stream)
|
426
|
+
|
427
|
+
instance.fatal('this contains "')
|
428
|
+
const result = await once(stream, 'data')
|
429
|
+
delete result.time
|
430
|
+
same(result, {
|
431
|
+
pid,
|
432
|
+
hostname,
|
433
|
+
level: 60,
|
434
|
+
name: 'hello',
|
435
|
+
msg: 'this contains "'
|
436
|
+
})
|
437
|
+
})
|
438
|
+
|
439
|
+
test('correctly escape msg strings with unclosed double quote', async ({ same }) => {
|
440
|
+
const stream = sink()
|
441
|
+
const instance = pino({
|
442
|
+
name: 'hello'
|
443
|
+
}, stream)
|
444
|
+
instance.fatal('" this contains')
|
445
|
+
const result = await once(stream, 'data')
|
446
|
+
delete result.time
|
447
|
+
same(result, {
|
448
|
+
pid,
|
449
|
+
hostname,
|
450
|
+
level: 60,
|
451
|
+
name: 'hello',
|
452
|
+
msg: '" this contains'
|
453
|
+
})
|
454
|
+
})
|
455
|
+
|
456
|
+
test('correctly escape quote in a key', async ({ same }) => {
|
457
|
+
const stream = sink()
|
458
|
+
const instance = pino(stream)
|
459
|
+
const obj = { 'some"obj': 'world' }
|
460
|
+
instance.info(obj, 'a string')
|
461
|
+
const result = await once(stream, 'data')
|
462
|
+
delete result.time
|
463
|
+
same(result, {
|
464
|
+
level: 30,
|
465
|
+
pid,
|
466
|
+
hostname,
|
467
|
+
msg: 'a string',
|
468
|
+
'some"obj': 'world'
|
469
|
+
})
|
470
|
+
same(Object.keys(obj), ['some"obj'])
|
471
|
+
})
|
472
|
+
|
473
|
+
// https://github.com/pinojs/pino/issues/139
|
474
|
+
test('object and format string', async ({ same }) => {
|
475
|
+
const stream = sink()
|
476
|
+
const instance = pino(stream)
|
477
|
+
instance.info({}, 'foo %s', 'bar')
|
478
|
+
|
479
|
+
const result = await once(stream, 'data')
|
480
|
+
delete result.time
|
481
|
+
same(result, {
|
482
|
+
pid,
|
483
|
+
hostname,
|
484
|
+
level: 30,
|
485
|
+
msg: 'foo bar'
|
486
|
+
})
|
487
|
+
})
|
488
|
+
|
489
|
+
test('object and format string property', async ({ same }) => {
|
490
|
+
const stream = sink()
|
491
|
+
const instance = pino(stream)
|
492
|
+
instance.info({ answer: 42 }, 'foo %s', 'bar')
|
493
|
+
const result = await once(stream, 'data')
|
494
|
+
delete result.time
|
495
|
+
same(result, {
|
496
|
+
pid,
|
497
|
+
hostname,
|
498
|
+
level: 30,
|
499
|
+
msg: 'foo bar',
|
500
|
+
answer: 42
|
501
|
+
})
|
502
|
+
})
|
503
|
+
|
504
|
+
test('correctly strip undefined when returned from toJSON', async ({ equal }) => {
|
505
|
+
const stream = sink()
|
506
|
+
const instance = pino({
|
507
|
+
test: 'this'
|
508
|
+
}, stream)
|
509
|
+
instance.fatal({ test: { toJSON () { return undefined } } })
|
510
|
+
const result = await once(stream, 'data')
|
511
|
+
equal('test' in result, false)
|
512
|
+
})
|
513
|
+
|
514
|
+
test('correctly supports stderr', async ({ same }) => {
|
515
|
+
// stderr inherits from Stream, rather than Writable
|
516
|
+
const dest = {
|
517
|
+
writable: true,
|
518
|
+
write (result) {
|
519
|
+
result = JSON.parse(result)
|
520
|
+
delete result.time
|
521
|
+
same(result, {
|
522
|
+
pid,
|
523
|
+
hostname,
|
524
|
+
level: 60,
|
525
|
+
msg: 'a message'
|
526
|
+
})
|
527
|
+
}
|
528
|
+
}
|
529
|
+
const instance = pino(dest)
|
530
|
+
instance.fatal('a message')
|
531
|
+
})
|
532
|
+
|
533
|
+
test('normalize number to string', async ({ same }) => {
|
534
|
+
const stream = sink()
|
535
|
+
const instance = pino(stream)
|
536
|
+
instance.info(1)
|
537
|
+
const result = await once(stream, 'data')
|
538
|
+
delete result.time
|
539
|
+
same(result, {
|
540
|
+
pid,
|
541
|
+
hostname,
|
542
|
+
level: 30,
|
543
|
+
msg: '1'
|
544
|
+
})
|
545
|
+
})
|
546
|
+
|
547
|
+
test('normalize number to string with an object', async ({ same }) => {
|
548
|
+
const stream = sink()
|
549
|
+
const instance = pino(stream)
|
550
|
+
instance.info({ answer: 42 }, 1)
|
551
|
+
const result = await once(stream, 'data')
|
552
|
+
delete result.time
|
553
|
+
same(result, {
|
554
|
+
pid,
|
555
|
+
hostname,
|
556
|
+
level: 30,
|
557
|
+
msg: '1',
|
558
|
+
answer: 42
|
559
|
+
})
|
560
|
+
})
|
561
|
+
|
562
|
+
test('handles objects with null prototype', async ({ same }) => {
|
563
|
+
const stream = sink()
|
564
|
+
const instance = pino(stream)
|
565
|
+
const o = Object.create(null)
|
566
|
+
o.test = 'test'
|
567
|
+
instance.info(o)
|
568
|
+
const result = await once(stream, 'data')
|
569
|
+
delete result.time
|
570
|
+
same(result, {
|
571
|
+
pid,
|
572
|
+
hostname,
|
573
|
+
level: 30,
|
574
|
+
test: 'test'
|
575
|
+
})
|
576
|
+
})
|
577
|
+
|
578
|
+
test('pino.destination', async ({ same }) => {
|
579
|
+
const tmp = file()
|
580
|
+
const instance = pino(pino.destination(tmp))
|
581
|
+
instance.info('hello')
|
582
|
+
await watchFileCreated(tmp)
|
583
|
+
const result = JSON.parse(readFileSync(tmp).toString())
|
584
|
+
delete result.time
|
585
|
+
same(result, {
|
586
|
+
pid,
|
587
|
+
hostname,
|
588
|
+
level: 30,
|
589
|
+
msg: 'hello'
|
590
|
+
})
|
591
|
+
})
|
592
|
+
|
593
|
+
test('auto pino.destination with a string', async ({ same }) => {
|
594
|
+
const tmp = file()
|
595
|
+
const instance = pino(tmp)
|
596
|
+
instance.info('hello')
|
597
|
+
await watchFileCreated(tmp)
|
598
|
+
const result = JSON.parse(readFileSync(tmp).toString())
|
599
|
+
delete result.time
|
600
|
+
same(result, {
|
601
|
+
pid,
|
602
|
+
hostname,
|
603
|
+
level: 30,
|
604
|
+
msg: 'hello'
|
605
|
+
})
|
606
|
+
})
|
607
|
+
|
608
|
+
test('auto pino.destination with a string as second argument', async ({ same }) => {
|
609
|
+
const tmp = file()
|
610
|
+
const instance = pino(null, tmp)
|
611
|
+
instance.info('hello')
|
612
|
+
await watchFileCreated(tmp)
|
613
|
+
const result = JSON.parse(readFileSync(tmp).toString())
|
614
|
+
delete result.time
|
615
|
+
same(result, {
|
616
|
+
pid,
|
617
|
+
hostname,
|
618
|
+
level: 30,
|
619
|
+
msg: 'hello'
|
620
|
+
})
|
621
|
+
})
|
622
|
+
|
623
|
+
test('does not override opts with a string as second argument', async ({ same }) => {
|
624
|
+
const tmp = file()
|
625
|
+
const instance = pino({
|
626
|
+
timestamp: () => ',"time":"none"'
|
627
|
+
}, tmp)
|
628
|
+
instance.info('hello')
|
629
|
+
await watchFileCreated(tmp)
|
630
|
+
const result = JSON.parse(readFileSync(tmp).toString())
|
631
|
+
same(result, {
|
632
|
+
pid,
|
633
|
+
hostname,
|
634
|
+
level: 30,
|
635
|
+
time: 'none',
|
636
|
+
msg: 'hello'
|
637
|
+
})
|
638
|
+
})
|
639
|
+
|
640
|
+
// https://github.com/pinojs/pino/issues/222
|
641
|
+
test('children with same names render in correct order', async ({ equal }) => {
|
642
|
+
const stream = sink()
|
643
|
+
const root = pino(stream)
|
644
|
+
root.child({ a: 1 }).child({ a: 2 }).info({ a: 3 })
|
645
|
+
const { a } = await once(stream, 'data')
|
646
|
+
equal(a, 3, 'last logged object takes precedence')
|
647
|
+
})
|
648
|
+
|
649
|
+
test('use `safe-stable-stringify` to avoid circular dependencies', async ({ same }) => {
|
650
|
+
const stream = sink()
|
651
|
+
const root = pino(stream)
|
652
|
+
// circular depth
|
653
|
+
const obj = {}
|
654
|
+
obj.a = obj
|
655
|
+
root.info(obj)
|
656
|
+
const { a } = await once(stream, 'data')
|
657
|
+
same(a, { a: '[Circular]' })
|
658
|
+
})
|
659
|
+
|
660
|
+
test('correctly log non circular objects', async ({ same }) => {
|
661
|
+
const stream = sink()
|
662
|
+
const root = pino(stream)
|
663
|
+
const obj = {}
|
664
|
+
let parent = obj
|
665
|
+
for (let i = 0; i < 10; i++) {
|
666
|
+
parent.node = {}
|
667
|
+
parent = parent.node
|
668
|
+
}
|
669
|
+
root.info(obj)
|
670
|
+
const { node } = await once(stream, 'data')
|
671
|
+
same(node, { node: { node: { node: { node: { node: { node: { node: { node: { node: {} } } } } } } } } })
|
672
|
+
})
|
673
|
+
|
674
|
+
test('safe-stable-stringify must be used when interpolating', async (t) => {
|
675
|
+
const stream = sink()
|
676
|
+
const instance = pino(stream)
|
677
|
+
|
678
|
+
const o = { a: { b: {} } }
|
679
|
+
o.a.b.c = o.a.b
|
680
|
+
instance.info('test %j', o)
|
681
|
+
|
682
|
+
const { msg } = await once(stream, 'data')
|
683
|
+
t.equal(msg, 'test {"a":{"b":{"c":"[Circular]"}}}')
|
684
|
+
})
|
685
|
+
|
686
|
+
test('throws when setting useOnlyCustomLevels without customLevels', async ({ throws }) => {
|
687
|
+
throws(() => {
|
688
|
+
pino({
|
689
|
+
useOnlyCustomLevels: true
|
690
|
+
})
|
691
|
+
}, 'customLevels is required if useOnlyCustomLevels is set true')
|
692
|
+
})
|
693
|
+
|
694
|
+
test('correctly log Infinity', async (t) => {
|
695
|
+
const stream = sink()
|
696
|
+
const instance = pino(stream)
|
697
|
+
|
698
|
+
const o = { num: Infinity }
|
699
|
+
instance.info(o)
|
700
|
+
|
701
|
+
const { num } = await once(stream, 'data')
|
702
|
+
t.equal(num, null)
|
703
|
+
})
|
704
|
+
|
705
|
+
test('correctly log -Infinity', async (t) => {
|
706
|
+
const stream = sink()
|
707
|
+
const instance = pino(stream)
|
708
|
+
|
709
|
+
const o = { num: -Infinity }
|
710
|
+
instance.info(o)
|
711
|
+
|
712
|
+
const { num } = await once(stream, 'data')
|
713
|
+
t.equal(num, null)
|
714
|
+
})
|
715
|
+
|
716
|
+
test('correctly log NaN', async (t) => {
|
717
|
+
const stream = sink()
|
718
|
+
const instance = pino(stream)
|
719
|
+
|
720
|
+
const o = { num: NaN }
|
721
|
+
instance.info(o)
|
722
|
+
|
723
|
+
const { num } = await once(stream, 'data')
|
724
|
+
t.equal(num, null)
|
725
|
+
})
|
726
|
+
|
727
|
+
test('offers a .default() method to please typescript', async ({ equal }) => {
|
728
|
+
equal(pino.default, pino)
|
729
|
+
|
730
|
+
const stream = sink()
|
731
|
+
const instance = pino.default(stream)
|
732
|
+
instance.info('hello world')
|
733
|
+
check(equal, await once(stream, 'data'), 30, 'hello world')
|
734
|
+
})
|
735
|
+
|
736
|
+
test('correctly skip function', async (t) => {
|
737
|
+
const stream = sink()
|
738
|
+
const instance = pino(stream)
|
739
|
+
|
740
|
+
const o = { num: NaN }
|
741
|
+
instance.info(o, () => {})
|
742
|
+
|
743
|
+
const { msg } = await once(stream, 'data')
|
744
|
+
t.equal(msg, undefined)
|
745
|
+
})
|
746
|
+
|
747
|
+
test('correctly skip Infinity', async (t) => {
|
748
|
+
const stream = sink()
|
749
|
+
const instance = pino(stream)
|
750
|
+
|
751
|
+
const o = { num: NaN }
|
752
|
+
instance.info(o, Infinity)
|
753
|
+
|
754
|
+
const { msg } = await once(stream, 'data')
|
755
|
+
t.equal(msg, null)
|
756
|
+
})
|
757
|
+
|
758
|
+
test('correctly log number', async (t) => {
|
759
|
+
const stream = sink()
|
760
|
+
const instance = pino(stream)
|
761
|
+
|
762
|
+
const o = { num: NaN }
|
763
|
+
instance.info(o, 42)
|
764
|
+
|
765
|
+
const { msg } = await once(stream, 'data')
|
766
|
+
t.equal(msg, 42)
|
767
|
+
})
|
768
|
+
|
769
|
+
test('nestedKey should not be used for non-objects', async ({ strictSame }) => {
|
770
|
+
const stream = sink()
|
771
|
+
const message = 'hello'
|
772
|
+
const nestedKey = 'stuff'
|
773
|
+
const instance = pino({
|
774
|
+
nestedKey
|
775
|
+
}, stream)
|
776
|
+
instance.info(message)
|
777
|
+
const result = await once(stream, 'data')
|
778
|
+
delete result.time
|
779
|
+
strictSame(result, {
|
780
|
+
pid,
|
781
|
+
hostname,
|
782
|
+
level: 30,
|
783
|
+
msg: message
|
784
|
+
})
|
785
|
+
})
|
786
|
+
|
787
|
+
test('throws if prettyPrint is passed in as an option', async (t) => {
|
788
|
+
t.throws(() => {
|
789
|
+
pino({
|
790
|
+
prettyPrint: true
|
791
|
+
})
|
792
|
+
}, new Error('prettyPrint option is no longer supported, see the pino-pretty package (https://github.com/pinojs/pino-pretty)'))
|
793
|
+
})
|
794
|
+
|
795
|
+
test('Should invoke `onChild` with the newly created child', async ({ equal }) => {
|
796
|
+
let innerChild
|
797
|
+
const child = pino({
|
798
|
+
onChild: (instance) => {
|
799
|
+
innerChild = instance
|
800
|
+
}
|
801
|
+
}).child({ foo: 'bar' })
|
802
|
+
equal(child, innerChild)
|
803
|
+
})
|
804
|
+
|
805
|
+
test('logger message should have the prefix message that defined in the logger creation', async ({ equal }) => {
|
806
|
+
const stream = sink()
|
807
|
+
const logger = pino({
|
808
|
+
msgPrefix: 'My name is Bond '
|
809
|
+
}, stream)
|
810
|
+
logger.info('James Bond')
|
811
|
+
const { msg } = await once(stream, 'data')
|
812
|
+
equal(msg, 'My name is Bond James Bond')
|
813
|
+
})
|
814
|
+
|
815
|
+
test('child message should have the prefix message that defined in the child creation', async ({ equal }) => {
|
816
|
+
const stream = sink()
|
817
|
+
const instance = pino(stream)
|
818
|
+
const child = instance.child({}, { msgPrefix: 'My name is Bond ' })
|
819
|
+
child.info('James Bond')
|
820
|
+
const { msg } = await once(stream, 'data')
|
821
|
+
equal(msg, 'My name is Bond James Bond')
|
822
|
+
})
|
823
|
+
|
824
|
+
test('child message should have the prefix message that defined in the child creation when logging with log meta', async ({ equal }) => {
|
825
|
+
const stream = sink()
|
826
|
+
const instance = pino(stream)
|
827
|
+
const child = instance.child({}, { msgPrefix: 'My name is Bond ' })
|
828
|
+
child.info({ hello: 'world' }, 'James Bond')
|
829
|
+
const { msg, hello } = await once(stream, 'data')
|
830
|
+
equal(hello, 'world')
|
831
|
+
equal(msg, 'My name is Bond James Bond')
|
832
|
+
})
|
833
|
+
|
834
|
+
test('logged message should not have the prefix when not providing any message', async ({ equal }) => {
|
835
|
+
const stream = sink()
|
836
|
+
const instance = pino(stream)
|
837
|
+
const child = instance.child({}, { msgPrefix: 'This should not be shown ' })
|
838
|
+
child.info({ hello: 'world' })
|
839
|
+
const { msg, hello } = await once(stream, 'data')
|
840
|
+
equal(hello, 'world')
|
841
|
+
equal(msg, undefined)
|
842
|
+
})
|
843
|
+
|
844
|
+
test('child message should append parent prefix to current prefix that defined in the child creation', async ({ equal }) => {
|
845
|
+
const stream = sink()
|
846
|
+
const instance = pino({
|
847
|
+
msgPrefix: 'My name is Bond '
|
848
|
+
}, stream)
|
849
|
+
const child = instance.child({}, { msgPrefix: 'James ' })
|
850
|
+
child.info('Bond')
|
851
|
+
const { msg } = await once(stream, 'data')
|
852
|
+
equal(msg, 'My name is Bond James Bond')
|
853
|
+
})
|
854
|
+
|
855
|
+
test('child message should inherent parent prefix', async ({ equal }) => {
|
856
|
+
const stream = sink()
|
857
|
+
const instance = pino({
|
858
|
+
msgPrefix: 'My name is Bond '
|
859
|
+
}, stream)
|
860
|
+
const child = instance.child({})
|
861
|
+
child.info('James Bond')
|
862
|
+
const { msg } = await once(stream, 'data')
|
863
|
+
equal(msg, 'My name is Bond James Bond')
|
864
|
+
})
|
865
|
+
|
866
|
+
test('grandchild message should inherent parent prefix', async ({ equal }) => {
|
867
|
+
const stream = sink()
|
868
|
+
const instance = pino(stream)
|
869
|
+
const child = instance.child({}, { msgPrefix: 'My name is Bond ' })
|
870
|
+
const grandchild = child.child({})
|
871
|
+
grandchild.info('James Bond')
|
872
|
+
const { msg } = await once(stream, 'data')
|
873
|
+
equal(msg, 'My name is Bond James Bond')
|
874
|
+
})
|