1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
'use strict';
let tap = require('tap');
let SimpleFormatter = require('../../../lib/cologne/formatter/simple');
// Prepare the test
let logObject, colorFormatter, plainFormatter, formattedString, isoDate;
tap.plan(12);
logObject = {
_timestamp: Date.now() + .134,
_cologneLog: '1.0.0',
_from: 'Dummy Logger',
_level: 3,
_levelString: 'error',
message: 'testing stuff!'
};
isoDate = (new Date(logObject._timestamp)).toISOString();
plainFormatter = new SimpleFormatter();
colorFormatter = new SimpleFormatter({
colorize: true
});
/**
* TEST: #format() - plain
*/
formattedString = plainFormatter.format(logObject);
tap.equal(typeof formattedString, 'string',
'#format() should output a string in plain mode');
tap.ok(formattedString.match(logObject._from),
'#format() should include the from property in plain mode');
tap.ok(formattedString.match(isoDate),
'#format() should include the timestamp property in iso format in plain mode');
tap.ok(formattedString.match(logObject._levelString),
'#format() should include the level string property in plain mode');
tap.ok(formattedString.match(logObject.message),
'#format() should include the message property in plain mode');
/**
* TEST: #format() - colorized
*/
formattedString = colorFormatter.format(logObject);
tap.equal(typeof formattedString, 'string',
'#format() should output a string in color mode');
tap.ok(formattedString.match(logObject._from),
'#format() should include the from property in color mode');
tap.ok(formattedString.match(isoDate),
'#format() should include the timestamp property in iso format in color mode');
tap.ok(formattedString.match(logObject._levelString),
'#format() should include the level string property in color mode');
tap.ok(formattedString.match(logObject.message),
'#format() should include the message property in color mode');
tap.equal(formattedString.split(String.fromCharCode(27) + '[31m').length, 2,
'#format() should colorize the string');
tap.equal(formattedString.split(String.fromCharCode(27) + '[0m').length, 2,
'#format() should colorize only a bit of the string');
|