Open History to see the last commit
1import * as NodeFS from "node:fs";
2import * as NodePath from "node:path";
3import { describe, expect, it } from "vite-plus/test";
4
5import {
6 customThemeNames,
7 getGeneratedUniwindThemeOutputs,
8 readDefaultThemeVariables,
9 renderUniwindThemesCSS,
10} from "./generate-uniwind-themes.mts";
11
12describe("generate mobile Uniwind themes", () => {
13 it("keeps the committed outputs current", () => {
14 const staleOutputs = getGeneratedUniwindThemeOutputs()
15 .filter(
16 ([filename, contents]) =>
17 !NodeFS.existsSync(filename) || NodeFS.readFileSync(filename, "utf8") !== contents,
18 )
19 .map(([filename]) => NodePath.relative(import.meta.dirname, filename));
20
21 expect(
22 staleOutputs,
23 "Run `vp run --filter @t3tools/mobile generate` and commit the generated outputs.",
24 ).toEqual([]);
25 });
26
27 it("registers every custom palette for both appearances", () => {
28 expect(customThemeNames).toEqual([
29 "t3-chat-light",
30 "t3-chat-dark",
31 "grove-light",
32 "grove-dark",
33 "ocean-light",
34 "ocean-dark",
35 "ember-light",
36 "ember-dark",
37 "iris-light",
38 "iris-dark",
39 ]);
40
41 const stylesheet = renderUniwindThemesCSS();
42 for (const themeName of customThemeNames) {
43 expect(stylesheet.match(new RegExp(`@variant ${themeName} \\{`, "gu"))).toHaveLength(1);
44 }
45 });
46
47 it("generates the default runtime bridge from the authored CSS", () => {
48 const css = NodeFS.readFileSync(NodePath.resolve(import.meta.dirname, "../global.css"), "utf8");
49 const variables = readDefaultThemeVariables(css);
50
51 expect(variables.light["--color-screen"]).toBe("#f2f2f7");
52 expect(variables.dark["--color-screen"]).toBe("#0a0a0a");
53 expect(Object.keys(variables.light)).toEqual(Object.keys(variables.dark));
54 });
55
56 it("gives every theme the same variables and a fixed Clerk palette for its appearance", () => {
57 const css =
58 NodeFS.readFileSync(NodePath.resolve(import.meta.dirname, "../global.css"), "utf8") +
59 renderUniwindThemesCSS();
60 const themes = new Map<string, Map<string, string>>(
61 ["light", "dark", ...customThemeNames].map((name) => [name, new Map()]),
62 );
63 for (const [, name, body] of css.matchAll(/@variant ([\w-]+) \{([^}]+)\}/gu)) {
64 const variables = themes.get(name!);
65 for (const [, variable, value] of body!.matchAll(/(--[\w-]+):\s*([^;]+);/gu)) {
66 variables?.set(variable!, value!.trim().toLowerCase());
67 }
68 }
69
70 const lightVariables = themes.get("light")!;
71 for (const [name, variables] of themes) {
72 expect([...variables.keys()].sort(), name).toEqual([...lightVariables.keys()].sort());
73 const isDark = name === "dark" || name.endsWith("-dark");
74 expect(
75 Object.fromEntries(
76 [...variables].filter(([variable]) => variable.startsWith("--color-clerk-")),
77 ),
78 name,
79 ).toEqual({
80 "--color-clerk-page": isDark ? "#0e0e0e" : "#f2f2f7",
81 "--color-clerk-foreground": isDark ? "#f5f5f5" : "#262626",
82 "--color-clerk-foreground-muted": isDark ? "#a3a3a3" : "#737373",
83 "--color-clerk-border": isDark ? "rgba(42, 42, 42, 0.06)" : "rgba(229, 229, 234, 0.06)",
84 "--color-clerk-danger": isDark ? "#fca5a5" : "#dc2626",
85 });
86 }
87 });
88});