Files
Genarrative/scripts/vite-retired-css-plugin.test.ts
T
kdletters c56da8dc26 恢复新版创作主页与平台侧栏
恢复 /creation 新版创作工具主页及创作、项目公共侧栏。

将 creation-home 重新纳入 Vite、TypeScript、ESLint 与 Vitest 活动编译链。

恢复 /creation 的 Nginx 与 Pingora SPA 白名单并保留旧子路径下线边界。

补充路由、标题、CSS 过滤和网关 smoke 回归验证。
2026-07-18 15:41:55 +08:00

46 lines
1.5 KiB
TypeScript

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"');
});
});