test(qa): e2e 装配修正 + 集成/门禁测试与工具链重构

- e2e:修死选择器与蜜罐误命中、补断言、GA4/security-headers 用例诚实标注
  skip 边界;新增 assert-helpers/fixtures/hydrated/primary-nav/touch-targets
  等复用桩。
- 集成层:config/test/jest.integration.config.js + tests-integration/ 真库
  一次性 SQLite 用例,teardown 守卫开发库指纹。
- 门禁工具链:jest.setup 归位到根、scripts/accessibility 全站 axe 节点计数、
  check-brand-text-token/check-motion-constraints 机械守卫、stryker/lighthouse
  配置收敛。
This commit is contained in:
2026-09-28 10:48:08 +08:00
parent a366bd1400
commit 6bb7c557ee
142 changed files with 6597 additions and 2653 deletions
+14 -2
View File
@@ -1,4 +1,4 @@
import { test, expect, APIRequestContext } from '@playwright/test';
import { test, expect, APIRequestContext } from './fixtures';
import { config as dotenvConfig } from 'dotenv';
import path from 'path';
@@ -263,6 +263,8 @@ test.describe('CMS 内容发布工作流', { tag: '@critical' }, () => {
test.describe.configure({ mode: 'serial' });
test('admin 可完成 创建草稿 → 提交审核 → 发布 → 前台可见', async ({ request, page }) => {
// N-27 修复:本块原先只有 helper 调用、块级零断言。helper 确有内部断言,
// 但块的终点状态与「前台可见」结果不在块级被证明 ⇒ 补两条块级硬断言。
const suffix = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
const token = await loginAdmin(request);
@@ -271,9 +273,14 @@ test.describe('CMS 内容发布工作流', { tag: '@critical' }, () => {
await submitForReview(request, token, id);
const afterApprove = await approveItem(request, token, id);
console.log('[DEBUG] after approve status=%s slug=%s', afterApprove.status, afterApprove.slug);
// 块级断言 1:工作流终态必须是 published(helper 只内部检查响应,
// 返回值再未被验证过)
expect(afterApprove.status, 'approve 后终态应为 published').toBe('published');
await revalidateNews(request, slug);
console.log('[DEBUG] revalidate done, navigating to /news/%s', slug);
await verifyNewsVisibleOnFrontend(page, request, slug, title, suffix);
// 块级断言 2:验证步骤确实抵达了前台详情 URL(而非停留在别处)
await expect(page).toHaveURL(new RegExp(`/news/${slug}$`));
});
test('非法状态流转会被拦截', async ({ request }) => {
@@ -332,11 +339,16 @@ test.describe('CMS 内容发布工作流', { tag: '@critical' }, () => {
expect(editorApproveResponse.status()).toBe(403);
// 4. 审核员审核通过
// N-27 修复:同 test 1 的口径——helper 内部断言响应,但块的终点状态与
// 「前台可见」结果必须在块级被证明。
const reviewerToken = await login(request, REVIEWER_CREDENTIALS);
await approveItem(request, reviewerToken, id);
const afterApprove = await approveItem(request, reviewerToken, id);
expect(afterApprove.status, '审核员 approve 后终态应为 published').toBe('published');
// 5. 刷新 ISR 缓存并验证前台可见
await revalidateNews(request, slug);
await verifyNewsVisibleOnFrontend(page, request, slug, title, suffix);
// 块级断言:验证步骤确实抵达了前台详情 URL(而非停留在别处)
await expect(page).toHaveURL(new RegExp(`/news/${slug}$`));
});
});