]> git.r.bdr.sh - rbdr/cologne/blame - test/cologne/log_utilities.js
Recover from npm package
[rbdr/cologne] / test / cologne / log_utilities.js
CommitLineData
58906d77
RBR
1'use strict';
2
3let tap = require('tap');
4
5let LogUtilities = require('../../lib/cologne/log_utilities');
6
7// Prepare the test
8let t1, t2, preciseTime, regularObject, circularObject,
9 regularStringify, cologneStringify, circularStringify;
10
11tap.plan(7);
12
13regularObject = {
14 a: 1,
15 b: {
16 c: 'true',
17 d: false
18 }
19};
20
21circularObject = {
22 a: 1,
23 b: {
24 c: 'true',
25 d: false
26 }
27};
28circularObject.b.circular = circularObject;
29
30/**
31 * TEST: ::now()
32 */
33t1 = Date.now();
34preciseTime = LogUtilities.now();
35t2 = Date.now();
36
37// This test is sloppy :(
38tap.ok(Math.abs(t1 - preciseTime) < 1,
39 '::now() should give a precise timestamp (before)');
40tap.ok(Math.abs(t2 - preciseTime) < 1,
41 '::now() should give a precise timestamp (after)');
42
43/**
44 * TEST: ::stringify()
45 */
46
47regularStringify = JSON.stringify(regularObject);
48cologneStringify = LogUtilities.stringify(regularObject);
49circularStringify = LogUtilities.stringify(circularObject);
50
51tap.equal(regularStringify, cologneStringify,
52 '::stringify() should behave like JSON.stringify for non-circular objects');
53tap.equal(typeof JSON.parse(circularStringify).b.circular, 'string',
54 '::stringify() should replace circular references with a string');
55
56/**
57 * TEST: ::getAnsiCode()
58 */
59
60// NOTE: This isn't even trying to be a complete test... Just testing
61// that we get other than reset if valid, and the same as reset for all
62// invalid ones. knowing that reset is [0m
63
64tap.equal(LogUtilities.getAnsiCode('reset'), '[0m',
65 '::getAnsiCode is sending the correct reset code');
66tap.equal(LogUtilities.getAnsiCode('someRandomString'), LogUtilities.getAnsiCode('reset'),
67 '::getAnsiCode() should give us a reset code if something weird is sent');
68tap.notEqual(LogUtilities.getAnsiCode('red'), LogUtilities.getAnsiCode('reset'),
69 '::getAnsiCode() should give us a non-reset code if it\'s something real');