Files
aurora-admin/tools/run-site-smoke.mjs
T
aurora-admin eb25feedaf feat(S6-P21): 组件族参数化(13族/44成员/导航族15文件同源/79→48概念组件)
【本次核心 · S6-P21】
- 族层数据:families.json + 44 份契约注入 family/familyRole/familyParams;
  data.json / data.js / site/details 同步。13 族 / 44 成员 / 35 独立 → 概念组件 79→48。
- 79 个 slug 全保留、集合逐一不变(铁律 5 对外承诺未破);frameworks 仍 395 文件、薄壳仍 79。
- 归族判据为契约中可核对字段(semanticTypeCandidates 重叠 / anatomy 为同一骨架子集 /
  变体维度同构 / doNotInvent 显式从属声明),每族 mergeBasis 写明依据,不按名字猜。
- 实现层合并(导航族端到端切片):tools/gen-family-impl.mjs 从 5 端模板生成
  TopMenu / SideMenu / MixedNavigation 共 15 文件,参数 direction=top|side|mixed;
  三份 CSS md5 完全相同 = 一份样式表服务三个组件。
- 新增 tools/gen-families.mjs、tools/gen-family-impl.mjs、tools/verify-families.mjs、
  tools/lib/family-model.mjs、tools/lib/family-impl/nav-menu/*.tpl。

【同时清掉此前已完成但未提交的批次】
生成物(data.json / data.js / site/sources / site/components 薄壳 / sitemap.xml / tests 报告)
跨阶段交织,无法拆成互相自洽的多个提交,故按既有批量风格合并提交:
- Package:三端可 import(S5-P18)+ 发布到私有 npm 源
- Docs site:导航语言改下拉(S5-P19)、详情页代码块默认展开、中英切换完整性
- Security:生产部署链审计修复(2026-09-19)+ 线上部署
- Theme modes 日间/夜间/自动;S1-P4 data.js 瘦身;S2-P5 暗色;S2-P6 跨端一致性;
  S2-P7 行为断言;S2-P9 FAQ;S3-P8 RTL;S3-P9 契约缺口解释层;S4-P12 发布流程
- 补入 tools/pack-deploy.mjs、run-site-smoke.mjs、verify-*.mjs,.dockerignore、
  安全审计修复与待决策项.md

【验收】
- node tools/verify-families.mjs → OK: 族层端到端一致(13 族 / 44 成员 / 79 组件不变 / 395 文件不变)
- node tools/verify-cross-platform.mjs → 79/79 identical(HEAD 基线 high 44)
- node tools/run-regression.mjs → 100%(79/79 页,1017/1017 断言,N/A 34),连跑 8 次一致,0 超时
- 逐页实测:topmenu / sidemenu / mixednavigation 各 13/13,帧内 direction 参数正确,0 JS 错误
- 零运行时依赖 OK;build-site.ps1 ASCII-only OK

【未纳入】site/components/<slug>/ 平台薄壳 316 个 —— 历史从未跟踪且属构建产物,保持现状。
2026-09-20 03:32:31 +08:00

89 lines
5.8 KiB
JavaScript

#!/usr/bin/env node
/**
* run-site-smoke.mjs — browser smoke test for the documentation language switch.
* Start node site/dev-server.js first, then run this file.
*/
import { chromium } from 'playwright';
const BASE = process.env.REG_BASE || 'http://127.0.0.1:3311';
const url = `${BASE}/site/index.html`;
const failures = [];
function assert(condition, message) {
if (!condition) failures.push(message);
console.log(`[site-smoke] ${condition ? 'OK' : 'FAIL'} ${message}`);
}
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
try {
await page.goto(`${url}#/component/button`, { waitUntil: 'networkidle', timeout: 15000 });
await page.evaluate(() => localStorage.removeItem('aa-lang'));
await page.reload({ waitUntil: 'networkidle' });
await page.waitForSelector('#content .detail-head', { timeout: 10000 });
assert(await page.locator('html').getAttribute('lang') === 'zh-CN', 'default language is zh-CN');
assert((await page.locator('#lang-cur').textContent()).trim() === '简体中文', 'language trigger shows the current language');
assert(await page.locator('#lang-trigger').getAttribute('aria-expanded') === 'false', 'language menu starts collapsed');
assert(await page.locator('#lang-menu .lang-opt[data-lang="zh"]').getAttribute('aria-selected') === 'true', 'zh option is marked selected');
assert((await page.locator('.topnav a[data-nav="overview"]').textContent()).trim() === '组件', 'Chinese navigation is visible');
assert((await page.title()) === 'Aurora Admin · 组件库文档', 'Chinese document title is visible');
assert(await page.locator('#fw-select').inputValue() === 'h5', 'default framework is h5');
// 下拉行为:展开 → Esc 关闭 → 方向键展开并聚焦当前语言 → 选中英语
await page.locator('#lang-trigger').click();
assert(await page.locator('#lang-trigger').getAttribute('aria-expanded') === 'true', 'trigger reports aria-expanded=true');
assert(await page.locator('#lang-menu').isVisible(), 'menu is visible after clicking the trigger');
await page.keyboard.press('Escape');
assert(!(await page.locator('#lang-menu').isVisible()), 'Escape closes the menu');
assert(await page.locator('#lang-trigger').getAttribute('aria-expanded') === 'false', 'Escape resets aria-expanded');
await page.locator('#fw-select').selectOption('react');
await page.locator('#lang-trigger').focus();
await page.keyboard.press('ArrowDown');
assert(await page.evaluate(() => document.activeElement?.getAttribute('data-lang')) === 'zh', 'ArrowDown opens the menu and focuses the current language');
await page.keyboard.press('ArrowDown');
assert(await page.evaluate(() => document.activeElement?.getAttribute('data-lang')) === 'en', 'ArrowDown moves focus to the next language');
await page.keyboard.press('Enter');
await page.waitForFunction(() => document.documentElement.lang === 'en');
await page.waitForSelector('#content .detail-head');
assert(await page.locator('html').getAttribute('lang') === 'en', 'switch updates html lang to en');
assert((await page.locator('#lang-cur').textContent()).trim() === 'English', 'language trigger shows English after switching');
assert(await page.locator('#lang-menu .lang-opt[data-lang="en"]').getAttribute('aria-selected') === 'true', 'en option is marked selected');
assert(await page.evaluate(() => document.activeElement?.id) === 'lang-trigger', 'focus returns to the trigger after choosing');
assert((await page.locator('.topnav a[data-nav="overview"]').textContent()).trim() === 'Components', 'English navigation is visible');
assert((await page.title()) === 'Aurora Admin · Component Library', 'English document title is visible');
assert(await page.evaluate(() => localStorage.getItem('aa-lang')) === 'en', 'English preference is persisted');
assert(await page.locator('#fw-select').inputValue() === 'react', 'framework selection survives language switch');
assert((await page.locator('#content .detail-head h1').textContent()).includes('Button'), 'component name switches to English');
assert((await page.locator('#toc').textContent()).includes('When to Use'), 'component TOC switches to English');
await page.locator('#fab-theme').click();
assert((await page.locator('#theme-panel .tp-head').textContent()).trim() === 'Theme', 'theme panel switches to English');
await page.locator('#fab-theme').click();
await page.goto(`${url}#/overview`, { waitUntil: 'networkidle' });
await page.waitForSelector('#content .page-title');
assert((await page.locator('#content .page-title').textContent()).trim() === 'All Components', 'English route navigation remains active');
await page.reload({ waitUntil: 'networkidle' });
await page.waitForSelector('#content .page-title');
assert(await page.locator('html').getAttribute('lang') === 'en', 'English preference survives reload');
assert((await page.locator('#content .page-title').textContent()).trim() === 'All Components', 'English route content survives reload');
await page.locator('#lang-trigger').click();
await page.locator('#lang-menu .lang-opt[data-lang="zh"]').click();
await page.waitForFunction(() => document.documentElement.lang === 'zh-CN');
assert((await page.locator('#lang-cur').textContent()).trim() === '简体中文', 'language trigger shows the current language again');
assert(await page.evaluate(() => localStorage.getItem('aa-lang')) === 'zh', 'Chinese preference is persisted after switching back');
assert((await page.locator('#content .page-title').textContent()).trim() === '组件总览', 'Chinese content restores after switching back');
} finally {
await browser.close();
}
if (failures.length) {
console.error(`\n[site-smoke] ${failures.length} check(s) failed`);
process.exit(1);
}
console.log('\n[site-smoke] OK — all checks passed');