|
| 1 | +process.env.NODE_ENV = 'test' |
| 2 | + |
| 3 | +const { join } = require('path') |
| 4 | +const Stream = require('stream') |
| 5 | +const async = require('async') |
| 6 | +const test = require('tape') |
| 7 | +const { logger } = require(join(__dirname, '..')) |
| 8 | + |
| 9 | +const levels = [ |
| 10 | + 'fatal', |
| 11 | + 'error', |
| 12 | + 'warn', |
| 13 | + 'info', |
| 14 | + 'debug', |
| 15 | + 'trace' |
| 16 | +] |
| 17 | + |
| 18 | +test('*** logger', function (t) { |
| 19 | + t.plan(10 + levels.length) |
| 20 | + t.comment('constructor') |
| 21 | + t.equal(typeof logger, 'function', 'did return construct correctly') |
| 22 | + |
| 23 | + t.comment('parameters') |
| 24 | + t.equal(typeof logger(), 'object', 'did return correctly') |
| 25 | + t.equal(typeof logger({}), 'object', 'blank object parameter') |
| 26 | + |
| 27 | + t.comment('level property') |
| 28 | + let levelProp = logger({ |
| 29 | + level: 'info' |
| 30 | + }) |
| 31 | + t.equal(typeof levelProp, 'object', 'did return correctly') |
| 32 | + t.equal(levelProp.info.name, 'LOG', 'has level info method') |
| 33 | + t.equal(levelProp.debug.name, 'noop', 'has no debug method') |
| 34 | + |
| 35 | + t.comment('stream property') |
| 36 | + let streamProp = logger({ |
| 37 | + stream: new Stream() |
| 38 | + }) |
| 39 | + |
| 40 | + t.equal(typeof streamProp, 'object', 'did return correctly') |
| 41 | + t.equal(streamProp.stream._isStdio, true, 'defaults to stdout') |
| 42 | + t.equal(streamProp.stream.writable, true, 'stream is readable') |
| 43 | + |
| 44 | + t.comment('pretty property') |
| 45 | + let prettyProp = logger({ pretty: true }) |
| 46 | + t.equal(typeof prettyProp, 'object', 'did return correctly') |
| 47 | + |
| 48 | + async.forEach(levels, function (level, cb) { |
| 49 | + let type = logger().hasOwnProperty(level) |
| 50 | + t.equal(type, true, `Should return ${level} method`) |
| 51 | + cb() |
| 52 | + }, t.end) |
| 53 | +}) |
0 commit comments