-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.test.ts
83 lines (72 loc) · 2.22 KB
/
main.test.ts
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
// Copyright 2024 Im-Beast. All rights reserved. MIT license.
/// <reference lib="deno.ns" />
import { assertEquals } from "@std/assert";
import { ColorSupport, getColorSupport } from "./main.ts";
function resetEnv(): void {
Deno.env.delete("COLORTERM");
Deno.env.delete("TERM");
Deno.env.delete("CI");
Deno.env.delete("NO_COLOR");
Deno.env.delete("FORCE_COLOR");
}
async function subTest(
t: Deno.TestContext,
variables: [keys: string[], values: string[]][],
expected: ColorSupport,
) {
for (const [keys, values] of variables) {
for (const value of values) {
const keyTitle = keys.length > 1 ? `[${keys}]` : keys[0];
await t.step(
`\x1b[33m${keyTitle}\x1b[0m=\x1b[36m${value}\x1b[0m`,
async () => {
resetEnv();
for (const key of keys) {
Deno.env.set(key, value);
}
assertEquals(await getColorSupport(), expected);
for (const key of keys) {
Deno.env.delete(key);
}
},
);
}
}
}
Deno.test("TrueColor", async (t) => {
await subTest(t, [
[["COLORTERM"], ["truecolor", "24bit"]],
// deno-fmt-ignore
[["TERM"], ["iterm", "linux-truecolor", "screen-truecolor", "tmux-truecolor", "xterm-truecolor", "vte-truecolor"]],
[["CI", "GITHUB_ACTIONS"], ["TRUE", "1"]],
[["CI", "GITEA_ACTIONS"], ["TRUE", "1"]],
[["FORCE_COLOR"], ["1", "TRUE"]],
], ColorSupport.TrueColor);
});
Deno.test("HighColor", async (t) => {
await subTest(t, [
// deno-fmt-ignore
[["TERM"], ["linux-256", "screen-256", "tmux-256", "xterm-256", "xterm", "rxvt", "tmux", "putty", "teken" ]],
], ColorSupport.HighColor);
});
Deno.test("FourBit", async (t) => {
await subTest(t, [
[["COLORTERM"], ["4bit"]],
[["CI", "TRAVIS"], ["1", "TRUE"]],
[["CI", "CIRCLECI"], ["1", "TRUE"]],
[["CI", "GITLAB_CI"], ["1", "TRUE"]],
[["CI", "BUILDKITE"], ["1", "TRUE"]],
[["CI", "DRONE"], ["1", "TRUE"]],
[["CI", "APPVEYOR"], ["1", "TRUE"]],
], ColorSupport.FourBit);
});
Deno.test("None", async (t) => {
await subTest(t, [
[["TERM"], ["DUMB"]],
], ColorSupport.None);
});
Deno.test("NoColor", async (t) => {
await subTest(t, [
[["NO_COLOR"], ["1"]],
], ColorSupport.NoColor);
});