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

log-shim.js « utils « lib « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dee4efbaa4552dad4e413890754eef4d061fad3c (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const t = require('tap')

const makeShim = (mocks) => t.mock('../../../lib/utils/log-shim.js', mocks)

const loggers = [
  'notice',
  'error',
  'warn',
  'info',
  'verbose',
  'http',
  'silly',
  'pause',
  'resume',
]

t.test('has properties', (t) => {
  const shim = makeShim()

  t.match(shim, {
    level: String,
    levels: {},
    gauge: {},
    stream: {},
    heading: undefined,
    enableColor: Function,
    disableColor: Function,
    enableUnicode: Function,
    disableUnicode: Function,
    enableProgress: Function,
    disableProgress: Function,
    ...loggers.reduce((acc, l) => {
      acc[l] = Function
      return acc
    }, {}),
  })

  t.match(Object.keys(shim).sort(), [
    'level',
    'heading',
    'levels',
    'gauge',
    'stream',
    'tracker',
    'useColor',
    'enableColor',
    'disableColor',
    'enableUnicode',
    'disableUnicode',
    'enableProgress',
    'disableProgress',
    'progressEnabled',
    'clearProgress',
    'showProgress',
    'newItem',
    'newGroup',
    ...loggers,
  ].sort())

  t.end()
})

t.test('works with npmlog/proclog proxy', t => {
  const procLog = { silly: () => 'SILLY' }
  const npmlog = { level: 'woo', enableColor: () => true }
  const shim = makeShim({ npmlog, 'proc-log': procLog })

  t.equal(shim.level, 'woo', 'can get a property')

  npmlog.level = 'hey'
  t.strictSame(
    [shim.level, npmlog.level],
    ['hey', 'hey'],
    'can get a property after update on npmlog'
  )

  shim.level = 'test'
  t.strictSame(
    [shim.level, npmlog.level],
    ['test', 'test'],
    'can get a property after update on shim'
  )

  t.ok(shim.enableColor(), 'can call method on shim to call npmlog')
  t.equal(shim.silly(), 'SILLY', 'can call method on proclog')
  t.notOk(shim.LEVELS, 'only includes levels from npmlog')
  t.throws(() => shim.gauge = 100, 'cant set getters properies')

  t.end()
})

t.test('works with npmlog/proclog proxy', t => {
  const shim = makeShim()

  loggers.forEach((k) => {
    t.doesNotThrow(() => shim[k]('test'))
  })

  t.end()
})