SPB Git

Repository Public

brand.test.ts 1.4 KB 27 lines typescript

1import { readFileSync } from "node:fs";2import { describe, expect, it } from "vitest";34const tokens = JSON.parse(readFileSync("brand/tokens.json", "utf8")) as { color: Record<"light" | "dark", Record<string, string>> };5const css = readFileSync("src/app/globals.css", "utf8");6const block = (selector: string) => { const at = css.indexOf(`${selector} {`); return css.slice(at, css.indexOf("}", at)); };78describe("design tokens", () => {9  it("are identical in brand/tokens.json and in the stylesheet, for both themes", () => {10    for (const [theme, selector] of [["light", ":root"], ["dark", '[data-theme="dark"]']] as const) {11      const rules = block(selector);12      for (const [name, value] of Object.entries(tokens.color[theme])) expect(rules, `${theme} --${name}`).toContain(`--${name}: ${value};`);13    }14  });15  it("gives the no-JavaScript dark fallback the same values", () => {16    const fallback = css.slice(css.indexOf(":root:not([data-theme])"));17    for (const [name, value] of Object.entries(tokens.color.dark)) expect(fallback, name).toContain(`--${name}: ${value};`);18  });19  it("ships an original vector mark with no external reference", () => {20    for (const file of ["brand/atlas-mark.svg", "brand/atlas-mark-light.svg", "brand/atlas-wordmark.svg", "src/app/icon.svg"]) {21      const svg = readFileSync(file, "utf8");22      expect(svg, file).toMatch(/^<svg /);23      expect(svg, file).not.toMatch(/href=|<image|<script|url\(/);24    }25  });26});27
Files main
Menu

Theme