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