Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

themeCssHooks.test.ts

28 lines1.2 KB

1// @effect-diagnostics nodeBuiltinImport:off - a plain test that scans the source tree once.
2import * as NodeFS from "node:fs";
3import * as NodePath from "node:path";
4​
5import { THEME_CSS_HOOKS } from "@t3tools/shared/themeCss";
6import { expect, it } from "vite-plus/test";
7​
8const sourceDirectory = import.meta.dirname;
9const source = NodeFS.readdirSync(sourceDirectory, { recursive: true, encoding: "utf8" })
10 .filter((file) => /\.(tsx?|css)$/.test(file) && !file.includes(".test."))
11 .map((file) => NodeFS.readFileSync(NodePath.join(sourceDirectory, file), "utf8"))
12 .join("\n");
13​
14/** How the selector's hook is written in source: an attribute, a slot value, or a class name. */
15function sourcePattern(selector: string): RegExp {
16 const slot = /^\[data-slot="([a-z-]+)"\]$/.exec(selector)?.[1];
17 if (slot) return new RegExp(`data-slot["']?\\s*[:=]\\s*["']${slot}["']`);
18 const attribute = /^\[(data-[a-z-]+)/.exec(selector)?.[1];
19 return new RegExp(`\\b${attribute ?? selector.slice(1)}\\b`);
21​
22// Theme CSS and the agent guide rely on these selectors. Rename one in the guide too.
23it.each(THEME_CSS_HOOKS.map((hook) => hook.selector))(
24 "%s is still in the web source",
25 (selector) => {
26 expect(source).toMatch(sourcePattern(selector));
27 },
28);