swadhinbiswas feat: complete DevPulse production developer operating system for Discord · 9/6/2026
4a8d707
63 lines · 1.8 KB
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
import { describe, expect, it } from "vitest";
import {
  formatBytes,
  formatDuration,
  formatRelativeTime,
  renderHorizontalBarChart,
  renderProgressBar,
  renderSparkline,
  truncate,
} from "./index.js";

describe("core formatters", () => {
  it("formats bytes correctly", () => {
    expect(formatBytes(0)).toBe("0 B");
    expect(formatBytes(1024)).toBe("1 KB");
    expect(formatBytes(1048576)).toBe("1 MB");
    expect(formatBytes(1073741824)).toBe("1 GB");
  });

  it("formats durations accurately", () => {
    expect(formatDuration(450)).toBe("450ms");
    expect(formatDuration(5000)).toBe("5s");
    expect(formatDuration(65000)).toBe("1m 5s");
    expect(formatDuration(3600000)).toBe("1h");
    expect(formatDuration(90000000)).toBe("1d 1h");
  });

  it("truncates strings gracefully", () => {
    expect(truncate("hello world", 5)).toBe("hell…");
    expect(truncate("hello", 10)).toBe("hello");
  });

  it("formats relative time", () => {
    const now = Date.now();
    expect(formatRelativeTime(now - 2000)).toBe("just now");
    expect(formatRelativeTime(now - 120000)).toBe("2m ago");
    expect(formatRelativeTime(now - 7200000)).toBe("2h ago");
    expect(formatRelativeTime(now - 86400000 * 3)).toBe("3d ago");
  });
});

describe("core charts", () => {
  it("renders progress bars", () => {
    const bar50 = renderProgressBar(50, 10);
    expect(bar50).toContain("█████░░░░░ 50%");
  });

  it("renders horizontal bar charts", () => {
    const chart = renderHorizontalBarChart([
      { label: "Mon", value: 5 },
      { label: "Tue", value: 10 },
    ]);
    expect(chart).toContain("Mon");
    expect(chart).toContain("Tue");
    expect(chart).toContain("█");
  });

  it("renders sparklines", () => {
    const spark = renderSparkline([1, 3, 5, 7, 9]);
    expect(spark.length).toBe(5);
  });
});