1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
'use strict';
const Tap = require('tap');
const Utilities = require('../lib/utilities');
// Prepare the test
Tap.plan(17);
/**
* TEST: ::now()
*/
const preciseTime = Utilities.now();
// I don't think this test makes sense lol
Tap.equal(typeof preciseTime, 'bigint',
'::now() should give a precise bigint timestamp');
/**
* TEST: ::stringify()
*/
const regularObject = {
a: 1,
b: {
c: 'true',
d: false
}
};
const circularObject = {
a: 1,
b: {
c: 'true',
d: false
}
};
circularObject.b.circular = circularObject;
const bigint = 666n;
const regularStringify = JSON.stringify(regularObject);
const cologneStringify = Utilities.stringify(regularObject);
const circularStringify = Utilities.stringify(circularObject);
const bigintStringify = Utilities.stringify(bigint);
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');
Tap.equal(bigintStringify, '"666n"',
'::stringify() should convert bigint to string');
/**
* TEST: ::getAnsiCode()
*/
// NOTE: This isn't even trying to be a complete test... Just testing
// that we get distinct non-reset codes if valid, and the same as reset
// for all invalid ones. knowing that reset is [0m
Tap.equal(Utilities.getAnsiCode('reset'), '[0m',
'::getAnsiCode is sending the correct reset code');
Tap.equal(Utilities.getAnsiCode('someRandomString'), Utilities.getAnsiCode('reset'),
'::getAnsiCode() should give us a reset code if something weird is sent');
const supportedCodes = ['bold', 'italics', 'underline', 'inverse', 'strikethrough',
'bold_off', 'italics_off', 'underline_off', 'inverse_off', 'strikethrough_off',
'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default',
'black_bg', 'red_bg', 'green_bg', 'yellow_bg', 'blue_bg', 'magenta_bg',
'cyan_bg', 'white_bg', 'default_bg'];
const resultingCodes = supportedCodes.map((code) => Utilities.getAnsiCode(code));
const isThereReset = resultingCodes.some((code) => code === '[0m');
Tap.equal((new Set(resultingCodes)).size, supportedCodes.length,
'::getAnsiCode() should not have duplicated non-reset codes');
Tap.false(isThereReset,
'::getAnsiCode() should not return a reset code in any other supported code');
/**
* TEST: ::getLevelAnsi()
*/
// 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(Utilities.getLevelAnsi(0), 'red',
'::gettLevelAnsi is red for emerg');
Tap.equal(Utilities.getLevelAnsi(1), 'red',
'::gettLevelAnsi is red for alert');
Tap.equal(Utilities.getLevelAnsi(2), 'red',
'::gettLevelAnsi is red for crit');
Tap.equal(Utilities.getLevelAnsi(3), 'red',
'::gettLevelAnsi is red for error');
Tap.equal(Utilities.getLevelAnsi(4), 'yellow',
'::gettLevelAnsi is yellow for warn');
Tap.equal(Utilities.getLevelAnsi(5), 'blue',
'::gettLevelAnsi is blue for notice');
Tap.equal(Utilities.getLevelAnsi(6), 'blue',
'::gettLevelAnsi is blue for info');
Tap.equal(Utilities.getLevelAnsi(7), 'green',
'::gettLevelAnsi is green for debug');
Tap.equal(Utilities.getLevelAnsi(8), 'default',
'::gettLevelAnsi is default for other values');
|