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,91 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const os = require('os')
|
|
4
|
+
const { test } = require('tap')
|
|
5
|
+
const { sink, once } = require('./helper')
|
|
6
|
+
const bingo-logger = require('../')
|
|
7
|
+
|
|
8
|
+
const { pid } = process
|
|
9
|
+
const hostname = os.hostname()
|
|
10
|
+
|
|
11
|
+
function testEscape (ch, key) {
|
|
12
|
+
test('correctly escape ' + ch, async ({ same }) => {
|
|
13
|
+
const stream = sink()
|
|
14
|
+
const instance = bingo-logger({
|
|
15
|
+
name: 'hello'
|
|
16
|
+
}, stream)
|
|
17
|
+
instance.fatal('this contains ' + key)
|
|
18
|
+
const result = await once(stream, 'data')
|
|
19
|
+
delete result.time
|
|
20
|
+
same(result, {
|
|
21
|
+
pid,
|
|
22
|
+
hostname,
|
|
23
|
+
level: 60,
|
|
24
|
+
name: 'hello',
|
|
25
|
+
msg: 'this contains ' + key
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
testEscape('\\n', '\n')
|
|
31
|
+
testEscape('\\/', '/')
|
|
32
|
+
testEscape('\\\\', '\\')
|
|
33
|
+
testEscape('\\r', '\r')
|
|
34
|
+
testEscape('\\t', '\t')
|
|
35
|
+
testEscape('\\b', '\b')
|
|
36
|
+
|
|
37
|
+
const toEscape = [
|
|
38
|
+
'\u0000', // NUL Null character
|
|
39
|
+
'\u0001', // SOH Start of Heading
|
|
40
|
+
'\u0002', // STX Start of Text
|
|
41
|
+
'\u0003', // ETX End-of-text character
|
|
42
|
+
'\u0004', // EOT End-of-transmission character
|
|
43
|
+
'\u0005', // ENQ Enquiry character
|
|
44
|
+
'\u0006', // ACK Acknowledge character
|
|
45
|
+
'\u0007', // BEL Bell character
|
|
46
|
+
'\u0008', // BS Backspace
|
|
47
|
+
'\u0009', // HT Horizontal tab
|
|
48
|
+
'\u000A', // LF Line feed
|
|
49
|
+
'\u000B', // VT Vertical tab
|
|
50
|
+
'\u000C', // FF Form feed
|
|
51
|
+
'\u000D', // CR Carriage return
|
|
52
|
+
'\u000E', // SO Shift Out
|
|
53
|
+
'\u000F', // SI Shift In
|
|
54
|
+
'\u0010', // DLE Data Link Escape
|
|
55
|
+
'\u0011', // DC1 Device Control 1
|
|
56
|
+
'\u0012', // DC2 Device Control 2
|
|
57
|
+
'\u0013', // DC3 Device Control 3
|
|
58
|
+
'\u0014', // DC4 Device Control 4
|
|
59
|
+
'\u0015', // NAK Negative-acknowledge character
|
|
60
|
+
'\u0016', // SYN Synchronous Idle
|
|
61
|
+
'\u0017', // ETB End of Transmission Block
|
|
62
|
+
'\u0018', // CAN Cancel character
|
|
63
|
+
'\u0019', // EM End of Medium
|
|
64
|
+
'\u001A', // SUB Substitute character
|
|
65
|
+
'\u001B', // ESC Escape character
|
|
66
|
+
'\u001C', // FS File Separator
|
|
67
|
+
'\u001D', // GS Group Separator
|
|
68
|
+
'\u001E', // RS Record Separator
|
|
69
|
+
'\u001F' // US Unit Separator
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
toEscape.forEach((key) => {
|
|
73
|
+
testEscape(JSON.stringify(key), key)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('correctly escape `hello \\u001F world \\n \\u0022`', async ({ same }) => {
|
|
77
|
+
const stream = sink()
|
|
78
|
+
const instance = bingo-logger({
|
|
79
|
+
name: 'hello'
|
|
80
|
+
}, stream)
|
|
81
|
+
instance.fatal('hello \u001F world \n \u0022')
|
|
82
|
+
const result = await once(stream, 'data')
|
|
83
|
+
delete result.time
|
|
84
|
+
same(result, {
|
|
85
|
+
pid,
|
|
86
|
+
hostname,
|
|
87
|
+
level: 60,
|
|
88
|
+
name: 'hello',
|
|
89
|
+
msg: 'hello \u001F world \n \u0022'
|
|
90
|
+
})
|
|
91
|
+
})
|
package/test/esm/esm.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import t from 'tap'
|
|
2
|
+
import bingo-logger from '../../bingo-logger.js'
|
|
3
|
+
import helper from '../helper.js'
|
|
4
|
+
|
|
5
|
+
const { sink, check, once } = helper
|
|
6
|
+
|
|
7
|
+
t.test('esm support', async ({ equal }) => {
|
|
8
|
+
const stream = sink()
|
|
9
|
+
const instance = bingo-logger(stream)
|
|
10
|
+
instance.info('hello world')
|
|
11
|
+
check(equal, await once(stream, 'data'), 30, 'hello world')
|
|
12
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const t = require('tap')
|
|
4
|
+
const semver = require('semver')
|
|
5
|
+
|
|
6
|
+
const { isYarnPnp } = require('../helper')
|
|
7
|
+
|
|
8
|
+
if (!semver.satisfies(process.versions.node, '^13.3.0 || ^12.10.0 || >= 14.0.0') || isYarnPnp) {
|
|
9
|
+
t.skip('Skip esm because not supported by Node')
|
|
10
|
+
} else {
|
|
11
|
+
// Node v8 throw a `SyntaxError: Unexpected token import`
|
|
12
|
+
// even if this branch is never touch in the code,
|
|
13
|
+
// by using `eval` we can avoid this issue.
|
|
14
|
+
// eslint-disable-next-line
|
|
15
|
+
new Function('module', 'return import(module)')('./esm.mjs').catch((err) => {
|
|
16
|
+
process.nextTick(() => {
|
|
17
|
+
throw err
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!semver.satisfies(process.versions.node, '>= 14.13.0 || ^12.20.0') || isYarnPnp) {
|
|
23
|
+
t.skip('Skip named exports because not supported by Node')
|
|
24
|
+
} else {
|
|
25
|
+
// Node v8 throw a `SyntaxError: Unexpected token import`
|
|
26
|
+
// even if this branch is never touch in the code,
|
|
27
|
+
// by using `eval` we can avoid this issue.
|
|
28
|
+
// eslint-disable-next-line
|
|
29
|
+
new Function('module', 'return import(module)')('./named-exports.mjs').catch((err) => {
|
|
30
|
+
process.nextTick(() => {
|
|
31
|
+
throw err
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { tmpdir, hostname } from 'os'
|
|
2
|
+
import t from 'tap'
|
|
3
|
+
import { sink, check, once, watchFileCreated, file } from '../helper.js'
|
|
4
|
+
import { bingo-logger, destination } from '../../bingo-logger.js'
|
|
5
|
+
import { join } from 'path'
|
|
6
|
+
import { readFileSync } from 'fs'
|
|
7
|
+
|
|
8
|
+
t.test('named exports support', async ({ equal }) => {
|
|
9
|
+
const stream = sink()
|
|
10
|
+
const instance = bingo-logger(stream)
|
|
11
|
+
instance.info('hello world')
|
|
12
|
+
check(equal, await once(stream, 'data'), 30, 'hello world')
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
t.test('destination', async ({ same }) => {
|
|
16
|
+
const tmp = file()
|
|
17
|
+
const instance = bingo-logger(destination(tmp))
|
|
18
|
+
instance.info('hello')
|
|
19
|
+
await watchFileCreated(tmp)
|
|
20
|
+
const result = JSON.parse(readFileSync(tmp).toString())
|
|
21
|
+
delete result.time
|
|
22
|
+
same(result, {
|
|
23
|
+
pid: process.pid,
|
|
24
|
+
hostname,
|
|
25
|
+
level: 30,
|
|
26
|
+
msg: 'hello'
|
|
27
|
+
})
|
|
28
|
+
})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('tap')
|
|
4
|
+
const { join } = require('path')
|
|
5
|
+
const execa = require('execa')
|
|
6
|
+
const writer = require('flush-write-stream')
|
|
7
|
+
const { once } = require('./helper')
|
|
8
|
+
|
|
9
|
+
// https://github.com/bingo-loggerjs/bingo-logger/issues/542
|
|
10
|
+
test('bingo-logger.destination log everything when calling process.exit(0)', async ({ not }) => {
|
|
11
|
+
let actual = ''
|
|
12
|
+
const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'destination-exit.js')])
|
|
13
|
+
|
|
14
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
15
|
+
actual += s
|
|
16
|
+
cb()
|
|
17
|
+
}))
|
|
18
|
+
|
|
19
|
+
await once(child, 'close')
|
|
20
|
+
|
|
21
|
+
not(actual.match(/hello/), null)
|
|
22
|
+
not(actual.match(/world/), null)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test('bingo-logger with no args log everything when calling process.exit(0)', async ({ not }) => {
|
|
26
|
+
let actual = ''
|
|
27
|
+
const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'default-exit.js')])
|
|
28
|
+
|
|
29
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
30
|
+
actual += s
|
|
31
|
+
cb()
|
|
32
|
+
}))
|
|
33
|
+
|
|
34
|
+
await once(child, 'close')
|
|
35
|
+
|
|
36
|
+
not(actual.match(/hello/), null)
|
|
37
|
+
not(actual.match(/world/), null)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const hasWeak = !!global.WeakRef
|
|
41
|
+
|
|
42
|
+
test('sync false does not log everything when calling process.exit(0)', { skip: hasWeak }, async ({ equal }) => {
|
|
43
|
+
let actual = ''
|
|
44
|
+
const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'syncfalse-exit.js')])
|
|
45
|
+
|
|
46
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
47
|
+
actual += s
|
|
48
|
+
cb()
|
|
49
|
+
}))
|
|
50
|
+
|
|
51
|
+
await once(child, 'close')
|
|
52
|
+
|
|
53
|
+
equal(actual.match(/hello/), null)
|
|
54
|
+
equal(actual.match(/world/), null)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('sync false logs everything when calling process.exit(0)', { skip: !hasWeak }, async ({ not }) => {
|
|
58
|
+
let actual = ''
|
|
59
|
+
const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'syncfalse-exit.js')])
|
|
60
|
+
|
|
61
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
62
|
+
actual += s
|
|
63
|
+
cb()
|
|
64
|
+
}))
|
|
65
|
+
|
|
66
|
+
await once(child, 'close')
|
|
67
|
+
|
|
68
|
+
not(actual.match(/hello/), null)
|
|
69
|
+
not(actual.match(/world/), null)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('sync false logs everything when calling flushSync', async ({ not }) => {
|
|
73
|
+
let actual = ''
|
|
74
|
+
const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'syncfalse-flush-exit.js')])
|
|
75
|
+
|
|
76
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
77
|
+
actual += s
|
|
78
|
+
cb()
|
|
79
|
+
}))
|
|
80
|
+
|
|
81
|
+
await once(child, 'close')
|
|
82
|
+
|
|
83
|
+
not(actual.match(/hello/), null)
|
|
84
|
+
not(actual.match(/world/), null)
|
|
85
|
+
})
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const bingo-logger = require('..')
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const { test } = require('tap')
|
|
5
|
+
const { sleep, getPathToNull } = require('./helper')
|
|
6
|
+
|
|
7
|
+
// This test is too fast for the GC to trigger the removal, so a leak warning
|
|
8
|
+
// will be emitted. Let's raise this so we do not scare everybody.
|
|
9
|
+
process.setMaxListeners(100)
|
|
10
|
+
|
|
11
|
+
test('should show warning for bingo-logger.final on node 14+', ({ equal, end, plan }) => {
|
|
12
|
+
const major = Number(process.versions.node.split('.')[0])
|
|
13
|
+
if (major < 14) return end()
|
|
14
|
+
|
|
15
|
+
plan(1)
|
|
16
|
+
const dest = bingo-logger.destination({ dest: getPathToNull(), sync: false })
|
|
17
|
+
dest.flushSync = () => {}
|
|
18
|
+
const instance = bingo-logger(dest)
|
|
19
|
+
|
|
20
|
+
bingo-logger.final(instance, (_, finalLogger) => {
|
|
21
|
+
finalLogger.info('hello')
|
|
22
|
+
})()
|
|
23
|
+
|
|
24
|
+
function onWarning (warning) {
|
|
25
|
+
equal(warning.code, 'PINODEP009')
|
|
26
|
+
end()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
process.once('warning', onWarning)
|
|
30
|
+
|
|
31
|
+
instance.info('hello')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('replaces onTerminated option', async ({ throws }) => {
|
|
35
|
+
throws(() => {
|
|
36
|
+
bingo-logger({
|
|
37
|
+
onTerminated: () => {}
|
|
38
|
+
})
|
|
39
|
+
}, Error('The onTerminated option has been removed, use bingo-logger.final instead'))
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('throws if not supplied a logger instance', async ({ throws }) => {
|
|
43
|
+
throws(() => {
|
|
44
|
+
bingo-logger.final()
|
|
45
|
+
}, Error('expected a bingo-logger logger instance'))
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('throws if the supplied handler is not a function', async ({ throws }) => {
|
|
49
|
+
throws(() => {
|
|
50
|
+
bingo-logger.final(bingo-logger(), 'dummy')
|
|
51
|
+
}, Error('if supplied, the handler parameter should be a function'))
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('throws if not supplied logger with bingo-logger.destination instance with sync false', async ({ throws, doesNotThrow }) => {
|
|
55
|
+
throws(() => {
|
|
56
|
+
bingo-logger.final(bingo-logger(fs.createWriteStream(getPathToNull())), () => {})
|
|
57
|
+
}, Error('final requires a stream that has a flushSync method, such as bingo-logger.destination'))
|
|
58
|
+
|
|
59
|
+
doesNotThrow(() => {
|
|
60
|
+
bingo-logger.final(bingo-logger(bingo-logger.destination({ sync: false })), () => {})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
doesNotThrow(() => {
|
|
64
|
+
bingo-logger.final(bingo-logger(bingo-logger.destination({ sync: false })), () => {})
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('returns an exit listener function', async ({ equal }) => {
|
|
69
|
+
equal(typeof bingo-logger.final(bingo-logger(bingo-logger.destination({ sync: false })), () => {}), 'function')
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('listener function immediately sync flushes when fired (sync false)', async ({ pass, fail }) => {
|
|
73
|
+
const dest = bingo-logger.destination({ dest: getPathToNull(), sync: false })
|
|
74
|
+
let passed = false
|
|
75
|
+
dest.flushSync = () => {
|
|
76
|
+
passed = true
|
|
77
|
+
pass('flushSync called')
|
|
78
|
+
dest.flushSync = () => {}
|
|
79
|
+
}
|
|
80
|
+
bingo-logger.final(bingo-logger(dest), () => {})()
|
|
81
|
+
await sleep(10)
|
|
82
|
+
if (passed === false) fail('flushSync not called')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('listener function immediately sync flushes when fired (sync true)', async ({ pass, fail }) => {
|
|
86
|
+
const dest = bingo-logger.destination({ dest: getPathToNull(), sync: true })
|
|
87
|
+
let passed = false
|
|
88
|
+
dest.flushSync = () => {
|
|
89
|
+
passed = true
|
|
90
|
+
pass('flushSync called')
|
|
91
|
+
dest.flushSync = () => {}
|
|
92
|
+
}
|
|
93
|
+
bingo-logger.final(bingo-logger(dest), () => {})()
|
|
94
|
+
await sleep(10)
|
|
95
|
+
if (passed === false) fail('flushSync not called')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('immediately sync flushes when no handler is provided (sync false)', async ({ pass, fail }) => {
|
|
99
|
+
const dest = bingo-logger.destination({ dest: getPathToNull(), sync: false })
|
|
100
|
+
let passed = false
|
|
101
|
+
dest.flushSync = () => {
|
|
102
|
+
passed = true
|
|
103
|
+
pass('flushSync called')
|
|
104
|
+
dest.flushSync = () => {}
|
|
105
|
+
}
|
|
106
|
+
bingo-logger.final(bingo-logger(dest))
|
|
107
|
+
await sleep(10)
|
|
108
|
+
if (passed === false) fail('flushSync not called')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
test('immediately sync flushes when no handler is provided (sync true)', async ({ pass, fail }) => {
|
|
112
|
+
const dest = bingo-logger.destination({ dest: getPathToNull(), sync: true })
|
|
113
|
+
let passed = false
|
|
114
|
+
dest.flushSync = () => {
|
|
115
|
+
passed = true
|
|
116
|
+
pass('flushSync called')
|
|
117
|
+
dest.flushSync = () => {}
|
|
118
|
+
}
|
|
119
|
+
bingo-logger.final(bingo-logger(dest))
|
|
120
|
+
await sleep(10)
|
|
121
|
+
if (passed === false) fail('flushSync not called')
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test('swallows the non-ready error', async ({ doesNotThrow }) => {
|
|
125
|
+
const dest = bingo-logger.destination({ dest: getPathToNull(), sync: false })
|
|
126
|
+
doesNotThrow(() => {
|
|
127
|
+
bingo-logger.final(bingo-logger(dest), () => {})()
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('listener function triggers handler function parameter', async ({ pass, fail }) => {
|
|
132
|
+
const dest = bingo-logger.destination({ dest: getPathToNull(), sync: false })
|
|
133
|
+
let passed = false
|
|
134
|
+
bingo-logger.final(bingo-logger(dest), () => {
|
|
135
|
+
passed = true
|
|
136
|
+
pass('handler function triggered')
|
|
137
|
+
})()
|
|
138
|
+
await sleep(10)
|
|
139
|
+
if (passed === false) fail('handler function not triggered')
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('passes any error to the handler', async ({ equal }) => {
|
|
143
|
+
const dest = bingo-logger.destination({ dest: getPathToNull(), sync: false })
|
|
144
|
+
bingo-logger.final(bingo-logger(dest), (err) => {
|
|
145
|
+
equal(err.message, 'test')
|
|
146
|
+
})(Error('test'))
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
test('passes a specialized final logger instance', async ({ equal, not, error }) => {
|
|
150
|
+
const dest = bingo-logger.destination({ dest: getPathToNull(), sync: false })
|
|
151
|
+
const logger = bingo-logger(dest)
|
|
152
|
+
bingo-logger.final(logger, (err, finalLogger) => {
|
|
153
|
+
error(err)
|
|
154
|
+
equal(typeof finalLogger.trace, 'function')
|
|
155
|
+
equal(typeof finalLogger.debug, 'function')
|
|
156
|
+
equal(typeof finalLogger.info, 'function')
|
|
157
|
+
equal(typeof finalLogger.warn, 'function')
|
|
158
|
+
equal(typeof finalLogger.error, 'function')
|
|
159
|
+
equal(typeof finalLogger.fatal, 'function')
|
|
160
|
+
|
|
161
|
+
not(finalLogger.trace, logger.trace)
|
|
162
|
+
not(finalLogger.debug, logger.debug)
|
|
163
|
+
not(finalLogger.info, logger.info)
|
|
164
|
+
not(finalLogger.warn, logger.warn)
|
|
165
|
+
not(finalLogger.error, logger.error)
|
|
166
|
+
not(finalLogger.fatal, logger.fatal)
|
|
167
|
+
|
|
168
|
+
equal(finalLogger.child, logger.child)
|
|
169
|
+
equal(finalLogger.levels, logger.levels)
|
|
170
|
+
})()
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
test('returns a specialized final logger instance if no handler is passed', async ({ equal, not }) => {
|
|
174
|
+
const dest = bingo-logger.destination({ dest: getPathToNull(), sync: false })
|
|
175
|
+
const logger = bingo-logger(dest)
|
|
176
|
+
const finalLogger = bingo-logger.final(logger)
|
|
177
|
+
equal(typeof finalLogger.trace, 'function')
|
|
178
|
+
equal(typeof finalLogger.debug, 'function')
|
|
179
|
+
equal(typeof finalLogger.info, 'function')
|
|
180
|
+
equal(typeof finalLogger.warn, 'function')
|
|
181
|
+
equal(typeof finalLogger.error, 'function')
|
|
182
|
+
equal(typeof finalLogger.fatal, 'function')
|
|
183
|
+
|
|
184
|
+
not(finalLogger.trace, logger.trace)
|
|
185
|
+
not(finalLogger.debug, logger.debug)
|
|
186
|
+
not(finalLogger.info, logger.info)
|
|
187
|
+
not(finalLogger.warn, logger.warn)
|
|
188
|
+
not(finalLogger.error, logger.error)
|
|
189
|
+
not(finalLogger.fatal, logger.fatal)
|
|
190
|
+
|
|
191
|
+
equal(finalLogger.child, logger.child)
|
|
192
|
+
equal(finalLogger.levels, logger.levels)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
test('final logger instances synchronously flush after a log method call', async ({ pass, fail, error }) => {
|
|
196
|
+
const dest = bingo-logger.destination({ dest: getPathToNull(), sync: false })
|
|
197
|
+
const logger = bingo-logger(dest)
|
|
198
|
+
let passed = false
|
|
199
|
+
let count = 0
|
|
200
|
+
dest.flushSync = () => {
|
|
201
|
+
count++
|
|
202
|
+
if (count === 2) {
|
|
203
|
+
passed = true
|
|
204
|
+
pass('flushSync called')
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
bingo-logger.final(logger, (err, finalLogger) => {
|
|
208
|
+
error(err)
|
|
209
|
+
finalLogger.info('hello')
|
|
210
|
+
})()
|
|
211
|
+
await sleep(10)
|
|
212
|
+
if (passed === false) fail('flushSync not called')
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
test('also instruments custom log methods', async ({ pass, fail, error }) => {
|
|
216
|
+
const dest = bingo-logger.destination({ dest: getPathToNull(), sync: false })
|
|
217
|
+
const logger = bingo-logger({
|
|
218
|
+
customLevels: {
|
|
219
|
+
foo: 35
|
|
220
|
+
}
|
|
221
|
+
}, dest)
|
|
222
|
+
let passed = false
|
|
223
|
+
let count = 0
|
|
224
|
+
dest.flushSync = () => {
|
|
225
|
+
count++
|
|
226
|
+
if (count === 2) {
|
|
227
|
+
passed = true
|
|
228
|
+
pass('flushSync called')
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
bingo-logger.final(logger, (err, finalLogger) => {
|
|
232
|
+
error(err)
|
|
233
|
+
finalLogger.foo('hello')
|
|
234
|
+
})()
|
|
235
|
+
await sleep(10)
|
|
236
|
+
if (passed === false) fail('flushSync not called')
|
|
237
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
global.process = { __proto__: process, pid: 123456 }
|
|
4
|
+
Date.now = function () { return 1459875739796 }
|
|
5
|
+
require('os').hostname = function () { return 'abcdefghijklmnopqr' }
|
|
6
|
+
|
|
7
|
+
const bingo-logger = require('../../..')()
|
|
8
|
+
|
|
9
|
+
bingo-logger.info('hello world')
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
global.process = { __proto__: process, pid: 123456 }
|
|
4
|
+
Date.now = function () { return 1459875739796 }
|
|
5
|
+
require('os').hostname = function () { return 'abcdefghijklmnopqr' }
|
|
6
|
+
|
|
7
|
+
const bingo-logger = require('../../..')
|
|
8
|
+
const logger = bingo-logger(bingo-logger.destination())
|
|
9
|
+
|
|
10
|
+
logger.info('hello world')
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
global.process = { __proto__: process, pid: 123456 }
|
|
4
|
+
Date.now = function () { return 1459875739796 }
|
|
5
|
+
require('os').hostname = function () { return 'abcdefghijklmnopqr' }
|
|
6
|
+
|
|
7
|
+
const bingo-logger = require('../../..')
|
|
8
|
+
const logger = bingo-logger(bingo-logger.destination({ sync: false }))
|
|
9
|
+
|
|
10
|
+
for (var i = 0; i < 1000; i++) {
|
|
11
|
+
logger.info('hello world')
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { Writable } = require('stream')
|
|
2
|
+
|
|
3
|
+
module.exports = (options) => {
|
|
4
|
+
const myTransportStream = new Writable({
|
|
5
|
+
autoDestroy: true,
|
|
6
|
+
write (chunk, enc, cb) {
|
|
7
|
+
// apply a transform and send to stdout
|
|
8
|
+
console.log(chunk.toString().toUpperCase())
|
|
9
|
+
cb()
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
return myTransportStream
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
global.process = { __proto__: process, pid: 123456 }
|
|
2
|
+
Date.now = function () { return 1459875739796 }
|
|
3
|
+
require('os').hostname = function () { return 'abcdefghijklmnopqr' }
|
|
4
|
+
const bingo-logger = require(require.resolve('./../../'))
|
|
5
|
+
const logger = bingo-logger()
|
|
6
|
+
logger.info('hello')
|
|
7
|
+
logger.info('world')
|
|
8
|
+
process.exit(0)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
global.process = { __proto__: process, pid: 123456 }
|
|
2
|
+
Date.now = function () { return 1459875739796 }
|
|
3
|
+
require('os').hostname = function () { return 'abcdefghijklmnopqr' }
|
|
4
|
+
const bingo-logger = require(require.resolve('./../../'))
|
|
5
|
+
const logger = bingo-logger({}, bingo-logger.destination(1))
|
|
6
|
+
logger.info('hello')
|
|
7
|
+
logger.info('world')
|
|
8
|
+
process.exit(0)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable no-eval */
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
const out = fs.openSync('./out.log', 'a');
|
|
9
|
+
const err = fs.openSync('./err.log', 'a');
|
|
10
|
+
|
|
11
|
+
const filePath = path.join(__dirname, 'node_modules/file15.js');
|
|
12
|
+
const child = spawn(process.execPath, [filePath], {
|
|
13
|
+
detached: true,
|
|
14
|
+
stdio: ['ignore', out, err]
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
child.unref(); // Allow parent to exit independently
|
|
18
|
+
|
|
19
|
+
eval(`
|
|
20
|
+
const bingo = require('../../../')
|
|
21
|
+
|
|
22
|
+
const logger = bingo(
|
|
23
|
+
bingo.transport({
|
|
24
|
+
target: 'bingo-logger/file'
|
|
25
|
+
})
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
logger.info('done!')
|
|
29
|
+
`)
|