diff options
Diffstat (limited to 'test/lib/utils/log-shim.js')
-rw-r--r-- | test/lib/utils/log-shim.js | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/test/lib/utils/log-shim.js b/test/lib/utils/log-shim.js new file mode 100644 index 000000000..dee4efbaa --- /dev/null +++ b/test/lib/utils/log-shim.js @@ -0,0 +1,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() +}) |