9c9c8f468a
恢复创作、项目、我的平台侧栏与现役搜索 恢复全宽个人页及资料编辑、充值兑换、社区反馈和 API Key 入口 迁移平台资料、钱包和设置客户端并移除旧创作依赖 新增 Vite 与 ESLint 退役模块门禁并补齐界面和搜索测试 同步旧创作退役方案、平台入口决策与踩坑记录
108 lines
3.3 KiB
TypeScript
108 lines
3.3 KiB
TypeScript
import type { Plugin } from 'vite';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
import viteConfig from '../vite.config';
|
|
|
|
async function resolveVitePlugin(name: string) {
|
|
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 === name);
|
|
}
|
|
|
|
function resolveRetiredCssPlugin() {
|
|
return resolveVitePlugin('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"');
|
|
});
|
|
});
|
|
|
|
describe('retired creation template module boundary plugin', () => {
|
|
it('rejects retired component and service modules from the active Vite graph', async () => {
|
|
const plugin = await resolveVitePlugin('retired-creation-template-modules');
|
|
const transform = plugin?.transform;
|
|
|
|
expect(plugin?.enforce).toBe('pre');
|
|
expect(typeof transform).toBe('function');
|
|
if (typeof transform !== 'function') {
|
|
return;
|
|
}
|
|
|
|
expect(() =>
|
|
transform.call(
|
|
{} as never,
|
|
'export {}',
|
|
'/workspace/src/components/rpg-entry/RpgEntryHomeView.tsx',
|
|
),
|
|
).toThrow(/退役创作模板模块不得进入现役 Vite 依赖图/u);
|
|
expect(() =>
|
|
transform.call(
|
|
{} as never,
|
|
'export {}',
|
|
'/workspace/src/services/rpg-entry/rpgProfileClient.ts?t=1',
|
|
),
|
|
).toThrow(/退役创作模板模块不得进入现役 Vite 依赖图/u);
|
|
});
|
|
|
|
it('allows active creation, project, and profile modules', async () => {
|
|
const plugin = await resolveVitePlugin('retired-creation-template-modules');
|
|
const transform = plugin?.transform;
|
|
|
|
expect(typeof transform).toBe('function');
|
|
if (typeof transform !== 'function') {
|
|
return;
|
|
}
|
|
|
|
expect(
|
|
transform.call(
|
|
{} as never,
|
|
'export {}',
|
|
'/workspace/src/components/creation-home/CreationLandingView.tsx',
|
|
),
|
|
).toBeNull();
|
|
expect(
|
|
transform.call(
|
|
{} as never,
|
|
'export {}',
|
|
'/workspace/src/components/platform-entry/PlatformActiveProfileView.tsx',
|
|
),
|
|
).toBeNull();
|
|
expect(
|
|
transform.call(
|
|
{} as never,
|
|
'export {}',
|
|
'/workspace/src/services/platform-entry/platformProfileClient.ts',
|
|
),
|
|
).toBeNull();
|
|
});
|
|
});
|