|
|
@@ -1,8 +1,9 @@
|
|
|
-import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
|
|
+import { describe, expect, it, vi, afterEach } from "vitest";
|
|
|
import type { TerminalTheme } from "../theme.js";
|
|
|
|
|
|
describe("detectTerminalTheme", () => {
|
|
|
const originalEnv = process.env.COLORFGBG;
|
|
|
+ const originalPlatform = process.platform;
|
|
|
|
|
|
afterEach(() => {
|
|
|
if (originalEnv === undefined) {
|
|
|
@@ -10,44 +11,44 @@ describe("detectTerminalTheme", () => {
|
|
|
} else {
|
|
|
process.env.COLORFGBG = originalEnv;
|
|
|
}
|
|
|
+ Object.defineProperty(process, "platform", { value: originalPlatform });
|
|
|
vi.resetModules();
|
|
|
});
|
|
|
|
|
|
- async function detect(colorfgbg?: string): Promise<TerminalTheme> {
|
|
|
- if (colorfgbg !== undefined) {
|
|
|
- process.env.COLORFGBG = colorfgbg;
|
|
|
+ async function detect(opts?: { colorfgbg?: string; platform?: string }): Promise<TerminalTheme> {
|
|
|
+ if (opts?.colorfgbg !== undefined) {
|
|
|
+ process.env.COLORFGBG = opts.colorfgbg;
|
|
|
} else {
|
|
|
delete process.env.COLORFGBG;
|
|
|
}
|
|
|
+ if (opts?.platform) {
|
|
|
+ Object.defineProperty(process, "platform", { value: opts.platform });
|
|
|
+ }
|
|
|
const mod = await import("../theme.js");
|
|
|
return mod.detectTerminalTheme();
|
|
|
}
|
|
|
|
|
|
- it("defaults to dark when COLORFGBG is not set", async () => {
|
|
|
- expect(await detect()).toBe("dark");
|
|
|
- });
|
|
|
-
|
|
|
- it("detects dark background from COLORFGBG with bg index 0", async () => {
|
|
|
- expect(await detect("15;0")).toBe("dark");
|
|
|
+ it("detects dark background from COLORFGBG bg index 0", async () => {
|
|
|
+ expect(await detect({ colorfgbg: "15;0" })).toBe("dark");
|
|
|
});
|
|
|
|
|
|
- it("detects dark background from three-part COLORFGBG", async () => {
|
|
|
- expect(await detect("15;0;0")).toBe("dark");
|
|
|
+ it("detects dark from three-part COLORFGBG", async () => {
|
|
|
+ expect(await detect({ colorfgbg: "15;0;0" })).toBe("dark");
|
|
|
});
|
|
|
|
|
|
- it("detects light background from COLORFGBG with bg index 15", async () => {
|
|
|
- expect(await detect("0;15")).toBe("light");
|
|
|
+ it("detects light background from COLORFGBG bg index 15", async () => {
|
|
|
+ expect(await detect({ colorfgbg: "0;15" })).toBe("light");
|
|
|
});
|
|
|
|
|
|
- it("detects light background from bg index 7", async () => {
|
|
|
- expect(await detect("0;7")).toBe("light");
|
|
|
+ it("detects light from bg index 7", async () => {
|
|
|
+ expect(await detect({ colorfgbg: "0;7" })).toBe("light");
|
|
|
});
|
|
|
|
|
|
it("treats index 8 as dark", async () => {
|
|
|
- expect(await detect("15;8")).toBe("dark");
|
|
|
+ expect(await detect({ colorfgbg: "15;8" })).toBe("dark");
|
|
|
});
|
|
|
|
|
|
- it("defaults to dark for unparseable values", async () => {
|
|
|
- expect(await detect("garbage")).toBe("dark");
|
|
|
+ it("defaults to dark on non-darwin without COLORFGBG", async () => {
|
|
|
+ expect(await detect({ platform: "linux" })).toBe("dark");
|
|
|
});
|
|
|
});
|