feat(P2): 实现质量保障类5项功能(无障碍/视觉回归/通知渠道/漏洞扫描/灾备)
## 新增功能 ### 1. 屏幕阅读器兼容性增强(a11y) - 无障碍工具库:src/shared/lib/a11y.ts - aria-live Hook:src/shared/hooks/use-aria-live.ts - a11y 组件:skip-link/visually-hidden/focus-trap/aria-status - 增强 UI:table.tsx 系统性 ARIA role,dialog.tsx aria-modal - 审计文档:docs/accessibility/a11y-audit.md(WCAG 2.1 AA 清单) ### 2. 视觉回归测试 - 测试套件:tests/visual/(homepage + 3 个 dashboard) - 3 视口(desktop/tablet/mobile)× 2 主题(light/dark) - 动态元素遮罩,避免误报 - playwright.config.ts 新增 visual-chromium 项目 - 文档:docs/testing/visual-regression.md ### 3. 短信/微信推送渠道集成 - 新模块:src/modules/notifications/ - 4 个渠道:SMS(阿里云/腾讯云)、WeChat(公众号)、Email(SMTP)、In-App - 分发器按用户偏好并行多渠道发送 - 外部 SDK 动态 import,Mock 模式开发可用 - 文档:docs/notifications/channels.md ### 4. 漏洞扫描 CI 集成 - CI security-scan job:npm audit + Snyk + Trivy FS + OWASP ZAP - 独立工作流 security.yml:每周一深度扫描 + 容器镜像扫描 - 配置:suppressions.json + .trivyignore - 本地脚本:security-scan.sh/ps1 - 文档:docs/security/scanning.md(SLA 分级) ### 5. 灾备方案 - 脚本:backup-verify/backup-offsite-sync/dr-drill/failover/health-check - CI 增强:备份后校验+异地同步,每周灾备演练 - 独立工作流 dr-drill.yml:每周一凌晨 4 点自动演练 - 文档:docs/dr/dr-plan.md(RTO 4h/RPO 24h)+ dr-runbook.md(6 故障场景) ## 验证 - npx tsc --noEmit:0 错误 - npm run lint:0 错误 0 警告
This commit is contained in:
102
tests/visual/visual.config.ts
Normal file
102
tests/visual/visual.config.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* 视觉回归测试配置
|
||||
*
|
||||
* 定义需要视觉测试的页面、视口尺寸、主题以及快照存储路径。
|
||||
* 被 tests/visual 下的 spec 文件与 helpers 共享使用。
|
||||
*/
|
||||
|
||||
/** 视口尺寸标识 */
|
||||
export type ViewportSize = "desktop" | "tablet" | "mobile"
|
||||
|
||||
/** 主题标识 */
|
||||
export type ThemeName = "light" | "dark"
|
||||
|
||||
/** 角色标识 */
|
||||
export type UserRole = "admin" | "teacher" | "student"
|
||||
|
||||
/** 视口像素配置 */
|
||||
export const VIEWPORTS: Record<ViewportSize, { width: number; height: number }> = {
|
||||
desktop: { width: 1920, height: 1080 },
|
||||
tablet: { width: 768, height: 1024 },
|
||||
mobile: { width: 375, height: 812 },
|
||||
}
|
||||
|
||||
/** 主题列表 */
|
||||
export const THEMES: ThemeName[] = ["light", "dark"]
|
||||
|
||||
/** 视口列表 */
|
||||
export const VIEWPORT_LIST: ViewportSize[] = ["desktop", "tablet", "mobile"]
|
||||
|
||||
/** 快照基线存储目录(相对项目根) */
|
||||
export const SNAPSHOT_BASE_DIR = "tests/visual/__screenshots__"
|
||||
|
||||
/** storageState 存储目录(相对项目根) */
|
||||
export const STORAGE_STATE_DIR = "tests/visual/.auth"
|
||||
|
||||
/** 角色对应的登录后仪表盘路由 */
|
||||
export const DASHBOARD_ROUTES: Record<UserRole, string> = {
|
||||
admin: "/admin/dashboard",
|
||||
teacher: "/teacher/dashboard",
|
||||
student: "/student/dashboard",
|
||||
}
|
||||
|
||||
/** 视觉测试目标页面定义 */
|
||||
export interface VisualPageTarget {
|
||||
/** 页面名称,用于快照命名 */
|
||||
name: string
|
||||
/** 相对 baseURL 的路径 */
|
||||
path: string
|
||||
/** 是否需要登录 */
|
||||
requiresAuth: boolean
|
||||
/** 登录角色(requiresAuth=true 时必填) */
|
||||
role?: UserRole
|
||||
/** 页面描述 */
|
||||
description: string
|
||||
}
|
||||
|
||||
/** 需要进行视觉测试的页面清单 */
|
||||
export const VISUAL_PAGES: VisualPageTarget[] = [
|
||||
{
|
||||
name: "homepage",
|
||||
path: "/login",
|
||||
requiresAuth: false,
|
||||
description: "登录页",
|
||||
},
|
||||
{
|
||||
name: "admin-dashboard",
|
||||
path: "/admin/dashboard",
|
||||
requiresAuth: true,
|
||||
role: "admin",
|
||||
description: "管理员仪表盘",
|
||||
},
|
||||
{
|
||||
name: "teacher-dashboard",
|
||||
path: "/teacher/dashboard",
|
||||
requiresAuth: true,
|
||||
role: "teacher",
|
||||
description: "教师仪表盘",
|
||||
},
|
||||
{
|
||||
name: "student-dashboard",
|
||||
path: "/student/dashboard",
|
||||
requiresAuth: true,
|
||||
role: "student",
|
||||
description: "学生仪表盘",
|
||||
},
|
||||
]
|
||||
|
||||
/** toHaveScreenshot 的默认选项 */
|
||||
export const SCREENSHOT_DEFAULT_OPTIONS = {
|
||||
maxDiffPixelRatio: 0.01,
|
||||
animations: "disabled" as const,
|
||||
caret: "hide" as const,
|
||||
scale: "css" as const,
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成快照文件名
|
||||
* @example homepage-desktop-light.png
|
||||
*/
|
||||
export function snapshotName(pageName: string, viewport: ViewportSize, theme: ThemeName): string {
|
||||
return `${pageName}-${viewport}-${theme}.png`
|
||||
}
|
||||
Reference in New Issue
Block a user