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.
- package/LICENSE +24 -0
- package/README.md +113 -0
- package/bin.js +6 -0
- package/bingo-logger.js +211 -0
- package/browser.js +358 -0
- package/docs/api.md +1352 -0
- package/docs/asynchronous.md +102 -0
- package/docs/benchmarks.md +58 -0
- package/docs/browser.md +199 -0
- package/docs/bundling.md +34 -0
- package/docs/child-loggers.md +95 -0
- package/docs/ecosystem.md +74 -0
- package/docs/help.md +305 -0
- package/docs/lts.md +62 -0
- package/docs/pretty.md +101 -0
- package/docs/redaction.md +135 -0
- package/docs/transports.md +792 -0
- package/docs/web.md +257 -0
- package/file.js +12 -0
- package/lib/caller.js +30 -0
- package/lib/deprecations.js +10 -0
- package/lib/levels.js +193 -0
- package/lib/meta.js +5 -0
- package/lib/multistream.js +156 -0
- package/lib/parse.js +14 -0
- package/lib/proto.js +216 -0
- package/lib/redaction.js +118 -0
- package/lib/symbols.js +70 -0
- package/lib/time.js +11 -0
- package/lib/tools.js +563 -0
- package/lib/transport-stream.js +47 -0
- package/lib/transport.js +157 -0
- package/lib/worker-pipeline.js +40 -0
- package/lib/worker.js +54 -0
- package/package.json +131 -0
- package/test/basic.test.js +719 -0
- package/test/broken-pipe.test.js +42 -0
- package/test/browser-levels.test.js +218 -0
- package/test/browser-serializers.test.js +354 -0
- package/test/browser-timestamp.test.js +88 -0
- package/test/browser-transmit.test.js +349 -0
- package/test/browser.test.js +547 -0
- package/test/complex-objects.test.js +34 -0
- package/test/crlf.test.js +32 -0
- package/test/custom-levels.test.js +294 -0
- package/test/error.test.js +374 -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 +28 -0
- package/test/exit.test.js +85 -0
- package/test/final.test.js +237 -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 +29 -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/file15.js +10 -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/eval/node_modules/test.list +3 -0
- package/test/fixtures/pretty/basic.js +6 -0
- package/test/fixtures/pretty/child-with-serializer.js +17 -0
- package/test/fixtures/pretty/child-with-updated-chindings.js +8 -0
- package/test/fixtures/pretty/child.js +8 -0
- package/test/fixtures/pretty/custom-time-label.js +9 -0
- package/test/fixtures/pretty/custom-time.js +9 -0
- package/test/fixtures/pretty/dateformat.js +10 -0
- package/test/fixtures/pretty/error-props.js +9 -0
- package/test/fixtures/pretty/error.js +7 -0
- package/test/fixtures/pretty/final-no-log-before.js +8 -0
- package/test/fixtures/pretty/final-return.js +7 -0
- package/test/fixtures/pretty/final.js +9 -0
- package/test/fixtures/pretty/formatters.js +13 -0
- package/test/fixtures/pretty/level-first.js +6 -0
- package/test/fixtures/pretty/no-time.js +9 -0
- package/test/fixtures/pretty/null-prototype.js +8 -0
- package/test/fixtures/pretty/obj-msg-prop.js +6 -0
- package/test/fixtures/pretty/pretty-factory.js +6 -0
- package/test/fixtures/pretty/redact.js +9 -0
- package/test/fixtures/pretty/serializers.js +17 -0
- package/test/fixtures/pretty/skipped-output.js +13 -0
- package/test/fixtures/pretty/suppress-flush-sync-warning.js +7 -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/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-worker.js +13 -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.es2017.cjs +12 -0
- package/test/fixtures/ts/to-file-transport.es5.cjs +58 -0
- package/test/fixtures/ts/to-file-transport.es6.cjs +23 -0
- package/test/fixtures/ts/to-file-transport.esnext.cjs +12 -0
- package/test/fixtures/ts/to-file-transport.ts +11 -0
- package/test/fixtures/ts/transpile.cjs +40 -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 +97 -0
- package/test/http.test.js +242 -0
- package/test/is-level-enabled.test.js +43 -0
- package/test/jest/basic.spec.js +10 -0
- package/test/levels.test.js +528 -0
- package/test/metadata.test.js +106 -0
- package/test/mixin-merge-strategy.test.js +55 -0
- package/test/mixin.test.js +162 -0
- package/test/multistream.test.js +589 -0
- package/test/pretty.test.js +392 -0
- package/test/redact.test.js +828 -0
- package/test/serializers.test.js +253 -0
- package/test/stdout-protection.test.js +19 -0
- package/test/syncfalse.test.js +118 -0
- package/test/timestamp.test.js +121 -0
- package/test/transport/big.test.js +41 -0
- package/test/transport/bundlers-support.test.js +97 -0
- package/test/transport/caller.test.js +23 -0
- package/test/transport/core.test.js +546 -0
- package/test/transport/core.test.ts +236 -0
- package/test/transport/core.transpiled.test.ts +116 -0
- package/test/transport/module-link.test.js +239 -0
- package/test/transport/pipeline.test.js +36 -0
- package/test/transport/syncfalse.test.js +31 -0
- package/test/transport/targets.test.js +28 -0
- package/test/types/pino-import.test-d.ts +29 -0
- package/test/types/pino-multistream.test-d.ts +26 -0
- package/test/types/pino-top-export.test-d.ts +37 -0
- package/test/types/pino-transport.test-d.ts +122 -0
- package/test/types/pino-type-only.test-d.ts +16 -0
- package/test/types/pino.test-d.ts +341 -0
- package/test/types/pino.ts +42 -0
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const test = require('tape')
|
|
3
|
+
const fresh = require('import-fresh')
|
|
4
|
+
const pinoStdSerializers = require('bingo-logger-std-serializers')
|
|
5
|
+
const bingo-logger = require('../browser')
|
|
6
|
+
|
|
7
|
+
levelTest('fatal')
|
|
8
|
+
levelTest('error')
|
|
9
|
+
levelTest('warn')
|
|
10
|
+
levelTest('info')
|
|
11
|
+
levelTest('debug')
|
|
12
|
+
levelTest('trace')
|
|
13
|
+
|
|
14
|
+
test('silent level', ({ end, fail, pass }) => {
|
|
15
|
+
const instance = bingo-logger({
|
|
16
|
+
level: 'silent',
|
|
17
|
+
browser: { write: fail }
|
|
18
|
+
})
|
|
19
|
+
instance.info('test')
|
|
20
|
+
const child = instance.child({ test: 'test' })
|
|
21
|
+
child.info('msg-test')
|
|
22
|
+
// use setTimeout because setImmediate isn't supported in most browsers
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
pass()
|
|
25
|
+
end()
|
|
26
|
+
}, 0)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('enabled false', ({ end, fail, pass }) => {
|
|
30
|
+
const instance = bingo-logger({
|
|
31
|
+
enabled: false,
|
|
32
|
+
browser: { write: fail }
|
|
33
|
+
})
|
|
34
|
+
instance.info('test')
|
|
35
|
+
const child = instance.child({ test: 'test' })
|
|
36
|
+
child.info('msg-test')
|
|
37
|
+
// use setTimeout because setImmediate isn't supported in most browsers
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
pass()
|
|
40
|
+
end()
|
|
41
|
+
}, 0)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('throw if creating child without bindings', ({ end, throws }) => {
|
|
45
|
+
const instance = bingo-logger()
|
|
46
|
+
throws(() => instance.child())
|
|
47
|
+
end()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('stubs write, flush and ee methods on instance', ({ end, ok, is }) => {
|
|
51
|
+
const instance = bingo-logger()
|
|
52
|
+
|
|
53
|
+
ok(isFunc(instance.setMaxListeners))
|
|
54
|
+
ok(isFunc(instance.getMaxListeners))
|
|
55
|
+
ok(isFunc(instance.emit))
|
|
56
|
+
ok(isFunc(instance.addListener))
|
|
57
|
+
ok(isFunc(instance.on))
|
|
58
|
+
ok(isFunc(instance.prependListener))
|
|
59
|
+
ok(isFunc(instance.once))
|
|
60
|
+
ok(isFunc(instance.prependOnceListener))
|
|
61
|
+
ok(isFunc(instance.removeListener))
|
|
62
|
+
ok(isFunc(instance.removeAllListeners))
|
|
63
|
+
ok(isFunc(instance.listeners))
|
|
64
|
+
ok(isFunc(instance.listenerCount))
|
|
65
|
+
ok(isFunc(instance.eventNames))
|
|
66
|
+
ok(isFunc(instance.write))
|
|
67
|
+
ok(isFunc(instance.flush))
|
|
68
|
+
|
|
69
|
+
is(instance.on(), undefined)
|
|
70
|
+
|
|
71
|
+
end()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('exposes levels object', ({ end, same }) => {
|
|
75
|
+
same(bingo-logger.levels, {
|
|
76
|
+
values: {
|
|
77
|
+
fatal: 60,
|
|
78
|
+
error: 50,
|
|
79
|
+
warn: 40,
|
|
80
|
+
info: 30,
|
|
81
|
+
debug: 20,
|
|
82
|
+
trace: 10
|
|
83
|
+
},
|
|
84
|
+
labels: {
|
|
85
|
+
10: 'trace',
|
|
86
|
+
20: 'debug',
|
|
87
|
+
30: 'info',
|
|
88
|
+
40: 'warn',
|
|
89
|
+
50: 'error',
|
|
90
|
+
60: 'fatal'
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
end()
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test('exposes faux stdSerializers', ({ end, ok, same }) => {
|
|
98
|
+
ok(bingo-logger.stdSerializers)
|
|
99
|
+
// make sure faux stdSerializers match bingo-logger-std-serializers
|
|
100
|
+
for (const serializer in pinoStdSerializers) {
|
|
101
|
+
ok(bingo-logger.stdSerializers[serializer], `bingo-logger.stdSerializers.${serializer}`)
|
|
102
|
+
}
|
|
103
|
+
// confirm faux methods return empty objects
|
|
104
|
+
same(bingo-logger.stdSerializers.req(), {})
|
|
105
|
+
same(bingo-logger.stdSerializers.mapHttpRequest(), {})
|
|
106
|
+
same(bingo-logger.stdSerializers.mapHttpResponse(), {})
|
|
107
|
+
same(bingo-logger.stdSerializers.res(), {})
|
|
108
|
+
// confirm wrapping function is a passthrough
|
|
109
|
+
const noChange = { foo: 'bar', fuz: 42 }
|
|
110
|
+
same(bingo-logger.stdSerializers.wrapRequestSerializer(noChange), noChange)
|
|
111
|
+
same(bingo-logger.stdSerializers.wrapResponseSerializer(noChange), noChange)
|
|
112
|
+
end()
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
test('exposes err stdSerializer', ({ end, ok }) => {
|
|
116
|
+
ok(bingo-logger.stdSerializers.err)
|
|
117
|
+
ok(bingo-logger.stdSerializers.err(Error()))
|
|
118
|
+
end()
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
consoleMethodTest('error')
|
|
122
|
+
consoleMethodTest('fatal', 'error')
|
|
123
|
+
consoleMethodTest('warn')
|
|
124
|
+
consoleMethodTest('info')
|
|
125
|
+
consoleMethodTest('debug')
|
|
126
|
+
consoleMethodTest('trace')
|
|
127
|
+
absentConsoleMethodTest('error', 'log')
|
|
128
|
+
absentConsoleMethodTest('warn', 'error')
|
|
129
|
+
absentConsoleMethodTest('info', 'log')
|
|
130
|
+
absentConsoleMethodTest('debug', 'log')
|
|
131
|
+
absentConsoleMethodTest('trace', 'log')
|
|
132
|
+
|
|
133
|
+
// do not run this with airtap
|
|
134
|
+
if (process.title !== 'browser') {
|
|
135
|
+
test('in absence of console, log methods become noops', ({ end, ok }) => {
|
|
136
|
+
const console = global.console
|
|
137
|
+
delete global.console
|
|
138
|
+
const instance = fresh('../browser')()
|
|
139
|
+
global.console = console
|
|
140
|
+
ok(fnName(instance.log).match(/noop/))
|
|
141
|
+
ok(fnName(instance.fatal).match(/noop/))
|
|
142
|
+
ok(fnName(instance.error).match(/noop/))
|
|
143
|
+
ok(fnName(instance.warn).match(/noop/))
|
|
144
|
+
ok(fnName(instance.info).match(/noop/))
|
|
145
|
+
ok(fnName(instance.debug).match(/noop/))
|
|
146
|
+
ok(fnName(instance.trace).match(/noop/))
|
|
147
|
+
end()
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
test('opts.browser.asObject logs bingo-logger-like object to console', ({ end, ok, is }) => {
|
|
152
|
+
const info = console.info
|
|
153
|
+
console.info = function (o) {
|
|
154
|
+
is(o.level, 30)
|
|
155
|
+
is(o.msg, 'test')
|
|
156
|
+
ok(o.time)
|
|
157
|
+
console.info = info
|
|
158
|
+
}
|
|
159
|
+
const instance = require('../browser')({
|
|
160
|
+
browser: {
|
|
161
|
+
asObject: true
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
instance.info('test')
|
|
166
|
+
end()
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
test('opts.browser.write func log single string', ({ end, ok, is }) => {
|
|
170
|
+
const instance = bingo-logger({
|
|
171
|
+
browser: {
|
|
172
|
+
write: function (o) {
|
|
173
|
+
is(o.level, 30)
|
|
174
|
+
is(o.msg, 'test')
|
|
175
|
+
ok(o.time)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
})
|
|
179
|
+
instance.info('test')
|
|
180
|
+
|
|
181
|
+
end()
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
test('opts.browser.write func string joining', ({ end, ok, is }) => {
|
|
185
|
+
const instance = bingo-logger({
|
|
186
|
+
browser: {
|
|
187
|
+
write: function (o) {
|
|
188
|
+
is(o.level, 30)
|
|
189
|
+
is(o.msg, 'test test2 test3')
|
|
190
|
+
ok(o.time)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
})
|
|
194
|
+
instance.info('test %s %s', 'test2', 'test3')
|
|
195
|
+
|
|
196
|
+
end()
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
test('opts.browser.write func string joining when asObject is true', ({ end, ok, is }) => {
|
|
200
|
+
const instance = bingo-logger({
|
|
201
|
+
browser: {
|
|
202
|
+
asObject: true,
|
|
203
|
+
write: function (o) {
|
|
204
|
+
is(o.level, 30)
|
|
205
|
+
is(o.msg, 'test test2 test3')
|
|
206
|
+
ok(o.time)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
})
|
|
210
|
+
instance.info('test %s %s', 'test2', 'test3')
|
|
211
|
+
|
|
212
|
+
end()
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
test('opts.browser.write func string joining when asObject is true', ({ end, ok, is }) => {
|
|
216
|
+
const instance = bingo-logger({
|
|
217
|
+
browser: {
|
|
218
|
+
asObject: true,
|
|
219
|
+
write: function (o) {
|
|
220
|
+
is(o.level, 30)
|
|
221
|
+
is(o.msg, 'test test2 test3')
|
|
222
|
+
ok(o.time)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
})
|
|
226
|
+
instance.info('test %s %s', 'test2', 'test3')
|
|
227
|
+
|
|
228
|
+
end()
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
test('opts.browser.write func string object joining', ({ end, ok, is }) => {
|
|
232
|
+
const instance = bingo-logger({
|
|
233
|
+
browser: {
|
|
234
|
+
write: function (o) {
|
|
235
|
+
is(o.level, 30)
|
|
236
|
+
is(o.msg, 'test {"test":"test2"} {"test":"test3"}')
|
|
237
|
+
ok(o.time)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
instance.info('test %j %j', { test: 'test2' }, { test: 'test3' })
|
|
242
|
+
|
|
243
|
+
end()
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test('opts.browser.write func string object joining when asObject is true', ({ end, ok, is }) => {
|
|
247
|
+
const instance = bingo-logger({
|
|
248
|
+
browser: {
|
|
249
|
+
asObject: true,
|
|
250
|
+
write: function (o) {
|
|
251
|
+
is(o.level, 30)
|
|
252
|
+
is(o.msg, 'test {"test":"test2"} {"test":"test3"}')
|
|
253
|
+
ok(o.time)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
instance.info('test %j %j', { test: 'test2' }, { test: 'test3' })
|
|
258
|
+
|
|
259
|
+
end()
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
test('opts.browser.write func string interpolation', ({ end, ok, is }) => {
|
|
263
|
+
const instance = bingo-logger({
|
|
264
|
+
browser: {
|
|
265
|
+
write: function (o) {
|
|
266
|
+
is(o.level, 30)
|
|
267
|
+
is(o.msg, 'test2 test ({"test":"test3"})')
|
|
268
|
+
ok(o.time)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
})
|
|
272
|
+
instance.info('%s test (%j)', 'test2', { test: 'test3' })
|
|
273
|
+
|
|
274
|
+
end()
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
test('opts.browser.write func number', ({ end, ok, is }) => {
|
|
278
|
+
const instance = bingo-logger({
|
|
279
|
+
browser: {
|
|
280
|
+
write: function (o) {
|
|
281
|
+
is(o.level, 30)
|
|
282
|
+
is(o.msg, 1)
|
|
283
|
+
ok(o.time)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
instance.info(1)
|
|
288
|
+
|
|
289
|
+
end()
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
test('opts.browser.write func log single object', ({ end, ok, is }) => {
|
|
293
|
+
const instance = bingo-logger({
|
|
294
|
+
browser: {
|
|
295
|
+
write: function (o) {
|
|
296
|
+
is(o.level, 30)
|
|
297
|
+
is(o.test, 'test')
|
|
298
|
+
ok(o.time)
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
})
|
|
302
|
+
instance.info({ test: 'test' })
|
|
303
|
+
|
|
304
|
+
end()
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
test('opts.browser.write obj writes to methods corresponding to level', ({ end, ok, is }) => {
|
|
308
|
+
const instance = bingo-logger({
|
|
309
|
+
browser: {
|
|
310
|
+
write: {
|
|
311
|
+
error: function (o) {
|
|
312
|
+
is(o.level, 50)
|
|
313
|
+
is(o.test, 'test')
|
|
314
|
+
ok(o.time)
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
instance.error({ test: 'test' })
|
|
320
|
+
|
|
321
|
+
end()
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
test('opts.browser.asObject/write supports child loggers', ({ end, ok, is }) => {
|
|
325
|
+
const instance = bingo-logger({
|
|
326
|
+
browser: {
|
|
327
|
+
write (o) {
|
|
328
|
+
is(o.level, 30)
|
|
329
|
+
is(o.test, 'test')
|
|
330
|
+
is(o.msg, 'msg-test')
|
|
331
|
+
ok(o.time)
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
})
|
|
335
|
+
const child = instance.child({ test: 'test' })
|
|
336
|
+
child.info('msg-test')
|
|
337
|
+
|
|
338
|
+
end()
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
test('opts.browser.asObject/write supports child child loggers', ({ end, ok, is }) => {
|
|
342
|
+
const instance = bingo-logger({
|
|
343
|
+
browser: {
|
|
344
|
+
write (o) {
|
|
345
|
+
is(o.level, 30)
|
|
346
|
+
is(o.test, 'test')
|
|
347
|
+
is(o.foo, 'bar')
|
|
348
|
+
is(o.msg, 'msg-test')
|
|
349
|
+
ok(o.time)
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
})
|
|
353
|
+
const child = instance.child({ test: 'test' }).child({ foo: 'bar' })
|
|
354
|
+
child.info('msg-test')
|
|
355
|
+
|
|
356
|
+
end()
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
test('opts.browser.asObject/write supports child child child loggers', ({ end, ok, is }) => {
|
|
360
|
+
const instance = bingo-logger({
|
|
361
|
+
browser: {
|
|
362
|
+
write (o) {
|
|
363
|
+
is(o.level, 30)
|
|
364
|
+
is(o.test, 'test')
|
|
365
|
+
is(o.foo, 'bar')
|
|
366
|
+
is(o.baz, 'bop')
|
|
367
|
+
is(o.msg, 'msg-test')
|
|
368
|
+
ok(o.time)
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
})
|
|
372
|
+
const child = instance.child({ test: 'test' }).child({ foo: 'bar' }).child({ baz: 'bop' })
|
|
373
|
+
child.info('msg-test')
|
|
374
|
+
|
|
375
|
+
end()
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
test('opts.browser.asObject defensively mitigates naughty numbers', ({ end, pass }) => {
|
|
379
|
+
const instance = bingo-logger({
|
|
380
|
+
browser: { asObject: true, write: () => {} }
|
|
381
|
+
})
|
|
382
|
+
const child = instance.child({ test: 'test' })
|
|
383
|
+
child._childLevel = -10
|
|
384
|
+
child.info('test')
|
|
385
|
+
pass() // if we reached here, there was no infinite loop, so, .. pass.
|
|
386
|
+
|
|
387
|
+
end()
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
test('opts.browser.write obj falls back to console where a method is not supplied', ({ end, ok, is }) => {
|
|
391
|
+
const info = console.info
|
|
392
|
+
console.info = (o) => {
|
|
393
|
+
is(o.level, 30)
|
|
394
|
+
is(o.msg, 'test')
|
|
395
|
+
ok(o.time)
|
|
396
|
+
console.info = info
|
|
397
|
+
}
|
|
398
|
+
const instance = require('../browser')({
|
|
399
|
+
browser: {
|
|
400
|
+
write: {
|
|
401
|
+
error (o) {
|
|
402
|
+
is(o.level, 50)
|
|
403
|
+
is(o.test, 'test')
|
|
404
|
+
ok(o.time)
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
})
|
|
409
|
+
instance.error({ test: 'test' })
|
|
410
|
+
instance.info('test')
|
|
411
|
+
|
|
412
|
+
end()
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
function levelTest (name) {
|
|
416
|
+
test(name + ' logs', ({ end, is }) => {
|
|
417
|
+
const msg = 'hello world'
|
|
418
|
+
sink(name, (args) => {
|
|
419
|
+
is(args[0], msg)
|
|
420
|
+
end()
|
|
421
|
+
})
|
|
422
|
+
bingo-logger({ level: name })[name](msg)
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
test('passing objects at level ' + name, ({ end, is }) => {
|
|
426
|
+
const msg = { hello: 'world' }
|
|
427
|
+
sink(name, (args) => {
|
|
428
|
+
is(args[0], msg)
|
|
429
|
+
end()
|
|
430
|
+
})
|
|
431
|
+
bingo-logger({ level: name })[name](msg)
|
|
432
|
+
})
|
|
433
|
+
|
|
434
|
+
test('passing an object and a string at level ' + name, ({ end, is }) => {
|
|
435
|
+
const a = { hello: 'world' }
|
|
436
|
+
const b = 'a string'
|
|
437
|
+
sink(name, (args) => {
|
|
438
|
+
is(args[0], a)
|
|
439
|
+
is(args[1], b)
|
|
440
|
+
end()
|
|
441
|
+
})
|
|
442
|
+
bingo-logger({ level: name })[name](a, b)
|
|
443
|
+
})
|
|
444
|
+
|
|
445
|
+
test('formatting logs as ' + name, ({ end, is }) => {
|
|
446
|
+
sink(name, (args) => {
|
|
447
|
+
is(args[0], 'hello %d')
|
|
448
|
+
is(args[1], 42)
|
|
449
|
+
end()
|
|
450
|
+
})
|
|
451
|
+
bingo-logger({ level: name })[name]('hello %d', 42)
|
|
452
|
+
})
|
|
453
|
+
|
|
454
|
+
test('passing error at level ' + name, ({ end, is }) => {
|
|
455
|
+
const err = new Error('myerror')
|
|
456
|
+
sink(name, (args) => {
|
|
457
|
+
is(args[0], err)
|
|
458
|
+
end()
|
|
459
|
+
})
|
|
460
|
+
bingo-logger({ level: name })[name](err)
|
|
461
|
+
})
|
|
462
|
+
|
|
463
|
+
test('passing error with a serializer at level ' + name, ({ end, is }) => {
|
|
464
|
+
// in browser - should have no effect (should not crash)
|
|
465
|
+
const err = new Error('myerror')
|
|
466
|
+
sink(name, (args) => {
|
|
467
|
+
is(args[0].err, err)
|
|
468
|
+
end()
|
|
469
|
+
})
|
|
470
|
+
const instance = bingo-logger({
|
|
471
|
+
level: name,
|
|
472
|
+
serializers: {
|
|
473
|
+
err: bingo-logger.stdSerializers.err
|
|
474
|
+
}
|
|
475
|
+
})
|
|
476
|
+
instance[name]({ err })
|
|
477
|
+
})
|
|
478
|
+
|
|
479
|
+
test('child logger for level ' + name, ({ end, is }) => {
|
|
480
|
+
const msg = 'hello world'
|
|
481
|
+
const parent = { hello: 'world' }
|
|
482
|
+
sink(name, (args) => {
|
|
483
|
+
is(args[0], parent)
|
|
484
|
+
is(args[1], msg)
|
|
485
|
+
end()
|
|
486
|
+
})
|
|
487
|
+
const instance = bingo-logger({ level: name })
|
|
488
|
+
const child = instance.child(parent)
|
|
489
|
+
child[name](msg)
|
|
490
|
+
})
|
|
491
|
+
|
|
492
|
+
test('child-child logger for level ' + name, ({ end, is }) => {
|
|
493
|
+
const msg = 'hello world'
|
|
494
|
+
const grandParent = { hello: 'world' }
|
|
495
|
+
const parent = { hello: 'you' }
|
|
496
|
+
sink(name, (args) => {
|
|
497
|
+
is(args[0], grandParent)
|
|
498
|
+
is(args[1], parent)
|
|
499
|
+
is(args[2], msg)
|
|
500
|
+
end()
|
|
501
|
+
})
|
|
502
|
+
const instance = bingo-logger({ level: name })
|
|
503
|
+
const child = instance.child(grandParent).child(parent)
|
|
504
|
+
child[name](msg)
|
|
505
|
+
})
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function consoleMethodTest (level, method) {
|
|
509
|
+
if (!method) method = level
|
|
510
|
+
test('bingo-logger().' + level + ' uses console.' + method, ({ end, is }) => {
|
|
511
|
+
sink(method, (args) => {
|
|
512
|
+
is(args[0], 'test')
|
|
513
|
+
end()
|
|
514
|
+
})
|
|
515
|
+
const instance = require('../browser')({ level })
|
|
516
|
+
instance[level]('test')
|
|
517
|
+
})
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function absentConsoleMethodTest (method, fallback) {
|
|
521
|
+
test('in absence of console.' + method + ', console.' + fallback + ' is used', ({ end, is }) => {
|
|
522
|
+
const fn = console[method]
|
|
523
|
+
console[method] = undefined
|
|
524
|
+
sink(fallback, function (args) {
|
|
525
|
+
is(args[0], 'test')
|
|
526
|
+
end()
|
|
527
|
+
console[method] = fn
|
|
528
|
+
})
|
|
529
|
+
const instance = require('../browser')({ level: method })
|
|
530
|
+
instance[method]('test')
|
|
531
|
+
})
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function isFunc (fn) { return typeof fn === 'function' }
|
|
535
|
+
function fnName (fn) {
|
|
536
|
+
const rx = /^\s*function\s*([^(]*)/i
|
|
537
|
+
const match = rx.exec(fn)
|
|
538
|
+
return match && match[1]
|
|
539
|
+
}
|
|
540
|
+
function sink (method, fn) {
|
|
541
|
+
if (method === 'fatal') method = 'error'
|
|
542
|
+
const orig = console[method]
|
|
543
|
+
console[method] = function () {
|
|
544
|
+
console[method] = orig
|
|
545
|
+
fn(Array.prototype.slice.call(arguments))
|
|
546
|
+
}
|
|
547
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('tap')
|
|
4
|
+
const { sink, once } = require('./helper')
|
|
5
|
+
const { PassThrough } = require('stream')
|
|
6
|
+
const bingo-logger = require('../')
|
|
7
|
+
|
|
8
|
+
test('Proxy and stream objects', async ({ equal }) => {
|
|
9
|
+
const s = new PassThrough()
|
|
10
|
+
s.resume()
|
|
11
|
+
s.write('', () => {})
|
|
12
|
+
const obj = { s, p: new Proxy({}, { get () { throw new Error('kaboom') } }) }
|
|
13
|
+
const stream = sink()
|
|
14
|
+
const instance = bingo-logger(stream)
|
|
15
|
+
instance.info({ obj })
|
|
16
|
+
|
|
17
|
+
const result = await once(stream, 'data')
|
|
18
|
+
|
|
19
|
+
equal(result.obj, '[unable to serialize, circular reference is too complex to analyze]')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('Proxy and stream objects', async ({ equal }) => {
|
|
23
|
+
const s = new PassThrough()
|
|
24
|
+
s.resume()
|
|
25
|
+
s.write('', () => {})
|
|
26
|
+
const obj = { s, p: new Proxy({}, { get () { throw new Error('kaboom') } }) }
|
|
27
|
+
const stream = sink()
|
|
28
|
+
const instance = bingo-logger(stream)
|
|
29
|
+
instance.info(obj)
|
|
30
|
+
|
|
31
|
+
const result = await once(stream, 'data')
|
|
32
|
+
|
|
33
|
+
equal(result.p, '[unable to serialize, circular reference is too complex to analyze]')
|
|
34
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('tap')
|
|
4
|
+
const writer = require('flush-write-stream')
|
|
5
|
+
const bingo-logger = require('../')
|
|
6
|
+
|
|
7
|
+
function capture () {
|
|
8
|
+
const ws = writer((chunk, enc, cb) => {
|
|
9
|
+
ws.data += chunk.toString()
|
|
10
|
+
cb()
|
|
11
|
+
})
|
|
12
|
+
ws.data = ''
|
|
13
|
+
return ws
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
test('bingo-logger uses LF by default', async ({ ok }) => {
|
|
17
|
+
const stream = capture()
|
|
18
|
+
const logger = bingo-logger(stream)
|
|
19
|
+
logger.info('foo')
|
|
20
|
+
logger.error('bar')
|
|
21
|
+
ok(/foo[^\r\n]+\n[^\r\n]+bar[^\r\n]+\n/.test(stream.data))
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('bingo-logger can log CRLF', async ({ ok }) => {
|
|
25
|
+
const stream = capture()
|
|
26
|
+
const logger = bingo-logger({
|
|
27
|
+
crlf: true
|
|
28
|
+
}, stream)
|
|
29
|
+
logger.info('foo')
|
|
30
|
+
logger.error('bar')
|
|
31
|
+
ok(/foo[^\n]+\r\n[^\n]+bar[^\n]+\r\n/.test(stream.data))
|
|
32
|
+
})
|