]>
git.r.bdr.sh - rbdr/cologne/blob - test/loggers/console.js
3 const Tap
= require('tap');
5 const ConsoleLogger
= require('../../lib/loggers/console');
9 const dummyFormatter
= {
11 format: function (log
) {
13 this.values
.push(log
);
18 const dummyConsole
= {
25 _log: function (type
, ...logs
) {
27 this.values
[type
] += logs
.length
;
29 log: function (...logs
) {
31 this._log('log', ...logs
);
33 warn: function (...logs
) {
35 this._log('warn', ...logs
);
37 error: function (...logs
) {
39 this._log('error', ...logs
);
41 info: function (...logs
) {
43 this._log('info', ...logs
);
48 _timestamp: Date
.now() + .134,
50 _from: 'Dummy Logger',
57 _timestamp: Date
.now() + .134,
59 _from: 'Dummy Logger',
65 const exampleLogs
= [logObjectA
, logObjectB
];
67 const regularLogger
= new ConsoleLogger({});
68 const overrideLogger
= new ConsoleLogger({
71 const formattedLogger
= new ConsoleLogger({
72 console: dummyConsole
,
73 formatter: dummyFormatter
77 * TEST: #log() - regular
80 Tap
.equal(regularLogger
.console
, global
.console
,
81 'It should default to the global console');
84 * TEST: #log() - override
87 logObjectA
._level
= 5;
88 logObjectB
._level
= 6;
89 overrideLogger
.log(...exampleLogs
); // should go to info
91 logObjectA
._level
= 4;
92 logObjectB
._level
= 4;
93 overrideLogger
.log(...exampleLogs
); // should go to warn
95 logObjectA
._level
= 1;
96 logObjectB
._level
= 3;
97 overrideLogger
.log(...exampleLogs
); // should go to error
99 logObjectA
._level
= 0;
100 logObjectB
._level
= 2;
101 overrideLogger
.log(...exampleLogs
); // should go to error
103 logObjectA
._level
= 7;
104 logObjectB
._level
= 8;
105 overrideLogger
.log(...exampleLogs
); // should go to log
107 Tap
.equal(dummyConsole
.values
.log
, exampleLogs
.length
,
108 'It should send debug messages to console\'s #log');
109 Tap
.equal(dummyConsole
.values
.info
, exampleLogs
.length
,
110 'It should send info and notice messages to console\'s #info');
111 Tap
.equal(dummyConsole
.values
.warn
, exampleLogs
.length
,
112 'It should send warn messages to console\'s #warn');
113 Tap
.equal(dummyConsole
.values
.error
, exampleLogs
.length
* 2,
114 'It should send error messages to console\'s #error');
117 * TEST: #log() - with formatter
120 formattedLogger
.log(...exampleLogs
); // should go to log
122 Tap
.similar(dummyFormatter
.values
, exampleLogs
,
123 'If available, it should send the objects to the formatter');