]> git.r.bdr.sh - rbdr/cologne/blame_incremental - test/loggers/console.js
Add larger timeout for file
[rbdr/cologne] / test / loggers / console.js
... / ...
CommitLineData
1'use strict';
2
3const Tap = require('tap');
4
5const ConsoleLogger = require('../../lib/loggers/console');
6
7// Prepare the test
8
9const dummyFormatter = {
10 values: [],
11 format: function (log) {
12
13 this.values.push(log);
14 return 'lol';
15 }
16};
17
18const dummyConsole = {
19 values: {
20 log: 0,
21 warn: 0,
22 error: 0,
23 info: 0
24 },
25 _log: function (type, ...logs) {
26
27 this.values[type] += logs.length;
28 },
29 log: function (...logs) {
30
31 this._log('log', ...logs);
32 },
33 warn: function (...logs) {
34
35 this._log('warn', ...logs);
36 },
37 error: function (...logs) {
38
39 this._log('error', ...logs);
40 },
41 info: function (...logs) {
42
43 this._log('info', ...logs);
44 }
45};
46
47const logObjectA = {
48 _timestamp: Date.now() + .134,
49 _cologneLog: '1.0.0',
50 _from: 'Dummy Logger',
51 _level: 6,
52 _levelString: 'info',
53 message: 'MessageOne'
54};
55
56const logObjectB = {
57 _timestamp: Date.now() + .134,
58 _cologneLog: '1.0.0',
59 _from: 'Dummy Logger',
60 _level: 6,
61 _levelString: 'info',
62 message: 'MessageTwo'
63};
64
65const logs = [logObjectA, logObjectB];
66
67const regularLogger = new ConsoleLogger({});
68const overrideLogger = new ConsoleLogger({
69 console: dummyConsole
70});
71const formattedLogger = new ConsoleLogger({
72 console: dummyConsole,
73 formatter: dummyFormatter
74});
75
76/**
77 * TEST: #log() - regular
78 */
79
80Tap.equal(regularLogger.console, global.console,
81 'It should default to the global console');
82
83/**
84 * TEST: #log() - override
85 */
86
87logObjectA._level = 5;
88logObjectB._level = 6;
89overrideLogger.log(...logs); // should go to info
90
91logObjectA._level = 4;
92logObjectB._level = 4;
93overrideLogger.log(...logs); // should go to warn
94
95logObjectA._level = 1;
96logObjectB._level = 3;
97overrideLogger.log(...logs); // should go to error
98
99logObjectA._level = 0;
100logObjectB._level = 2;
101overrideLogger.log(...logs); // should go to error
102
103logObjectA._level = 7;
104logObjectB._level = 8;
105overrideLogger.log(...logs); // should go to log
106
107Tap.equal(dummyConsole.values.log, logs.length,
108 'It should send debug messages to console\'s #log');
109Tap.equal(dummyConsole.values.info, logs.length,
110 'It should send info and notice messages to console\'s #info');
111Tap.equal(dummyConsole.values.warn, logs.length,
112 'It should send warn messages to console\'s #warn');
113Tap.equal(dummyConsole.values.error, logs.length * 2,
114 'It should send error messages to console\'s #error');
115
116/**
117 * TEST: #log() - with formatter
118 */
119
120formattedLogger.log(...logs); // should go to log
121
122Tap.similar(dummyFormatter.values, logs,
123 'If available, it should send the objects to the formatter');