]>
git.r.bdr.sh - rbdr/cologne/blob - test/cologne/log_utilities.js
e37268399eb78e2f08dbc7fe37235357f02b939a
3 let tap
= require('tap');
5 let LogUtilities
= require('../../lib/cologne/log_utilities');
8 let t1
, t2
, preciseTime
, regularObject
, circularObject
,
9 regularStringify
, cologneStringify
, circularStringify
;
28 circularObject
.b
.circular
= circularObject
;
34 preciseTime
= LogUtilities
.now();
37 // This test is sloppy :(
38 tap
.ok(Math
.abs(t1
- preciseTime
) < 1,
39 '::now() should give a precise timestamp (before)');
40 tap
.ok(Math
.abs(t2
- preciseTime
) < 1,
41 '::now() should give a precise timestamp (after)');
47 regularStringify
= JSON
.stringify(regularObject
);
48 cologneStringify
= LogUtilities
.stringify(regularObject
);
49 circularStringify
= LogUtilities
.stringify(circularObject
);
51 tap
.equal(regularStringify
, cologneStringify
,
52 '::stringify() should behave like JSON.stringify for non-circular objects');
53 tap
.equal(typeof JSON
.parse(circularStringify
).b
.circular
, 'string',
54 '::stringify() should replace circular references with a string');
57 * TEST: ::getAnsiCode()
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
64 tap
.equal(LogUtilities
.getAnsiCode('reset'), '[0m',
65 '::getAnsiCode is sending the correct reset code');
66 tap
.equal(LogUtilities
.getAnsiCode('someRandomString'), LogUtilities
.getAnsiCode('reset'),
67 '::getAnsiCode() should give us a reset code if something weird is sent');
68 tap
.notEqual(LogUtilities
.getAnsiCode('red'), LogUtilities
.getAnsiCode('reset'),
69 '::getAnsiCode() should give us a non-reset code if it\'s something real');