11cb0ef41Sopenharmony_ciconst t = require('tap') 21cb0ef41Sopenharmony_ciconst tmock = require('../../fixtures/tmock') 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst makeShim = (mocks) => tmock(t, '{LIB}/utils/log-shim.js', mocks) 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst loggers = [ 71cb0ef41Sopenharmony_ci 'notice', 81cb0ef41Sopenharmony_ci 'error', 91cb0ef41Sopenharmony_ci 'warn', 101cb0ef41Sopenharmony_ci 'info', 111cb0ef41Sopenharmony_ci 'verbose', 121cb0ef41Sopenharmony_ci 'http', 131cb0ef41Sopenharmony_ci 'silly', 141cb0ef41Sopenharmony_ci 'pause', 151cb0ef41Sopenharmony_ci 'resume', 161cb0ef41Sopenharmony_ci] 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cit.test('has properties', (t) => { 191cb0ef41Sopenharmony_ci const shim = makeShim() 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci t.match(shim, { 221cb0ef41Sopenharmony_ci level: String, 231cb0ef41Sopenharmony_ci levels: {}, 241cb0ef41Sopenharmony_ci gauge: {}, 251cb0ef41Sopenharmony_ci stream: {}, 261cb0ef41Sopenharmony_ci heading: undefined, 271cb0ef41Sopenharmony_ci enableColor: Function, 281cb0ef41Sopenharmony_ci disableColor: Function, 291cb0ef41Sopenharmony_ci enableUnicode: Function, 301cb0ef41Sopenharmony_ci disableUnicode: Function, 311cb0ef41Sopenharmony_ci enableProgress: Function, 321cb0ef41Sopenharmony_ci disableProgress: Function, 331cb0ef41Sopenharmony_ci ...loggers.reduce((acc, l) => { 341cb0ef41Sopenharmony_ci acc[l] = Function 351cb0ef41Sopenharmony_ci return acc 361cb0ef41Sopenharmony_ci }, {}), 371cb0ef41Sopenharmony_ci }) 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci t.match(Object.keys(shim).sort(), [ 401cb0ef41Sopenharmony_ci 'level', 411cb0ef41Sopenharmony_ci 'heading', 421cb0ef41Sopenharmony_ci 'levels', 431cb0ef41Sopenharmony_ci 'gauge', 441cb0ef41Sopenharmony_ci 'stream', 451cb0ef41Sopenharmony_ci 'tracker', 461cb0ef41Sopenharmony_ci 'useColor', 471cb0ef41Sopenharmony_ci 'enableColor', 481cb0ef41Sopenharmony_ci 'disableColor', 491cb0ef41Sopenharmony_ci 'enableUnicode', 501cb0ef41Sopenharmony_ci 'disableUnicode', 511cb0ef41Sopenharmony_ci 'enableProgress', 521cb0ef41Sopenharmony_ci 'disableProgress', 531cb0ef41Sopenharmony_ci 'progressEnabled', 541cb0ef41Sopenharmony_ci 'clearProgress', 551cb0ef41Sopenharmony_ci 'showProgress', 561cb0ef41Sopenharmony_ci 'newItem', 571cb0ef41Sopenharmony_ci 'newGroup', 581cb0ef41Sopenharmony_ci ...loggers, 591cb0ef41Sopenharmony_ci ].sort()) 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci t.end() 621cb0ef41Sopenharmony_ci}) 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_cit.test('works with npmlog/proclog proxy', t => { 651cb0ef41Sopenharmony_ci const procLog = { silly: () => 'SILLY' } 661cb0ef41Sopenharmony_ci const npmlog = { level: 'woo', enableColor: () => true } 671cb0ef41Sopenharmony_ci const shim = makeShim({ npmlog, 'proc-log': procLog }) 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci t.equal(shim.level, 'woo', 'can get a property') 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ci npmlog.level = 'hey' 721cb0ef41Sopenharmony_ci t.strictSame( 731cb0ef41Sopenharmony_ci [shim.level, npmlog.level], 741cb0ef41Sopenharmony_ci ['hey', 'hey'], 751cb0ef41Sopenharmony_ci 'can get a property after update on npmlog' 761cb0ef41Sopenharmony_ci ) 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci shim.level = 'test' 791cb0ef41Sopenharmony_ci t.strictSame( 801cb0ef41Sopenharmony_ci [shim.level, npmlog.level], 811cb0ef41Sopenharmony_ci ['test', 'test'], 821cb0ef41Sopenharmony_ci 'can get a property after update on shim' 831cb0ef41Sopenharmony_ci ) 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci t.ok(shim.enableColor(), 'can call method on shim to call npmlog') 861cb0ef41Sopenharmony_ci t.equal(shim.silly(), 'SILLY', 'can call method on proclog') 871cb0ef41Sopenharmony_ci t.notOk(shim.LEVELS, 'only includes levels from npmlog') 881cb0ef41Sopenharmony_ci t.throws(() => shim.gauge = 100, 'cant set getters properies') 891cb0ef41Sopenharmony_ci 901cb0ef41Sopenharmony_ci t.end() 911cb0ef41Sopenharmony_ci}) 921cb0ef41Sopenharmony_ci 931cb0ef41Sopenharmony_cit.test('works with npmlog/proclog proxy', t => { 941cb0ef41Sopenharmony_ci const shim = makeShim() 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ci loggers.forEach((k) => { 971cb0ef41Sopenharmony_ci t.doesNotThrow(() => shim[k]('test')) 981cb0ef41Sopenharmony_ci }) 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci t.end() 1011cb0ef41Sopenharmony_ci}) 102