Skip to content

Commit

Permalink
add maxLength to testCase
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-cloud committed May 20, 2023
1 parent cd8b019 commit 4dc786e
Showing 1 changed file with 68 additions and 21 deletions.
89 changes: 68 additions & 21 deletions test/tap/recordingAppender-test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,79 @@
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' } },
test('recording appender', (batch) => {
batch.test('should store logs in memory until cleared', (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();
});

const logger = log4js.getLogger();
logger.level = 'debug';
logger.debug('This will go to the recording!');
logger.debug('Another one');
batch.test('should store 2 rolling logs in memory until cleared', (t) => {
log4js.configure({
appenders: { rec2: { type: 'recording', maxLength: 2 } },
categories: { default: { appenders: ['rec2'], level: 'debug' } },
});

const recording = log4js.recording();
const loggingEvents = recording.playback();
const logger = log4js.getLogger();
logger.level = 'debug';
logger.debug('First log entry');
logger.debug('Second log entry');

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');
const recording = log4js.recording();

recording.reset();
const loggingEventsPostReset = recording.playback();
t.equal(
recording.playback().length,
2,
'There should be 2 recorded events'
);
t.equal(recording.playback()[0].data[0], 'First log entry');
t.equal(recording.playback()[1].data[0], 'Second log entry');

t.equal(
loggingEventsPostReset.length,
0,
'There should be 0 recorded events'
);
logger.debug('Third log entry');

t.equal(
recording.playback().length,
2,
'There should still be 2 recording events'
);
t.equal(recording.playback()[0].data[0], 'Second log entry');
t.equal(recording.playback()[1].data[0], 'Third log entry');

recording.reset();
const loggingEventsPostReset = recording.playback();

t.equal(
loggingEventsPostReset.length,
0,
'There should be 0 recorded events'
);

t.end();
});

t.end();
batch.end();
});

0 comments on commit 4dc786e

Please sign in to comment.