diff --git a/lib/index.js b/lib/index.js index c179948..db14009 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,18 +1,24 @@ -const log = { - LEVELS: [ - 'notice', - 'error', - 'warn', - 'info', - 'verbose', - 'http', - 'silly', - 'pause', - 'resume', - ], +module.exports = { + log: { + LEVELS: [ + 'notice', + 'error', + 'warn', + 'info', + 'verbose', + 'http', + 'silly', + 'pause', + 'resume', + ], + error: (...args) => process.emit('log', 'error', ...args), + notice: (...args) => process.emit('log', 'notice', ...args), + warn: (...args) => process.emit('log', 'warn', ...args), + info: (...args) => process.emit('log', 'info', ...args), + verbose: (...args) => process.emit('log', 'verbose', ...args), + http: (...args) => process.emit('log', 'http', ...args), + silly: (...args) => process.emit('log', 'silly', ...args), + pause: (...args) => process.emit('log', 'pause', ...args), + resume: (...args) => process.emit('log', 'resume', ...args), + }, } -for (const level of log.LEVELS) { - log[level] = (...args) => process.emit('log', level, ...args) -} - -module.exports = { log } diff --git a/tap-snapshots/test/index.js.test.cjs b/tap-snapshots/test/index.js.test.cjs index df4d5ef..47ff39f 100644 --- a/tap-snapshots/test/index.js.test.cjs +++ b/tap-snapshots/test/index.js.test.cjs @@ -5,7 +5,7 @@ * Make sure to inspect the output below. Do not ignore changes! */ 'use strict' -exports[`test/index.js TAP > log levels 1`] = ` +exports[`test/index.js TAP log > log levels 1`] = ` Array [ "notice", "error", diff --git a/test/index.js b/test/index.js index bd5afba..cfb6a07 100644 --- a/test/index.js +++ b/test/index.js @@ -2,15 +2,29 @@ const t = require('tap') const { log } = require('../') const { LEVELS } = log -t.matchSnapshot(LEVELS, 'log levels') -for (const level of LEVELS) { - t.test(level, t => { - t.match(log[level], Function) - process.once('log', (actual, ...args) => { - t.equal(actual, level, 'emitted log with expected level') - t.same(args, [1, 2, 3], 'got expected args') - t.end() - }) - log[level](1, 2, 3) +t.test('log', t => { + t.matchSnapshot(LEVELS, 'log levels') + t.test('all log.LEVELS have a function in log', t => { + for (const level of LEVELS) { + t.test(level, t => { + t.match(log[level], Function) + process.once('log', (actual, ...args) => { + t.equal(actual, level, 'emitted log with expected level') + t.same(args, [1, 'two', [3], { 4: 4 }], 'got expected args') + t.end() + }) + log[level](1, 'two', [3], { 4: 4 }) + }) + } + t.end() }) -} + t.test('all log functions are in log.LEVELS', t => { + t.plan(LEVELS.length) + for (const fn in log) { + if (fn !== 'LEVELS') { + t.ok(LEVELS.includes(fn), `log.${fn} is in LEVELS`) + } + } + }) + t.end() +})