mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
chore(test): improve test coverage for log4js
log4js.js - Line 83 - return recordingModule
This commit is contained in:
parent
a912401dc2
commit
05a64ff1fe
28
test/tap/recordingAppender-test.js
Normal file
28
test/tap/recordingAppender-test.js
Normal file
@ -0,0 +1,28 @@
|
||||
const { test } = require("tap");
|
||||
const log4js = require("../../lib/log4js");
|
||||
|
||||
test("recording appender", t => {
|
||||
log4js.configure({
|
||||
appenders: { rec: { type: 'recording' } },
|
||||
categories: { default: { appenders: [ 'rec' ], 'level': 'debug' } }
|
||||
});
|
||||
|
||||
const logger = log4js.getLogger();
|
||||
logger.level = 'debug';
|
||||
logger.debug('This will go to the recording!');
|
||||
logger.debug('Another one');
|
||||
|
||||
const recording = log4js.recording();
|
||||
const loggingEvents = recording.playback();
|
||||
|
||||
t.equal(loggingEvents.length, 2, "There should be 2 recorded events");
|
||||
t.equal(loggingEvents[0].data[0], "This will go to the recording!");
|
||||
t.equal(loggingEvents[1].data[0], "Another one");
|
||||
|
||||
recording.reset();
|
||||
const loggingEventsPostReset = recording.playback();
|
||||
|
||||
t.equal(loggingEventsPostReset.length, 0, "There should be 0 recorded events");
|
||||
|
||||
t.end();
|
||||
});
|
||||
@ -139,7 +139,7 @@ log4js.configure({
|
||||
|
||||
log4js.configure({
|
||||
appenders: { rec: { type: 'recording' } },
|
||||
categories: { default: { appenders: [ 'rec'], 'level': 'debug' } }
|
||||
categories: { default: { appenders: ['rec'], 'level': 'debug' } }
|
||||
});
|
||||
const logger8 = log4js.getLogger();
|
||||
logger8.level = 'debug'
|
||||
@ -150,6 +150,9 @@ const loggingEvents = recording.playback()
|
||||
if (loggingEvents.length !== 2) {
|
||||
throw new Error(`Expected 2 recorded events, got ${loggingEvents.length}`)
|
||||
}
|
||||
if (loggingEvents[0].data[0] !== 'This will go to the recording!') {
|
||||
throw new Error(`Expected message 'This will go to the recording!', got ${loggingEvents[0].data[0]}`)
|
||||
}
|
||||
if (loggingEvents[1].data[0] !== 'Another one') {
|
||||
throw new Error(`Expected message 'Another one', got ${loggingEvents[1].data[0]}`)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user