]> git.r.bdr.sh - rbdr/cologne/blobdiff - test/cologne/log_utilities.js
Recover from npm package
[rbdr/cologne] / test / cologne / log_utilities.js
diff --git a/test/cologne/log_utilities.js b/test/cologne/log_utilities.js
new file mode 100644 (file)
index 0000000..e372683
--- /dev/null
@@ -0,0 +1,69 @@
+'use strict';
+
+let tap = require('tap');
+
+let LogUtilities = require('../../lib/cologne/log_utilities');
+
+// Prepare the test
+let t1, t2, preciseTime, regularObject, circularObject,
+  regularStringify, cologneStringify, circularStringify;
+
+tap.plan(7);
+
+regularObject = {
+  a: 1,
+  b: {
+    c: 'true',
+    d: false
+  }
+};
+
+circularObject = {
+  a: 1,
+  b: {
+    c: 'true',
+    d: false
+  }
+};
+circularObject.b.circular = circularObject;
+
+/**
+ * TEST: ::now()
+ */
+t1 = Date.now();
+preciseTime = LogUtilities.now();
+t2 = Date.now();
+
+// This test is sloppy :(
+tap.ok(Math.abs(t1 - preciseTime) < 1,
+       '::now() should give a precise timestamp (before)');
+tap.ok(Math.abs(t2 - preciseTime) < 1,
+       '::now() should give a precise timestamp (after)');
+
+/**
+ * TEST: ::stringify()
+ */
+
+regularStringify = JSON.stringify(regularObject);
+cologneStringify = LogUtilities.stringify(regularObject);
+circularStringify = LogUtilities.stringify(circularObject);
+
+tap.equal(regularStringify, cologneStringify,
+         '::stringify() should behave like JSON.stringify for non-circular objects');
+tap.equal(typeof JSON.parse(circularStringify).b.circular, 'string',
+         '::stringify() should replace circular references with a string');
+
+/**
+ * TEST: ::getAnsiCode()
+ */
+
+// NOTE: This isn't even trying to be a complete test... Just testing
+// that we get other than reset if valid, and the same as reset for all
+// invalid ones. knowing that reset is [0m
+
+tap.equal(LogUtilities.getAnsiCode('reset'), '[0m',
+          '::getAnsiCode is sending the correct reset code');
+tap.equal(LogUtilities.getAnsiCode('someRandomString'), LogUtilities.getAnsiCode('reset'),
+          '::getAnsiCode() should give us a reset code if something weird is sent');
+tap.notEqual(LogUtilities.getAnsiCode('red'), LogUtilities.getAnsiCode('reset'),
+          '::getAnsiCode() should give us a non-reset code if it\'s something real');