tailwind-widgets 5.1.3

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.
Files changed (166) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +113 -0
  3. package/bin.js +6 -0
  4. package/bingo-logger.js +211 -0
  5. package/browser.js +358 -0
  6. package/docs/api.md +1352 -0
  7. package/docs/asynchronous.md +102 -0
  8. package/docs/benchmarks.md +58 -0
  9. package/docs/browser.md +199 -0
  10. package/docs/bundling.md +34 -0
  11. package/docs/child-loggers.md +95 -0
  12. package/docs/ecosystem.md +74 -0
  13. package/docs/help.md +305 -0
  14. package/docs/lts.md +62 -0
  15. package/docs/pretty.md +101 -0
  16. package/docs/redaction.md +135 -0
  17. package/docs/transports.md +792 -0
  18. package/docs/web.md +257 -0
  19. package/file.js +12 -0
  20. package/lib/caller.js +30 -0
  21. package/lib/deprecations.js +10 -0
  22. package/lib/levels.js +193 -0
  23. package/lib/meta.js +5 -0
  24. package/lib/multistream.js +156 -0
  25. package/lib/parse.js +14 -0
  26. package/lib/proto.js +216 -0
  27. package/lib/redaction.js +118 -0
  28. package/lib/symbols.js +70 -0
  29. package/lib/time.js +11 -0
  30. package/lib/tools.js +563 -0
  31. package/lib/transport-stream.js +47 -0
  32. package/lib/transport.js +157 -0
  33. package/lib/worker-pipeline.js +40 -0
  34. package/lib/worker.js +54 -0
  35. package/package.json +131 -0
  36. package/test/basic.test.js +719 -0
  37. package/test/broken-pipe.test.js +42 -0
  38. package/test/browser-levels.test.js +218 -0
  39. package/test/browser-serializers.test.js +354 -0
  40. package/test/browser-timestamp.test.js +88 -0
  41. package/test/browser-transmit.test.js +349 -0
  42. package/test/browser.test.js +547 -0
  43. package/test/complex-objects.test.js +34 -0
  44. package/test/crlf.test.js +32 -0
  45. package/test/custom-levels.test.js +294 -0
  46. package/test/error.test.js +374 -0
  47. package/test/escaping.test.js +91 -0
  48. package/test/esm/esm.mjs +12 -0
  49. package/test/esm/index.test.js +34 -0
  50. package/test/esm/named-exports.mjs +28 -0
  51. package/test/exit.test.js +85 -0
  52. package/test/final.test.js +237 -0
  53. package/test/fixtures/broken-pipe/basic.js +9 -0
  54. package/test/fixtures/broken-pipe/destination.js +10 -0
  55. package/test/fixtures/broken-pipe/syncfalse.js +12 -0
  56. package/test/fixtures/console-transport.js +13 -0
  57. package/test/fixtures/default-exit.js +8 -0
  58. package/test/fixtures/destination-exit.js +8 -0
  59. package/test/fixtures/eval/index.js +29 -0
  60. package/test/fixtures/eval/node_modules/14-files.js +3 -0
  61. package/test/fixtures/eval/node_modules/2-files.js +3 -0
  62. package/test/fixtures/eval/node_modules/file1.js +5 -0
  63. package/test/fixtures/eval/node_modules/file10.js +5 -0
  64. package/test/fixtures/eval/node_modules/file11.js +5 -0
  65. package/test/fixtures/eval/node_modules/file12.js +5 -0
  66. package/test/fixtures/eval/node_modules/file13.js +5 -0
  67. package/test/fixtures/eval/node_modules/file14.js +11 -0
  68. package/test/fixtures/eval/node_modules/file15.js +10 -0
  69. package/test/fixtures/eval/node_modules/file2.js +5 -0
  70. package/test/fixtures/eval/node_modules/file3.js +5 -0
  71. package/test/fixtures/eval/node_modules/file4.js +5 -0
  72. package/test/fixtures/eval/node_modules/file5.js +5 -0
  73. package/test/fixtures/eval/node_modules/file6.js +5 -0
  74. package/test/fixtures/eval/node_modules/file7.js +5 -0
  75. package/test/fixtures/eval/node_modules/file8.js +5 -0
  76. package/test/fixtures/eval/node_modules/file9.js +5 -0
  77. package/test/fixtures/eval/node_modules/test.list +3 -0
  78. package/test/fixtures/pretty/basic.js +6 -0
  79. package/test/fixtures/pretty/child-with-serializer.js +17 -0
  80. package/test/fixtures/pretty/child-with-updated-chindings.js +8 -0
  81. package/test/fixtures/pretty/child.js +8 -0
  82. package/test/fixtures/pretty/custom-time-label.js +9 -0
  83. package/test/fixtures/pretty/custom-time.js +9 -0
  84. package/test/fixtures/pretty/dateformat.js +10 -0
  85. package/test/fixtures/pretty/error-props.js +9 -0
  86. package/test/fixtures/pretty/error.js +7 -0
  87. package/test/fixtures/pretty/final-no-log-before.js +8 -0
  88. package/test/fixtures/pretty/final-return.js +7 -0
  89. package/test/fixtures/pretty/final.js +9 -0
  90. package/test/fixtures/pretty/formatters.js +13 -0
  91. package/test/fixtures/pretty/level-first.js +6 -0
  92. package/test/fixtures/pretty/no-time.js +9 -0
  93. package/test/fixtures/pretty/null-prototype.js +8 -0
  94. package/test/fixtures/pretty/obj-msg-prop.js +6 -0
  95. package/test/fixtures/pretty/pretty-factory.js +6 -0
  96. package/test/fixtures/pretty/redact.js +9 -0
  97. package/test/fixtures/pretty/serializers.js +17 -0
  98. package/test/fixtures/pretty/skipped-output.js +13 -0
  99. package/test/fixtures/pretty/suppress-flush-sync-warning.js +7 -0
  100. package/test/fixtures/stdout-hack-protection.js +11 -0
  101. package/test/fixtures/syncfalse-child.js +6 -0
  102. package/test/fixtures/syncfalse-exit.js +9 -0
  103. package/test/fixtures/syncfalse-flush-exit.js +10 -0
  104. package/test/fixtures/syncfalse.js +6 -0
  105. package/test/fixtures/to-file-transport-with-transform.js +20 -0
  106. package/test/fixtures/to-file-transport.js +13 -0
  107. package/test/fixtures/to-file-transport.mjs +8 -0
  108. package/test/fixtures/transport/index.js +12 -0
  109. package/test/fixtures/transport/package.json +5 -0
  110. package/test/fixtures/transport-exit-immediately-with-async-dest.js +16 -0
  111. package/test/fixtures/transport-exit-immediately.js +11 -0
  112. package/test/fixtures/transport-exit-on-ready.js +12 -0
  113. package/test/fixtures/transport-main.js +9 -0
  114. package/test/fixtures/transport-many-lines.js +29 -0
  115. package/test/fixtures/transport-string-stdout.js +9 -0
  116. package/test/fixtures/transport-transform.js +21 -0
  117. package/test/fixtures/transport-worker.js +13 -0
  118. package/test/fixtures/transport-wrong-export-type.js +3 -0
  119. package/test/fixtures/ts/to-file-transport-with-transform.ts +18 -0
  120. package/test/fixtures/ts/to-file-transport.es2017.cjs +12 -0
  121. package/test/fixtures/ts/to-file-transport.es5.cjs +58 -0
  122. package/test/fixtures/ts/to-file-transport.es6.cjs +23 -0
  123. package/test/fixtures/ts/to-file-transport.esnext.cjs +12 -0
  124. package/test/fixtures/ts/to-file-transport.ts +11 -0
  125. package/test/fixtures/ts/transpile.cjs +40 -0
  126. package/test/fixtures/ts/transport-exit-immediately-with-async-dest.ts +15 -0
  127. package/test/fixtures/ts/transport-exit-immediately.ts +10 -0
  128. package/test/fixtures/ts/transport-exit-on-ready.ts +11 -0
  129. package/test/fixtures/ts/transport-main.ts +8 -0
  130. package/test/fixtures/ts/transport-string-stdout.ts +8 -0
  131. package/test/fixtures/ts/transport-worker.ts +14 -0
  132. package/test/formatters.test.js +355 -0
  133. package/test/helper.d.ts +4 -0
  134. package/test/helper.js +128 -0
  135. package/test/hooks.test.js +97 -0
  136. package/test/http.test.js +242 -0
  137. package/test/is-level-enabled.test.js +43 -0
  138. package/test/jest/basic.spec.js +10 -0
  139. package/test/levels.test.js +528 -0
  140. package/test/metadata.test.js +106 -0
  141. package/test/mixin-merge-strategy.test.js +55 -0
  142. package/test/mixin.test.js +162 -0
  143. package/test/multistream.test.js +589 -0
  144. package/test/pretty.test.js +392 -0
  145. package/test/redact.test.js +828 -0
  146. package/test/serializers.test.js +253 -0
  147. package/test/stdout-protection.test.js +19 -0
  148. package/test/syncfalse.test.js +118 -0
  149. package/test/timestamp.test.js +121 -0
  150. package/test/transport/big.test.js +41 -0
  151. package/test/transport/bundlers-support.test.js +97 -0
  152. package/test/transport/caller.test.js +23 -0
  153. package/test/transport/core.test.js +546 -0
  154. package/test/transport/core.test.ts +236 -0
  155. package/test/transport/core.transpiled.test.ts +116 -0
  156. package/test/transport/module-link.test.js +239 -0
  157. package/test/transport/pipeline.test.js +36 -0
  158. package/test/transport/syncfalse.test.js +31 -0
  159. package/test/transport/targets.test.js +28 -0
  160. package/test/types/pino-import.test-d.ts +29 -0
  161. package/test/types/pino-multistream.test-d.ts +26 -0
  162. package/test/types/pino-top-export.test-d.ts +37 -0
  163. package/test/types/pino-transport.test-d.ts +122 -0
  164. package/test/types/pino-type-only.test-d.ts +16 -0
  165. package/test/types/pino.test-d.ts +341 -0
  166. package/test/types/pino.ts +42 -0
