]>
git.r.bdr.sh - rbdr/cologne/blob - test/loggers/file.js
3 const Fs
= require('fs');
5 const Tap
= require('tap');
7 const FileLogger
= require('../../lib/loggers/file');
11 const rawFile
= './raw.log';
12 const formatterFile
= './formatter.log';
13 const formatterString
= 'example';
16 _timestamp: Date
.now() + .134,
18 _from: 'Dummy Logger',
25 _timestamp: Date
.now() + .134,
27 _from: 'Dummy Logger',
33 const logs
= [logObjectA
, logObjectB
];
36 const dummyFormatter
= {
38 format: function (logObject
) {
40 this.values
.push(logObject
);
41 return formatterString
;
45 const rawLogger
= new FileLogger({
48 const formatterLogger
= new FileLogger({
50 formatter: dummyFormatter
54 * TEST: #log() - regular
57 rawLogger
.log(...logs
);
61 Tap
.test('raw file', (t
) => {
63 Fs
.readFile(rawFile
, { encoding: 'utf8' }, (_
, contents
) => {
65 const lines
= contents
.trim().split('\n');
67 Tap
.equal(lines
.length
, logs
.length
,
68 'it should send all params to the file');
70 Tap
.equal(JSON
.stringify(logObjectA
), lines
[0],
71 'it should log the raw json object');
73 Fs
.unlink(rawFile
, () => {
79 }, 10); // allow for flush
81 * TEST: #log() - formatter
84 formatterLogger
.log(...logs
);
88 Tap
.test('formatted file', (t
) => {
90 Fs
.readFile(formatterFile
, { encoding: 'utf8' }, (_
, contents
) => {
92 const lines
= contents
.trim().split('\n');
94 Tap
.equal(lines
.length
, logs
.length
,
95 'it should send all params to the file');
97 Tap
.equal(formatterString
, lines
[0],
98 'it should log the formatted object');
100 Fs
.unlink(formatterFile
, () => {