import type { Plugin } from 'vite'; import { describe, expect, it } from 'vitest'; import viteConfig from '../vite.config'; async function resolveRetiredCssPlugin() { const resolvedConfig = typeof viteConfig === 'function' ? await viteConfig({ command: 'serve', mode: 'test' }) : viteConfig; const plugins = (resolvedConfig.plugins ?? []).flat(Infinity) as Plugin[]; return plugins.find( (plugin) => plugin?.name === 'retired-creation-template-css', ); } describe('retired creation template CSS plugin', () => { it('runs before Tailwind turns source CSS into a Vite JavaScript module', async () => { const plugin = await resolveRetiredCssPlugin(); expect(plugin).toBeDefined(); expect(plugin?.enforce).toBe('pre'); }); it('keeps the active creation landing CSS while removing retired template CSS', async () => { const plugin = await resolveRetiredCssPlugin(); const transform = plugin?.transform; expect(typeof transform).toBe('function'); if (typeof transform !== 'function') { return; } const result = await transform.call( {} as never, "@import 'tailwindcss';\n.creation-landing { color: red; }\n.puzzle-runtime { color: blue; }", '/workspace/src/index.css', ); const code = typeof result === 'string' ? result : result?.code; expect(code).toContain('.creation-landing'); expect(code).not.toContain('.puzzle-runtime'); expect(code).toContain('@source "./components/creation-home"'); }); });