]>
git.r.bdr.sh - rbdr/cologne/blob - test/formatters/simple.js
3 const Tap
= require('tap');
5 const SimpleFormatter
= require('../../lib/formatters/simple');
12 _timestamp: BigInt(Date
.now()) * 1000000n
,
14 _from: 'Dummy Logger',
16 _levelString: 'error',
17 message: 'testing stuff!'
19 const isoDate
= (new Date(Number(logObject
._timestamp
) / 1000000)).toISOString();
21 const plainFormatter
= new SimpleFormatter();
22 const colorFormatter
= new SimpleFormatter({
27 * TEST: #format() - plain
30 const plainFormattedString
= plainFormatter
.format(logObject
);
32 Tap
.equal(typeof plainFormattedString
, 'string',
33 '#format() should output a string in plain mode');
35 Tap
.ok(plainFormattedString
.match(logObject
._from
),
36 '#format() should include the from property in plain mode');
38 Tap
.ok(plainFormattedString
.match(isoDate
),
39 '#format() should include the timestamp property in iso format in plain mode');
41 Tap
.ok(plainFormattedString
.match(logObject
._levelString
),
42 '#format() should include the level string property in plain mode');
44 Tap
.ok(plainFormattedString
.match(logObject
.message
),
45 '#format() should include the message property in plain mode');
48 * TEST: #format() - colorized
51 const colorFormattedString
= colorFormatter
.format(logObject
);
53 Tap
.equal(typeof colorFormattedString
, 'string',
54 '#format() should output a string in color mode');
56 Tap
.ok(colorFormattedString
.match(logObject
._from
),
57 '#format() should include the from property in color mode');
59 Tap
.ok(colorFormattedString
.match(isoDate
),
60 '#format() should include the timestamp property in iso format in color mode');
62 Tap
.ok(colorFormattedString
.match(logObject
._levelString
),
63 '#format() should include the level string property in color mode');
65 Tap
.ok(colorFormattedString
.match(logObject
.message
),
66 '#format() should include the message property in color mode');
68 Tap
.equal(colorFormattedString
.split(String
.fromCharCode(27) + '[31m').length
, 2,
69 '#format() should colorize the string');
71 Tap
.equal(colorFormattedString
.split(String
.fromCharCode(27) + '[0m').length
, 2,
72 '#format() should colorize only a bit of the string');