Files
fusion/packages/dashboard/app/test/cssFixture.ts
Fusion e81d090d8e feat(FN-3011): merge fusion/fn-3011
Commits merged:
- test(FN-3011): complete Step 2 — harden light-theme source assertions
- feat(FN-3011): complete Step 1 — restore global token scope
- fix(FN-3011): complete Step 3 — satisfy lint/test/typecheck/build gates
- test(FN-3011): complete Step 2 — harden light-theme source assertions
- feat(FN-3011): complete Step 1 — restore default light token ownership

Files changed:
.../app/__tests__/status-colors-theme.test.ts      | 100 +++++--
 .../app/components/CustomModelDropdown.css         |   6 -
 .../__tests__/ModelOnboardingModal.test.tsx        |   4 +-
 packages/dashboard/app/styles.css                  | 299 +++++++++++----------
 packages/dashboard/app/test/cssFixture.ts          |  11 +-
 5 files changed, 242 insertions(+), 178 deletions(-)

Fusion-Task-Id: FN-3011
2026-04-29 22:18:18 -07:00

65 lines
2.2 KiB
TypeScript

import { readFileSync, readdirSync } from "node:fs";
import { join, resolve } from "node:path";
const APP_DIR = resolve(__dirname, "..");
const COMPONENTS_DIR = join(APP_DIR, "components");
let cached: string | null = null;
let stylesCached: string | null = null;
export function loadStylesCss(): string {
if (stylesCached !== null) return stylesCached;
stylesCached = readFileSync(join(APP_DIR, "styles.css"), "utf-8");
return stylesCached;
}
export function loadAllAppCss(): string {
if (cached !== null) return cached;
// styles.css first (preserves all section-marker positions for legacy slice
// tests), then component CSS files in alphabetical order. This keeps both
// styles.css's intra-file order intact AND lets co-located component base
// rules be matched before any cross-file @media override referencing them.
// NOTE: public/theme-data.css is intentionally excluded here; tests that
// validate per-color-theme contracts should load it explicitly.
const parts: string[] = [loadStylesCss()];
const entries = readdirSync(COMPONENTS_DIR, { withFileTypes: true })
.filter((e) => e.isFile() && e.name.endsWith(".css"))
.map((e) => e.name)
.sort();
for (const name of entries) {
parts.push(readFileSync(join(COMPONENTS_DIR, name), "utf-8"));
}
cached = parts.join("\n");
return cached;
}
/**
* Returns the combined CSS with all @media (and other at-rule) blocks
* stripped out. Useful for tests that need to match a selector's BASE rule
* (top-level, not inside a media query) and want to avoid false matches
* against @media overrides that happen to come earlier in the source order.
*/
export function loadAllAppCssBaseOnly(): string {
const src = loadAllAppCss();
// Walk and excise any top-level @<rule> { ... } block (e.g. @media, @supports)
let out = "";
let i = 0;
while (i < src.length) {
if (src[i] === "@") {
const open = src.indexOf("{", i);
if (open === -1) { out += src.slice(i); break; }
let depth = 1;
let j = open + 1;
while (j < src.length && depth > 0) {
if (src[j] === "{") depth++;
else if (src[j] === "}") depth--;
j++;
}
i = j;
continue;
}
out += src[i++];
}
return out;
}