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