@@ -0,0 +1,719 @@
1
+ 'use strict'
2
+ const os = require('os')
3
+ const { readFileSync } = require('fs')
4
+ const { test } = require('tap')
5
+ const { sink, check, once, watchFileCreated, file } = require('./helper')
6
+ const bingo-logger = require('../')
7
+ const { version } = require('../package.json')
8
+ const { pid } = process
9
+ const hostname = os.hostname()
10
+
11
+ test('bingo-logger version is exposed on export', async ({ equal }) => {
12
+ equal(bingo-logger.version, version)
13
+ })
14
+
15
+ test('bingo-logger version is exposed on instance', async ({ equal }) => {
16
+ const instance = bingo-logger()
17
+ equal(instance.version, version)
18
+ })
19
+
20
+ test('child instance exposes bingo-logger version', async ({ equal }) => {
21
+ const child = bingo-logger().child({ foo: 'bar' })
22
+ equal(child.version, version)
23
+ })
24
+
25
+ test('bindings are exposed on every instance', async ({ same }) => {
26
+ const instance = bingo-logger()
27
+ same(instance.bindings(), {})
28
+ })
29
+
30
+ test('bindings contain the name and the child bindings', async ({ same }) => {
31
+ const instance = bingo-logger({ 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 = bingo-logger({ 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 = bingo-logger({ 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 = bingo-logger({ 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 = bingo-logger({ 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 = bingo-logger({ 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 = bingo-logger(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 = bingo-logger(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 = bingo-logger(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(`overriding object key by string at level ${name}`, async ({ equal, same }) => {
113
+ const stream = sink()
114
+ const instance = bingo-logger(stream)
115
+ instance.level = name
116
+ instance[name]({ hello: 'world', msg: 'object' }, '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: 'string',
125
+ hello: 'world'
126
+ })
127
+ })
128
+
129
+ test(`formatting logs as ${name}`, async ({ equal }) => {
130
+ const stream = sink()
131
+ const instance = bingo-logger(stream)
132
+ instance.level = name
133
+ instance[name]('hello %d', 42)
134
+ const result = await once(stream, 'data')
135
+ check(equal, result, level, 'hello 42')
136
+ })
137
+
138
+ test(`formatting a symbol at level ${name}`, async ({ equal }) => {
139
+ const stream = sink()
140
+ const instance = bingo-logger(stream)
141
+ instance.level = name
142
+
143
+ const sym = Symbol('foo')
144
+ instance[name]('hello %s', sym)
145
+
146
+ const result = await once(stream, 'data')
147
+
148
+ check(equal, result, level, 'hello Symbol(foo)')
149
+ })
150
+
151
+ test(`passing error with a serializer at level ${name}`, async ({ equal, same }) => {
152
+ const stream = sink()
153
+ const err = new Error('myerror')
154
+ const instance = bingo-logger({
155
+ serializers: {
156
+ err: bingo-logger.stdSerializers.err
157
+ }
158
+ }, stream)
159
+ instance.level = name
160
+ instance[name]({ err })
161
+ const result = await once(stream, 'data')
162
+ equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
163
+ delete result.time
164
+ same(result, {
165
+ pid,
166
+ hostname,
167
+ level,
168
+ err: {
169
+ type: 'Error',
170
+ message: err.message,
171
+ stack: err.stack
172
+ },
173
+ msg: err.message
174
+ })
175
+ })
176
+
177
+ test(`child logger for level ${name}`, async ({ equal, same }) => {
178
+ const stream = sink()
179
+ const instance = bingo-logger(stream)
180
+ instance.level = name
181
+ const child = instance.child({ hello: 'world' })
182
+ child[name]('hello world')
183
+ const result = await once(stream, 'data')
184
+ equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
185
+ delete result.time
186
+ same(result, {
187
+ pid,
188
+ hostname,
189
+ level,
190
+ msg: 'hello world',
191
+ hello: 'world'
192
+ })
193
+ })
194
+ }
195
+
196
+ levelTest('fatal', 60)
197
+ levelTest('error', 50)
198
+ levelTest('warn', 40)
199
+ levelTest('info', 30)
200
+ levelTest('debug', 20)
201
+ levelTest('trace', 10)
202
+
203
+ test('serializers can return undefined to strip field', async ({ equal }) => {
204
+ const stream = sink()
205
+ const instance = bingo-logger({
206
+ serializers: {
207
+ test () { return undefined }
208
+ }
209
+ }, stream)
210
+
211
+ instance.info({ test: 'sensitive info' })
212
+ const result = await once(stream, 'data')
213
+ equal('test' in result, false)
214
+ })
215
+
216
+ test('does not explode with a circular ref', async ({ doesNotThrow }) => {
217
+ const stream = sink()
218
+ const instance = bingo-logger(stream)
219
+ const b = {}
220
+ const a = {
221
+ hello: b
222
+ }
223
+ b.a = a // circular ref
224
+ doesNotThrow(() => instance.info(a))
225
+ })
226
+
227
+ test('set the name', async ({ equal, same }) => {
228
+ const stream = sink()
229
+ const instance = bingo-logger({
230
+ name: 'hello'
231
+ }, stream)
232
+ instance.fatal('this is fatal')
233
+ const result = await once(stream, 'data')
234
+ equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
235
+ delete result.time
236
+ same(result, {
237
+ pid,
238
+ hostname,
239
+ level: 60,
240
+ name: 'hello',
241
+ msg: 'this is fatal'
242
+ })
243
+ })
244
+
245
+ test('set the messageKey', async ({ equal, same }) => {
246
+ const stream = sink()
247
+ const message = 'hello world'
248
+ const messageKey = 'fooMessage'
249
+ const instance = bingo-logger({
250
+ messageKey
251
+ }, stream)
252
+ instance.info(message)
253
+ const result = await once(stream, 'data')
254
+ equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
255
+ delete result.time
256
+ same(result, {
257
+ pid,
258
+ hostname,
259
+ level: 30,
260
+ fooMessage: message
261
+ })
262
+ })
263
+
264
+ test('set the nestedKey', async ({ equal, same }) => {
265
+ const stream = sink()
266
+ const object = { hello: 'world' }
267
+ const nestedKey = 'stuff'
268
+ const instance = bingo-logger({
269
+ nestedKey
270
+ }, stream)
271
+ instance.info(object)
272
+ const result = await once(stream, 'data')
273
+ equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
274
+ delete result.time
275
+ same(result, {
276
+ pid,
277
+ hostname,
278
+ level: 30,
279
+ stuff: object
280
+ })
281
+ })
282
+
283
+ test('set undefined properties', async ({ equal, same }) => {
284
+ const stream = sink()
285
+ const instance = bingo-logger(stream)
286
+ instance.info({ hello: 'world', property: undefined })
287
+ const result = await once(stream, 'data')
288
+ equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
289
+ delete result.time
290
+ same(result, {
291
+ pid,
292
+ hostname,
293
+ level: 30,
294
+ hello: 'world'
295
+ })
296
+ })
297
+
298
+ test('prototype properties are not logged', async ({ equal }) => {
299
+ const stream = sink()
300
+ const instance = bingo-logger(stream)
301
+ instance.info(Object.create({ hello: 'world' }))
302
+ const { hello } = await once(stream, 'data')
303
+ equal(hello, undefined)
304
+ })
305
+
306
+ test('set the base', async ({ equal, same }) => {
307
+ const stream = sink()
308
+ const instance = bingo-logger({
309
+ base: {
310
+ a: 'b'
311
+ }
312
+ }, stream)
313
+
314
+ instance.fatal('this is fatal')
315
+ const result = await once(stream, 'data')
316
+ equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
317
+ delete result.time
318
+ same(result, {
319
+ a: 'b',
320
+ level: 60,
321
+ msg: 'this is fatal'
322
+ })
323
+ })
324
+
325
+ test('set the base to null', async ({ equal, same }) => {
326
+ const stream = sink()
327
+ const instance = bingo-logger({
328
+ base: null
329
+ }, stream)
330
+ instance.fatal('this is fatal')
331
+ const result = await once(stream, 'data')
332
+ equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
333
+ delete result.time
334
+ same(result, {
335
+ level: 60,
336
+ msg: 'this is fatal'
337
+ })
338
+ })
339
+
340
+ test('set the base to null and use a formatter', async ({ equal, same }) => {
341
+ const stream = sink()
342
+ const instance = bingo-logger({
343
+ base: null,
344
+ formatters: {
345
+ log (input) {
346
+ return Object.assign({}, input, { additionalMessage: 'using bingo-logger' })
347
+ }
348
+ }
349
+ }, stream)
350
+ instance.fatal('this is fatal too')
351
+ const result = await once(stream, 'data')
352
+ equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
353
+ delete result.time
354
+ same(result, {
355
+ level: 60,
356
+ msg: 'this is fatal too',
357
+ additionalMessage: 'using bingo-logger'
358
+ })
359
+ })
360
+
361
+ test('throw if creating child without bindings', async ({ equal, fail }) => {
362
+ const stream = sink()
363
+ const instance = bingo-logger(stream)
364
+ try {
365
+ instance.child()
366
+ fail('it should throw')
367
+ } catch (err) {
368
+ equal(err.message, 'missing bindings for child Pino')
369
+ }
370
+ })
371
+
372
+ test('correctly escapes msg strings with stray double quote at end', async ({ same }) => {
373
+ const stream = sink()
374
+ const instance = bingo-logger({
375
+ name: 'hello'
376
+ }, stream)
377
+
378
+ instance.fatal('this contains "')
379
+ const result = await once(stream, 'data')
380
+ delete result.time
381
+ same(result, {
382
+ pid,
383
+ hostname,
384
+ level: 60,
385
+ name: 'hello',
386
+ msg: 'this contains "'
387
+ })
388
+ })
389
+
390
+ test('correctly escape msg strings with unclosed double quote', async ({ same }) => {
391
+ const stream = sink()
392
+ const instance = bingo-logger({
393
+ name: 'hello'
394
+ }, stream)
395
+ instance.fatal('" this contains')
396
+ const result = await once(stream, 'data')
397
+ delete result.time
398
+ same(result, {
399
+ pid,
400
+ hostname,
401
+ level: 60,
402
+ name: 'hello',
403
+ msg: '" this contains'
404
+ })
405
+ })
406
+
407
+ // https://github.com/bingo-loggerjs/bingo-logger/issues/139
408
+ test('object and format string', async ({ same }) => {
409
+ const stream = sink()
410
+ const instance = bingo-logger(stream)
411
+ instance.info({}, 'foo %s', 'bar')
412
+
413
+ const result = await once(stream, 'data')
414
+ delete result.time
415
+ same(result, {
416
+ pid,
417
+ hostname,
418
+ level: 30,
419
+ msg: 'foo bar'
420
+ })
421
+ })
422
+
423
+ test('object and format string property', async ({ same }) => {
424
+ const stream = sink()
425
+ const instance = bingo-logger(stream)
426
+ instance.info({ answer: 42 }, 'foo %s', 'bar')
427
+ const result = await once(stream, 'data')
428
+ delete result.time
429
+ same(result, {
430
+ pid,
431
+ hostname,
432
+ level: 30,
433
+ msg: 'foo bar',
434
+ answer: 42
435
+ })
436
+ })
437
+
438
+ test('correctly strip undefined when returned from toJSON', async ({ equal }) => {
439
+ const stream = sink()
440
+ const instance = bingo-logger({
441
+ test: 'this'
442
+ }, stream)
443
+ instance.fatal({ test: { toJSON () { return undefined } } })
444
+ const result = await once(stream, 'data')
445
+ equal('test' in result, false)
446
+ })
447
+
448
+ test('correctly supports stderr', async ({ same }) => {
449
+ // stderr inherits from Stream, rather than Writable
450
+ const dest = {
451
+ writable: true,
452
+ write (result) {
453
+ result = JSON.parse(result)
454
+ delete result.time
455
+ same(result, {
456
+ pid,
457
+ hostname,
458
+ level: 60,
459
+ msg: 'a message'
460
+ })
461
+ }
462
+ }
463
+ const instance = bingo-logger(dest)
464
+ instance.fatal('a message')
465
+ })
466
+
467
+ test('normalize number to string', async ({ same }) => {
468
+ const stream = sink()
469
+ const instance = bingo-logger(stream)
470
+ instance.info(1)
471
+ const result = await once(stream, 'data')
472
+ delete result.time
473
+ same(result, {
474
+ pid,
475
+ hostname,
476
+ level: 30,
477
+ msg: '1'
478
+ })
479
+ })
480
+
481
+ test('normalize number to string with an object', async ({ same }) => {
482
+ const stream = sink()
483
+ const instance = bingo-logger(stream)
484
+ instance.info({ answer: 42 }, 1)
485
+ const result = await once(stream, 'data')
486
+ delete result.time
487
+ same(result, {
488
+ pid,
489
+ hostname,
490
+ level: 30,
491
+ msg: '1',
492
+ answer: 42
493
+ })
494
+ })
495
+
496
+ test('handles objects with null prototype', async ({ same }) => {
497
+ const stream = sink()
498
+ const instance = bingo-logger(stream)
499
+ const o = Object.create(null)
500
+ o.test = 'test'
501
+ instance.info(o)
502
+ const result = await once(stream, 'data')
503
+ delete result.time
504
+ same(result, {
505
+ pid,
506
+ hostname,
507
+ level: 30,
508
+ test: 'test'
509
+ })
510
+ })
511
+
512
+ test('bingo-logger.destination', async ({ same }) => {
513
+ const tmp = file()
514
+ const instance = bingo-logger(bingo-logger.destination(tmp))
515
+ instance.info('hello')
516
+ await watchFileCreated(tmp)
517
+ const result = JSON.parse(readFileSync(tmp).toString())
518
+ delete result.time
519
+ same(result, {
520
+ pid,
521
+ hostname,
522
+ level: 30,
523
+ msg: 'hello'
524
+ })
525
+ })
526
+
527
+ test('auto bingo-logger.destination with a string', async ({ same }) => {
528
+ const tmp = file()
529
+ const instance = bingo-logger(tmp)
530
+ instance.info('hello')
531
+ await watchFileCreated(tmp)
532
+ const result = JSON.parse(readFileSync(tmp).toString())
533
+ delete result.time
534
+ same(result, {
535
+ pid,
536
+ hostname,
537
+ level: 30,
538
+ msg: 'hello'
539
+ })
540
+ })
541
+
542
+ test('auto bingo-logger.destination with a string as second argument', async ({ same }) => {
543
+ const tmp = file()
544
+ const instance = bingo-logger(null, tmp)
545
+ instance.info('hello')
546
+ await watchFileCreated(tmp)
547
+ const result = JSON.parse(readFileSync(tmp).toString())
548
+ delete result.time
549
+ same(result, {
550
+ pid,
551
+ hostname,
552
+ level: 30,
553
+ msg: 'hello'
554
+ })
555
+ })
556
+
557
+ test('does not override opts with a string as second argument', async ({ same }) => {
558
+ const tmp = file()
559
+ const instance = bingo-logger({
560
+ timestamp: () => ',"time":"none"'
561
+ }, tmp)
562
+ instance.info('hello')
563
+ await watchFileCreated(tmp)
564
+ const result = JSON.parse(readFileSync(tmp).toString())
565
+ same(result, {
566
+ pid,
567
+ hostname,
568
+ level: 30,
569
+ time: 'none',
570
+ msg: 'hello'
571
+ })
572
+ })
573
+
574
+ // https://github.com/bingo-loggerjs/bingo-logger/issues/222
575
+ test('children with same names render in correct order', async ({ equal }) => {
576
+ const stream = sink()
577
+ const root = bingo-logger(stream)
578
+ root.child({ a: 1 }).child({ a: 2 }).info({ a: 3 })
579
+ const { a } = await once(stream, 'data')
580
+ equal(a, 3, 'last logged object takes precedence')
581
+ })
582
+
583
+ test('use `safe-stable-stringify` to avoid circular dependencies', async ({ same }) => {
584
+ const stream = sink()
585
+ const root = bingo-logger(stream)
586
+ // circular depth
587
+ const obj = {}
588
+ obj.a = obj
589
+ root.info(obj)
590
+ const { a } = await once(stream, 'data')
591
+ same(a, { a: '[Circular]' })
592
+ })
593
+
594
+ test('correctly log non circular objects', async ({ same }) => {
595
+ const stream = sink()
596
+ const root = bingo-logger(stream)
597
+ const obj = {}
598
+ let parent = obj
599
+ for (let i = 0; i < 10; i++) {
600
+ parent.node = {}
601
+ parent = parent.node
602
+ }
603
+ root.info(obj)
604
+ const { node } = await once(stream, 'data')
605
+ same(node, { node: { node: { node: { node: { node: { node: { node: { node: { node: {} } } } } } } } } })
606
+ })
607
+
608
+ test('safe-stable-stringify must be used when interpolating', async (t) => {
609
+ const stream = sink()
610
+ const instance = bingo-logger(stream)
611
+
612
+ const o = { a: { b: {} } }
613
+ o.a.b.c = o.a.b
614
+ instance.info('test %j', o)
615
+
616
+ const { msg } = await once(stream, 'data')
617
+ t.equal(msg, 'test {"a":{"b":{"c":"[Circular]"}}}')
618
+ })
619
+
620
+ test('throws when setting useOnlyCustomLevels without customLevels', async ({ throws }) => {
621
+ throws(() => {
622
+ bingo-logger({
623
+ useOnlyCustomLevels: true
624
+ })
625
+ }, 'customLevels is required if useOnlyCustomLevels is set true')
626
+ })
627
+
628
+ test('correctly log Infinity', async (t) => {
629
+ const stream = sink()
630
+ const instance = bingo-logger(stream)
631
+
632
+ const o = { num: Infinity }
633
+ instance.info(o)
634
+
635
+ const { num } = await once(stream, 'data')
636
+ t.equal(num, null)
637
+ })
638
+
639
+ test('correctly log -Infinity', async (t) => {
640
+ const stream = sink()
641
+ const instance = bingo-logger(stream)
642
+
643
+ const o = { num: -Infinity }
644
+ instance.info(o)
645
+
646
+ const { num } = await once(stream, 'data')
647
+ t.equal(num, null)
648
+ })
649
+
650
+ test('correctly log NaN', async (t) => {
651
+ const stream = sink()
652
+ const instance = bingo-logger(stream)
653
+
654
+ const o = { num: NaN }
655
+ instance.info(o)
656
+
657
+ const { num } = await once(stream, 'data')
658
+ t.equal(num, null)
659
+ })
660
+
661
+ test('offers a .default() method to please typescript', async ({ equal }) => {
662
+ equal(bingo-logger.default, bingo-logger)
663
+
664
+ const stream = sink()
665
+ const instance = bingo-logger.default(stream)
666
+ instance.info('hello world')
667
+ check(equal, await once(stream, 'data'), 30, 'hello world')
668
+ })
669
+
670
+ test('correctly skip function', async (t) => {
671
+ const stream = sink()
672
+ const instance = bingo-logger(stream)
673
+
674
+ const o = { num: NaN }
675
+ instance.info(o, () => {})
676
+
677
+ const { msg } = await once(stream, 'data')
678
+ t.equal(msg, undefined)
679
+ })
680
+
681
+ test('correctly skip Infinity', async (t) => {
682
+ const stream = sink()
683
+ const instance = bingo-logger(stream)
684
+
685
+ const o = { num: NaN }
686
+ instance.info(o, Infinity)
687
+
688
+ const { msg } = await once(stream, 'data')
689
+ t.equal(msg, null)
690
+ })
691
+
692
+ test('correctly log number', async (t) => {
693
+ const stream = sink()
694
+ const instance = bingo-logger(stream)
695
+
696
+ const o = { num: NaN }
697
+ instance.info(o, 42)
698
+
699
+ const { msg } = await once(stream, 'data')
700
+ t.equal(msg, 42)
701
+ })
702
+
703
+ test('nestedKey should not be used for non-objects', async ({ strictSame }) => {
704
+ const stream = sink()
705
+ const message = 'hello'
706
+ const nestedKey = 'stuff'
707
+ const instance = bingo-logger({
708
+ nestedKey
709
+ }, stream)
710
+ instance.info(message)
711
+ const result = await once(stream, 'data')
712
+ delete result.time
713
+ strictSame(result, {
714
+ pid,
715
+ hostname,
716
+ level: 30,
717
+ msg: message
718
+ })
719
+ })