node-nvm-ssh 0.0.1-security → 1.0.1
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 node-nvm-ssh might be problematic. Click here for more details.
- package/LICENSE +24 -0
- package/README.md +111 -3
- 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 +128 -3
- 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,355 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
/* eslint no-prototype-builtins: 0 */
|
|
3
|
+
|
|
4
|
+
const { hostname } = require('os')
|
|
5
|
+
const { join } = require('path')
|
|
6
|
+
const { readFile } = require('fs').promises
|
|
7
|
+
const { test } = require('tap')
|
|
8
|
+
const { sink, once, watchFileCreated, file } = require('./helper')
|
|
9
|
+
const bingo-logger = require('../')
|
|
10
|
+
|
|
11
|
+
test('level formatter', async ({ match }) => {
|
|
12
|
+
const stream = sink()
|
|
13
|
+
const logger = bingo-logger({
|
|
14
|
+
formatters: {
|
|
15
|
+
level (label, number) {
|
|
16
|
+
return {
|
|
17
|
+
log: {
|
|
18
|
+
level: label
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}, stream)
|
|
24
|
+
|
|
25
|
+
const o = once(stream, 'data')
|
|
26
|
+
logger.info('hello world')
|
|
27
|
+
match(await o, {
|
|
28
|
+
log: {
|
|
29
|
+
level: 'info'
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('bindings formatter', async ({ match }) => {
|
|
35
|
+
const stream = sink()
|
|
36
|
+
const logger = bingo-logger({
|
|
37
|
+
formatters: {
|
|
38
|
+
bindings (bindings) {
|
|
39
|
+
return {
|
|
40
|
+
process: {
|
|
41
|
+
pid: bindings.pid
|
|
42
|
+
},
|
|
43
|
+
host: {
|
|
44
|
+
name: bindings.hostname
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, stream)
|
|
50
|
+
|
|
51
|
+
const o = once(stream, 'data')
|
|
52
|
+
logger.info('hello world')
|
|
53
|
+
match(await o, {
|
|
54
|
+
process: {
|
|
55
|
+
pid: process.pid
|
|
56
|
+
},
|
|
57
|
+
host: {
|
|
58
|
+
name: hostname()
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('no bindings formatter', async ({ match, notOk }) => {
|
|
64
|
+
const stream = sink()
|
|
65
|
+
const logger = bingo-logger({
|
|
66
|
+
formatters: {
|
|
67
|
+
bindings (bindings) {
|
|
68
|
+
return null
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}, stream)
|
|
72
|
+
|
|
73
|
+
const o = once(stream, 'data')
|
|
74
|
+
logger.info('hello world')
|
|
75
|
+
const log = await o
|
|
76
|
+
notOk(log.hasOwnProperty('pid'))
|
|
77
|
+
notOk(log.hasOwnProperty('hostname'))
|
|
78
|
+
match(log, { msg: 'hello world' })
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('log formatter', async ({ match, equal }) => {
|
|
82
|
+
const stream = sink()
|
|
83
|
+
const logger = bingo-logger({
|
|
84
|
+
formatters: {
|
|
85
|
+
log (obj) {
|
|
86
|
+
equal(obj.hasOwnProperty('msg'), false)
|
|
87
|
+
return { hello: 'world', ...obj }
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}, stream)
|
|
91
|
+
|
|
92
|
+
const o = once(stream, 'data')
|
|
93
|
+
logger.info({ foo: 'bar', nested: { object: true } }, 'hello world')
|
|
94
|
+
match(await o, {
|
|
95
|
+
hello: 'world',
|
|
96
|
+
foo: 'bar',
|
|
97
|
+
nested: { object: true }
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('Formatters combined', async ({ match }) => {
|
|
102
|
+
const stream = sink()
|
|
103
|
+
const logger = bingo-logger({
|
|
104
|
+
formatters: {
|
|
105
|
+
level (label, number) {
|
|
106
|
+
return {
|
|
107
|
+
log: {
|
|
108
|
+
level: label
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
bindings (bindings) {
|
|
113
|
+
return {
|
|
114
|
+
process: {
|
|
115
|
+
pid: bindings.pid
|
|
116
|
+
},
|
|
117
|
+
host: {
|
|
118
|
+
name: bindings.hostname
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
log (obj) {
|
|
123
|
+
return { hello: 'world', ...obj }
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}, stream)
|
|
127
|
+
|
|
128
|
+
const o = once(stream, 'data')
|
|
129
|
+
logger.info({ foo: 'bar', nested: { object: true } }, 'hello world')
|
|
130
|
+
match(await o, {
|
|
131
|
+
log: {
|
|
132
|
+
level: 'info'
|
|
133
|
+
},
|
|
134
|
+
process: {
|
|
135
|
+
pid: process.pid
|
|
136
|
+
},
|
|
137
|
+
host: {
|
|
138
|
+
name: hostname()
|
|
139
|
+
},
|
|
140
|
+
hello: 'world',
|
|
141
|
+
foo: 'bar',
|
|
142
|
+
nested: { object: true }
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
test('Formatters in child logger', async ({ match }) => {
|
|
147
|
+
const stream = sink()
|
|
148
|
+
const logger = bingo-logger({
|
|
149
|
+
formatters: {
|
|
150
|
+
level (label, number) {
|
|
151
|
+
return {
|
|
152
|
+
log: {
|
|
153
|
+
level: label
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
bindings (bindings) {
|
|
158
|
+
return {
|
|
159
|
+
process: {
|
|
160
|
+
pid: bindings.pid
|
|
161
|
+
},
|
|
162
|
+
host: {
|
|
163
|
+
name: bindings.hostname
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
log (obj) {
|
|
168
|
+
return { hello: 'world', ...obj }
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}, stream)
|
|
172
|
+
|
|
173
|
+
const child = logger.child({
|
|
174
|
+
foo: 'bar',
|
|
175
|
+
nested: { object: true }
|
|
176
|
+
}, {
|
|
177
|
+
formatters: {
|
|
178
|
+
bindings (bindings) {
|
|
179
|
+
return { ...bindings, faz: 'baz' }
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
const o = once(stream, 'data')
|
|
185
|
+
child.info('hello world')
|
|
186
|
+
match(await o, {
|
|
187
|
+
log: {
|
|
188
|
+
level: 'info'
|
|
189
|
+
},
|
|
190
|
+
process: {
|
|
191
|
+
pid: process.pid
|
|
192
|
+
},
|
|
193
|
+
host: {
|
|
194
|
+
name: hostname()
|
|
195
|
+
},
|
|
196
|
+
hello: 'world',
|
|
197
|
+
foo: 'bar',
|
|
198
|
+
nested: { object: true },
|
|
199
|
+
faz: 'baz'
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
test('Formatters without bindings in child logger', async ({ match }) => {
|
|
204
|
+
const stream = sink()
|
|
205
|
+
const logger = bingo-logger({
|
|
206
|
+
formatters: {
|
|
207
|
+
level (label, number) {
|
|
208
|
+
return {
|
|
209
|
+
log: {
|
|
210
|
+
level: label
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
bindings (bindings) {
|
|
215
|
+
return {
|
|
216
|
+
process: {
|
|
217
|
+
pid: bindings.pid
|
|
218
|
+
},
|
|
219
|
+
host: {
|
|
220
|
+
name: bindings.hostname
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
log (obj) {
|
|
225
|
+
return { hello: 'world', ...obj }
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}, stream)
|
|
229
|
+
|
|
230
|
+
const child = logger.child({
|
|
231
|
+
foo: 'bar',
|
|
232
|
+
nested: { object: true }
|
|
233
|
+
}, {
|
|
234
|
+
formatters: {
|
|
235
|
+
log (obj) {
|
|
236
|
+
return { other: 'stuff', ...obj }
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
const o = once(stream, 'data')
|
|
242
|
+
child.info('hello world')
|
|
243
|
+
match(await o, {
|
|
244
|
+
log: {
|
|
245
|
+
level: 'info'
|
|
246
|
+
},
|
|
247
|
+
process: {
|
|
248
|
+
pid: process.pid
|
|
249
|
+
},
|
|
250
|
+
host: {
|
|
251
|
+
name: hostname()
|
|
252
|
+
},
|
|
253
|
+
foo: 'bar',
|
|
254
|
+
other: 'stuff',
|
|
255
|
+
nested: { object: true }
|
|
256
|
+
})
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
test('elastic common schema format', async ({ match, type }) => {
|
|
260
|
+
const stream = sink()
|
|
261
|
+
const ecs = {
|
|
262
|
+
formatters: {
|
|
263
|
+
level (label, number) {
|
|
264
|
+
return {
|
|
265
|
+
log: {
|
|
266
|
+
level: label,
|
|
267
|
+
logger: 'bingo-logger'
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
bindings (bindings) {
|
|
272
|
+
return {
|
|
273
|
+
process: {
|
|
274
|
+
pid: bindings.pid
|
|
275
|
+
},
|
|
276
|
+
host: {
|
|
277
|
+
name: bindings.hostname
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
log (obj) {
|
|
282
|
+
return { ecs: { version: '1.4.0' }, ...obj }
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
messageKey: 'message',
|
|
286
|
+
timestamp: () => `,"@timestamp":"${new Date(Date.now()).toISOString()}"`
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const logger = bingo-logger({ ...ecs }, stream)
|
|
290
|
+
|
|
291
|
+
const o = once(stream, 'data')
|
|
292
|
+
logger.info({ foo: 'bar' }, 'hello world')
|
|
293
|
+
const log = await o
|
|
294
|
+
type(log['@timestamp'], 'string')
|
|
295
|
+
match(log, {
|
|
296
|
+
log: { level: 'info', logger: 'bingo-logger' },
|
|
297
|
+
process: { pid: process.pid },
|
|
298
|
+
host: { name: hostname() },
|
|
299
|
+
ecs: { version: '1.4.0' },
|
|
300
|
+
foo: 'bar',
|
|
301
|
+
message: 'hello world'
|
|
302
|
+
})
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
test('formatter with transport', async ({ match, equal }) => {
|
|
306
|
+
const destination = file()
|
|
307
|
+
const logger = bingo-logger({
|
|
308
|
+
formatters: {
|
|
309
|
+
log (obj) {
|
|
310
|
+
equal(obj.hasOwnProperty('msg'), false)
|
|
311
|
+
return { hello: 'world', ...obj }
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
transport: {
|
|
315
|
+
targets: [
|
|
316
|
+
{
|
|
317
|
+
target: join(__dirname, 'fixtures', 'to-file-transport.js'),
|
|
318
|
+
options: { destination }
|
|
319
|
+
}
|
|
320
|
+
]
|
|
321
|
+
}
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
logger.info({ foo: 'bar', nested: { object: true } }, 'hello world')
|
|
325
|
+
await watchFileCreated(destination)
|
|
326
|
+
const result = JSON.parse(await readFile(destination))
|
|
327
|
+
delete result.time
|
|
328
|
+
match(result, {
|
|
329
|
+
hello: 'world',
|
|
330
|
+
foo: 'bar',
|
|
331
|
+
nested: { object: true }
|
|
332
|
+
})
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
test('throws when custom level formatter is used with transport.targets', async ({ throws }) => {
|
|
336
|
+
throws(() => {
|
|
337
|
+
bingo-logger({
|
|
338
|
+
formatters: {
|
|
339
|
+
level (label) {
|
|
340
|
+
return label
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
transport: {
|
|
344
|
+
targets: [
|
|
345
|
+
{
|
|
346
|
+
target: 'bingo-logger/file',
|
|
347
|
+
options: { destination: 'foo.log' }
|
|
348
|
+
}
|
|
349
|
+
]
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
)
|
|
353
|
+
},
|
|
354
|
+
Error('option.transport.targets do not allow custom level formatters'))
|
|
355
|
+
})
|
package/test/helper.d.ts
ADDED
package/test/helper.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const crypto = require('crypto')
|
|
4
|
+
const os = require('os')
|
|
5
|
+
const writer = require('flush-write-stream')
|
|
6
|
+
const split = require('split2')
|
|
7
|
+
const { existsSync, readFileSync, statSync, unlinkSync } = require('fs')
|
|
8
|
+
const pid = process.pid
|
|
9
|
+
const hostname = os.hostname()
|
|
10
|
+
const t = require('tap')
|
|
11
|
+
const { join } = require('path')
|
|
12
|
+
const { tmpdir } = os
|
|
13
|
+
|
|
14
|
+
const isWin = process.platform === 'win32'
|
|
15
|
+
const isYarnPnp = process.versions.pnp !== undefined
|
|
16
|
+
|
|
17
|
+
function getPathToNull () {
|
|
18
|
+
return isWin ? '\\\\.\\NUL' : '/dev/null'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function once (emitter, name) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
if (name !== 'error') emitter.once('error', reject)
|
|
24
|
+
emitter.once(name, (...args) => {
|
|
25
|
+
emitter.removeListener('error', reject)
|
|
26
|
+
resolve(...args)
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function sink (func) {
|
|
32
|
+
const result = split((data) => {
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(data)
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.log(err)
|
|
37
|
+
console.log(data)
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
if (func) result.pipe(writer.obj(func))
|
|
41
|
+
return result
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function check (is, chunk, level, msg) {
|
|
45
|
+
is(new Date(chunk.time) <= new Date(), true, 'time is greater than Date.now()')
|
|
46
|
+
delete chunk.time
|
|
47
|
+
is(chunk.pid, pid)
|
|
48
|
+
is(chunk.hostname, hostname)
|
|
49
|
+
is(chunk.level, level)
|
|
50
|
+
is(chunk.msg, msg)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function sleep (ms) {
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
setTimeout(resolve, ms)
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function watchFileCreated (filename) {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const TIMEOUT = process.env.PINO_TEST_WAIT_WATCHFILE_TIMEOUT || 10000
|
|
62
|
+
const INTERVAL = 100
|
|
63
|
+
const threshold = TIMEOUT / INTERVAL
|
|
64
|
+
let counter = 0
|
|
65
|
+
const interval = setInterval(() => {
|
|
66
|
+
const exists = existsSync(filename)
|
|
67
|
+
// On some CI runs file is created but not filled
|
|
68
|
+
if (exists && statSync(filename).size !== 0) {
|
|
69
|
+
clearInterval(interval)
|
|
70
|
+
resolve()
|
|
71
|
+
} else if (counter <= threshold) {
|
|
72
|
+
counter++
|
|
73
|
+
} else {
|
|
74
|
+
clearInterval(interval)
|
|
75
|
+
reject(new Error(
|
|
76
|
+
`${filename} hasn't been created within ${TIMEOUT} ms. ` +
|
|
77
|
+
(exists ? 'File exist, but still empty.' : 'File not yet created.')
|
|
78
|
+
))
|
|
79
|
+
}
|
|
80
|
+
}, INTERVAL)
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function watchForWrite (filename, testString) {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
const TIMEOUT = process.env.PINO_TEST_WAIT_WRITE_TIMEOUT || 10000
|
|
87
|
+
const INTERVAL = 100
|
|
88
|
+
const threshold = TIMEOUT / INTERVAL
|
|
89
|
+
let counter = 0
|
|
90
|
+
const interval = setInterval(() => {
|
|
91
|
+
if (readFileSync(filename).includes(testString)) {
|
|
92
|
+
clearInterval(interval)
|
|
93
|
+
resolve()
|
|
94
|
+
} else if (counter <= threshold) {
|
|
95
|
+
counter++
|
|
96
|
+
} else {
|
|
97
|
+
clearInterval(interval)
|
|
98
|
+
reject(new Error(`'${testString}' hasn't been written to ${filename} within ${TIMEOUT} ms.`))
|
|
99
|
+
}
|
|
100
|
+
}, INTERVAL)
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let files = []
|
|
105
|
+
|
|
106
|
+
function file () {
|
|
107
|
+
const hash = crypto.randomBytes(12).toString('hex')
|
|
108
|
+
const file = join(tmpdir(), `bingo-logger-${pid}-${hash}`)
|
|
109
|
+
files.push(file)
|
|
110
|
+
return file
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
process.on('beforeExit', () => {
|
|
114
|
+
if (files.length === 0) return
|
|
115
|
+
t.comment('unlink files')
|
|
116
|
+
for (const file of files) {
|
|
117
|
+
try {
|
|
118
|
+
t.comment(`unliking ${file}`)
|
|
119
|
+
unlinkSync(file)
|
|
120
|
+
} catch (e) {
|
|
121
|
+
console.log(e)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
files = []
|
|
125
|
+
t.comment('unlink completed')
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
module.exports = { getPathToNull, sink, check, once, sleep, watchFileCreated, watchForWrite, isWin, isYarnPnp, file }
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const tap = require('tap')
|
|
4
|
+
const { sink, once } = require('./helper')
|
|
5
|
+
const bingo-logger = require('../')
|
|
6
|
+
|
|
7
|
+
tap.test('log method hook', t => {
|
|
8
|
+
t.test('gets invoked', async t => {
|
|
9
|
+
t.plan(8)
|
|
10
|
+
|
|
11
|
+
const stream = sink()
|
|
12
|
+
const logger = bingo-logger({
|
|
13
|
+
hooks: {
|
|
14
|
+
logMethod (args, method, level) {
|
|
15
|
+
t.type(args, Array)
|
|
16
|
+
t.type(level, 'number')
|
|
17
|
+
t.equal(args.length, 3)
|
|
18
|
+
t.equal(level, this.levels.values.info)
|
|
19
|
+
t.same(args, ['a', 'b', 'c'])
|
|
20
|
+
|
|
21
|
+
t.type(method, Function)
|
|
22
|
+
t.equal(method.name, 'LOG')
|
|
23
|
+
|
|
24
|
+
method.apply(this, [args.join('-')])
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}, stream)
|
|
28
|
+
|
|
29
|
+
const o = once(stream, 'data')
|
|
30
|
+
logger.info('a', 'b', 'c')
|
|
31
|
+
t.match(await o, { msg: 'a-b-c' })
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
t.test('fatal method invokes hook', async t => {
|
|
35
|
+
t.plan(2)
|
|
36
|
+
|
|
37
|
+
const stream = sink()
|
|
38
|
+
const logger = bingo-logger({
|
|
39
|
+
hooks: {
|
|
40
|
+
logMethod (args, method) {
|
|
41
|
+
t.pass()
|
|
42
|
+
method.apply(this, [args.join('-')])
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}, stream)
|
|
46
|
+
|
|
47
|
+
const o = once(stream, 'data')
|
|
48
|
+
logger.fatal('a')
|
|
49
|
+
t.match(await o, { msg: 'a' })
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
t.test('children get the hook', async t => {
|
|
53
|
+
t.plan(4)
|
|
54
|
+
|
|
55
|
+
const stream = sink()
|
|
56
|
+
const root = bingo-logger({
|
|
57
|
+
hooks: {
|
|
58
|
+
logMethod (args, method) {
|
|
59
|
+
t.pass()
|
|
60
|
+
method.apply(this, [args.join('-')])
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}, stream)
|
|
64
|
+
const child = root.child({ child: 'one' })
|
|
65
|
+
const grandchild = child.child({ child: 'two' })
|
|
66
|
+
|
|
67
|
+
let o = once(stream, 'data')
|
|
68
|
+
child.info('a', 'b')
|
|
69
|
+
t.match(await o, { msg: 'a-b' })
|
|
70
|
+
|
|
71
|
+
o = once(stream, 'data')
|
|
72
|
+
grandchild.info('c', 'd')
|
|
73
|
+
t.match(await o, { msg: 'c-d' })
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
t.test('get log level', async t => {
|
|
77
|
+
t.plan(3)
|
|
78
|
+
|
|
79
|
+
const stream = sink()
|
|
80
|
+
const logger = bingo-logger({
|
|
81
|
+
hooks: {
|
|
82
|
+
logMethod (args, method, level) {
|
|
83
|
+
t.type(level, 'number')
|
|
84
|
+
t.equal(level, this.levels.values.error)
|
|
85
|
+
|
|
86
|
+
method.apply(this, [args.join('-')])
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, stream)
|
|
90
|
+
|
|
91
|
+
const o = once(stream, 'data')
|
|
92
|
+
logger.error('a')
|
|
93
|
+
t.match(await o, { msg: 'a' })
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
t.end()
|
|
97
|
+
})
|