Welcome to mirror list, hosted at ThFree Co, Russian Federation.

proc-log-listener.js « utils « lib « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2c1009503762d546038c86d0a877878306d555f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const t = require('tap')
const requireInject = require('require-inject')
const { inspect } = require('util')

const logs = []
const npmlog = {
  warn: (...args) => logs.push(['warn', ...args]),
  verbose: (...args) => logs.push(['verbose', ...args]),
}

requireInject('../../../lib/utils/proc-log-listener.js', {
  npmlog,
})()

process.emit('log', 'warn', 'hello', 'i am a warning')
t.strictSame(logs, [['warn', 'hello', 'i am a warning']])
logs.length = 0

const nopeError = new Error('nope')
npmlog.warn = () => {
  throw nopeError
}

process.emit('log', 'warn', 'fail')
t.strictSame(logs, [[
  'verbose',
  `attempt to log ${inspect(['warn', 'fail'])} crashed`,
  nopeError,
]])
logs.length = 0

npmlog.verbose = () => {
  throw nopeError
}
const consoleErrors = []
console.error = (...args) => consoleErrors.push(args)
process.emit('log', 'warn', 'fail2')
t.strictSame(logs, [])
t.strictSame(consoleErrors, [[
  `attempt to log ${inspect(['warn', 'fail2'])} crashed`,
  nopeError,
]])