]>
git.r.bdr.sh - rbdr/cologne/blob - test/cologne/formatter/simple.js
86425416f7146a386c5bfedd54e16c78abba20e6
3 let tap
= require('tap');
5 let SimpleFormatter
= require('../../../lib/cologne/formatter/simple');
8 let logObject
, colorFormatter
, plainFormatter
, formattedString
, isoDate
;
13 _timestamp: Date
.now() + .134,
15 _from: 'Dummy Logger',
17 _levelString: 'error',
18 message: 'testing stuff!'
20 isoDate
= (new Date(logObject
._timestamp
)).toISOString();
22 plainFormatter
= new SimpleFormatter();
23 colorFormatter
= new SimpleFormatter({
28 * TEST: #format() - plain
31 formattedString
= plainFormatter
.format(logObject
);
33 tap
.equal(typeof formattedString
, 'string',
34 '#format() should output a string in plain mode');
36 tap
.ok(formattedString
.match(logObject
._from
),
37 '#format() should include the from property in plain mode');
39 tap
.ok(formattedString
.match(isoDate
),
40 '#format() should include the timestamp property in iso format in plain mode');
42 tap
.ok(formattedString
.match(logObject
._levelString
),
43 '#format() should include the level string property in plain mode');
45 tap
.ok(formattedString
.match(logObject
.message
),
46 '#format() should include the message property in plain mode');
49 * TEST: #format() - colorized
52 formattedString
= colorFormatter
.format(logObject
);
54 tap
.equal(typeof formattedString
, 'string',
55 '#format() should output a string in color mode');
57 tap
.ok(formattedString
.match(logObject
._from
),
58 '#format() should include the from property in color mode');
60 tap
.ok(formattedString
.match(isoDate
),
61 '#format() should include the timestamp property in iso format in color mode');
63 tap
.ok(formattedString
.match(logObject
._levelString
),
64 '#format() should include the level string property in color mode');
66 tap
.ok(formattedString
.match(logObject
.message
),
67 '#format() should include the message property in color mode');
69 tap
.equal(formattedString
.split(String
.fromCharCode(27) + '[31m').length
, 2,
70 '#format() should colorize the string');
72 tap
.equal(formattedString
.split(String
.fromCharCode(27) + '[0m').length
, 2,
73 '#format() should colorize only a bit of the string');