-
Notifications
You must be signed in to change notification settings - Fork 248
/
format-helpers.spec.mjs
65 lines (52 loc) · 2.53 KB
/
format-helpers.spec.mjs
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
/* eslint-disable no-magic-numbers */
import { expect } from "chai";
import formatHelpers from "../../../../src/cli/listeners/performance-log/format-helpers.js";
describe("[U] cli/listeners/performance-log/format-helpers - formatTime", () => {
it("converts to ms, leftpads & adds the unit at the end", () => {
expect(formatHelpers.formatTime(14.88041018)).to.equal(" 14880ms");
});
it("converts to ms, leftpads & adds the unit at the end (0)", () => {
expect(formatHelpers.formatTime(0)).to.equal(" 0ms");
});
it("converts to ms, leftpads & adds the unit at the end (negative numbers)", () => {
expect(formatHelpers.formatTime(-3.1415926535)).to.equal(" -3142ms");
});
it("converts to ms, leftpads & adds the unit at the end (null treatment => 0)", () => {
expect(formatHelpers.formatTime(null)).to.equal(" 0ms");
});
it("converts to ms, leftpads & adds the unit at the end (undefined treatment => NaN)", () => {
expect(formatHelpers.formatTime()).to.equal(" NaNms");
});
it("converts to ms, leftpads & adds the unit at the end (non-number treatment => NaN)", () => {
expect(formatHelpers.formatTime("not a number")).to.equal(" NaNms");
});
});
describe("[U] cli/listeners/performance-log/format-helpers - formatMemory", () => {
it("converts to Mb, leftpads & adds the unit at the end", () => {
expect(formatHelpers.formatMemory(4033856)).to.equal(" 4Mb");
});
it("converts to Mb, leftpads & adds the unit at the end (0)", () => {
expect(formatHelpers.formatMemory(0)).to.equal(" 0Mb");
});
it("converts to Mb, leftpads & adds the unit at the end (negative numbers)", () => {
expect(formatHelpers.formatMemory(-403385623)).to.equal(" -385Mb");
});
it("converts to Mb, leftpads & adds the unit at the end (null)", () => {
expect(formatHelpers.formatMemory(0)).to.equal(" 0Mb");
});
it("converts to Mb, leftpads & adds the unit at the end (undefined)", () => {
expect(formatHelpers.formatMemory()).to.equal(" NaNMb");
});
it("converts to Mb, leftpads & adds the unit at the end (not a number)", () => {
expect(formatHelpers.formatMemory("not a number")).to.equal(" NaNMb");
});
});
describe("[U] cli/ears/performance-log-listener/format-helpers - formatPerfLine", () => {
it("produces neat columns with time, memmory and a message", () => {
expect(
formatHelpers.formatPerfLine(14.88041018, 7.245436738, "sim sala bim")
).to.match(
/ {3}7635ms {0,}\d+Mb {0,}\d+Mb {0,}\d+Mb {0,}\d+Mb sim sala bim\n/
);
});
});