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});