|
| 1 | +const test = require('tap').test; |
| 2 | +const sandbox = require('sandboxed-module'); |
| 3 | + |
| 4 | +test('../lib/index.js', (batch) => { |
| 5 | + |
| 6 | + batch.test('should provide a getLogger function', (t) => { |
| 7 | + const log4js = require('../lib'); |
| 8 | + |
| 9 | + t.isA(log4js.getLogger, 'function'); |
| 10 | + t.end(); |
| 11 | + }); |
| 12 | + |
| 13 | + batch.test('when log4js is not available', (t) => { |
| 14 | + const log4js = require('../lib'); |
| 15 | + const logger = log4js.getLogger(); |
| 16 | + |
| 17 | + t.test('logger should provide dummy functions for context', (assert) => { |
| 18 | + assert.isA(logger.addContext, 'function'); |
| 19 | + assert.isA(logger.removeContext, 'function'); |
| 20 | + assert.isA(logger.clearContext, 'function'); |
| 21 | + assert.end(); |
| 22 | + }); |
| 23 | + |
| 24 | + t.test('logger should always say that log levels are not enabled', (assert) => { |
| 25 | + ['Trace','Debug','Info','Warn','Error','Fatal'].forEach((level) => { |
| 26 | + assert.false(logger.isLevelEnabled(level)); |
| 27 | + assert.false(logger[`is${level}Enabled`]()); |
| 28 | + }); |
| 29 | + assert.end(); |
| 30 | + }); |
| 31 | + |
| 32 | + t.test('logger should provide logging functions', (assert) => { |
| 33 | + assert.isA(logger.log, 'function'); |
| 34 | + ['trace','debug','info','warn','error', 'fatal'].forEach((level) => { |
| 35 | + assert.isA(logger[level], 'function'); |
| 36 | + }); |
| 37 | + assert.end(); |
| 38 | + }); |
| 39 | + |
| 40 | + t.end(); |
| 41 | + }); |
| 42 | + |
| 43 | + batch.test('when log4js is available', (t) => { |
| 44 | + const log4js = sandbox.require('../lib', { |
| 45 | + requires: { |
| 46 | + log4js: { |
| 47 | + getLogger: () => 'cheese' |
| 48 | + } |
| 49 | + }, |
| 50 | + singleOnly: true |
| 51 | + }); |
| 52 | + const logger = log4js.getLogger(); |
| 53 | + |
| 54 | + t.equal(logger, 'cheese'); |
| 55 | + t.end(); |
| 56 | + }); |
| 57 | + |
| 58 | + batch.end(); |
| 59 | +}); |
0 commit comments