1const t = require('tap')
2const tmock = require('../../fixtures/tmock')
3
4const makeShim = (mocks) => tmock(t, '{LIB}/utils/log-shim.js', mocks)
5
6const loggers = [
7  'notice',
8  'error',
9  'warn',
10  'info',
11  'verbose',
12  'http',
13  'silly',
14  'pause',
15  'resume',
16]
17
18t.test('has properties', (t) => {
19  const shim = makeShim()
20
21  t.match(shim, {
22    level: String,
23    levels: {},
24    gauge: {},
25    stream: {},
26    heading: undefined,
27    enableColor: Function,
28    disableColor: Function,
29    enableUnicode: Function,
30    disableUnicode: Function,
31    enableProgress: Function,
32    disableProgress: Function,
33    ...loggers.reduce((acc, l) => {
34      acc[l] = Function
35      return acc
36    }, {}),
37  })
38
39  t.match(Object.keys(shim).sort(), [
40    'level',
41    'heading',
42    'levels',
43    'gauge',
44    'stream',
45    'tracker',
46    'useColor',
47    'enableColor',
48    'disableColor',
49    'enableUnicode',
50    'disableUnicode',
51    'enableProgress',
52    'disableProgress',
53    'progressEnabled',
54    'clearProgress',
55    'showProgress',
56    'newItem',
57    'newGroup',
58    ...loggers,
59  ].sort())
60
61  t.end()
62})
63
64t.test('works with npmlog/proclog proxy', t => {
65  const procLog = { silly: () => 'SILLY' }
66  const npmlog = { level: 'woo', enableColor: () => true }
67  const shim = makeShim({ npmlog, 'proc-log': procLog })
68
69  t.equal(shim.level, 'woo', 'can get a property')
70
71  npmlog.level = 'hey'
72  t.strictSame(
73    [shim.level, npmlog.level],
74    ['hey', 'hey'],
75    'can get a property after update on npmlog'
76  )
77
78  shim.level = 'test'
79  t.strictSame(
80    [shim.level, npmlog.level],
81    ['test', 'test'],
82    'can get a property after update on shim'
83  )
84
85  t.ok(shim.enableColor(), 'can call method on shim to call npmlog')
86  t.equal(shim.silly(), 'SILLY', 'can call method on proclog')
87  t.notOk(shim.LEVELS, 'only includes levels from npmlog')
88  t.throws(() => shim.gauge = 100, 'cant set getters properies')
89
90  t.end()
91})
92
93t.test('works with npmlog/proclog proxy', t => {
94  const shim = makeShim()
95
96  loggers.forEach((k) => {
97    t.doesNotThrow(() => shim[k]('test'))
98  })
99
100  t.end()
101})
102