import { mkdtempSync, rmSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, describe, expect, it } from 'vitest' import { extractCssVariables, extractTailwindPreset, } from '../../../scripts/extract-docs-theme' const tempDirs: string[] = [] function createTempDir(): string { const dir = mkdtempSync(join(tmpdir(), 'mint-docs-theme-')) tempDirs.push(dir) return dir } afterEach(() => { for (const dir of tempDirs.splice(0)) { rmSync(dir, { recursive: true, force: true }) } }) describe('extract docs theme helpers', () => { it('groups CSS variables by root comment sections', () => { const dir = createTempDir() const cssPath = join(dir, 'variables.css') writeFileSync(cssPath, ` :root { --spacing-sm: 0.5rem; /* Background colors */ --bg-default: #ffffff; --bg-muted: var(--mint-50); } `) expect(extractCssVariables(cssPath)).toEqual({ General: [ { name: '--spacing-sm', value: '0.5rem' }, ], 'Background colors': [ { name: '--bg-default', value: '#ffffff' }, { name: '--bg-muted', value: 'var(--mint-50)' }, ], }) }) it('extracts Tailwind color groups and font families', () => { const dir = createTempDir() const presetPath = join(dir, 'tailwind.preset.ts') writeFileSync(presetPath, ` export default { theme: { extend: { colors: { mint: { 50: "#f0fdfa", 600: "#0d9488", }, bg: { canvas: "var(--bg-default)", }, }, fontFamily: { sans: ['Inter', 'sans-serif'], mono: ["JetBrains Mono", "monospace"], }, }, }, } `) expect(extractTailwindPreset(presetPath)).toMatchObject({ colors: { mint: { 50: '#f0fdfa', 600: '#0d9488', }, bg: { canvas: 'var(--bg-default)', }, }, fontFamily: { sans: 'Inter', mono: 'JetBrains Mono', }, }) }) })