1.2 KB45 lines
Blame
1export const STATUS_COLORS: Record<string, string> = {
2 passed: "\x1b[32m",
3 failed: "\x1b[31m",
4 running: "\x1b[33m",
5 pending: "\x1b[90m",
6 cancelled: "\x1b[90m",
7 skipped: "\x1b[90m",
8};
9
10export const STATUS_ICONS: Record<string, string> = {
11 passed: "\x1b[32m✓\x1b[0m",
12 failed: "\x1b[31m✗\x1b[0m",
13 running: "\x1b[33m●\x1b[0m",
14 pending: "\x1b[90m○\x1b[0m",
15 cancelled: "\x1b[90m⊘\x1b[0m",
16 skipped: "\x1b[90m-\x1b[0m",
17};
18
19export const RESET = "\x1b[0m";
20
21export function colorStatus(status: string): string {
22 return `${STATUS_COLORS[status] ?? ""}${status}${RESET}`;
23}
24
25export function formatDuration(ms: number | null): string {
26 if (!ms) return "-";
27 if (ms < 1000) return `${ms}ms`;
28 const s = Math.round(ms / 1000);
29 if (s < 60) return `${s}s`;
30 return `${Math.floor(s / 60)}m${s % 60}s`;
31}
32
33export function formatDurationRange(start: string | null, end: string | null): string {
34 if (!start) return "";
35 const s = new Date(start + "Z").getTime();
36 const e = end ? new Date(end + "Z").getTime() : Date.now();
37 return formatDuration(e - s);
38}
39
40export function formatTime(iso: string | null): string {
41 if (!iso) return "-";
42 const d = new Date(iso + "Z");
43 return d.toLocaleString();
44}
45