chore(test): improve test coverage for log4js

log4js.js - Line 83 - return recordingModule
This commit is contained in:
Lam Wei Li 2022-03-07 00:19:14 +08:00
parent a912401dc2
commit 05a64ff1fe
No known key found for this signature in database
GPG Key ID: 90F6ABECF080D7BF
2 changed files with 32 additions and 1 deletions

View 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();
});

View File

@ -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]}`)
}