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
+22 -4
View File
@@ -26,12 +26,26 @@ const PAGES = [
{ path: '/contact', name: '联系我们' },
];
// 负 PID = 杀整个进程组:`npm run preview` 只是包装进程,真正 LISTEN :3000 的是 next-server 孙进程;
// 只 kill 包装进程会让孙进程被 init 收养继续占端口,下一轮 E2E / Lighthouse 会静默复用它。
let serverStopped = false;
function stopServer(server) {
if (!server || !server.pid || serverStopped) return;
serverStopped = true;
try {
process.kill(-server.pid, 'SIGTERM');
} catch {
/* 进程组已自行退出 */
}
}
function startServer() {
return new Promise((resolve, reject) => {
const server = spawn('npm', ['run', 'preview'], {
cwd: path.resolve(__dirname, '..'),
stdio: 'pipe',
shell: true,
detached: true,
});
server.stdout.on('data', (data) => {
@@ -58,8 +72,11 @@ async function waitForServer(url, retries = 30) {
const res = await fetch(url, { method: 'HEAD' });
if (res.ok || res.status === 404) return;
} catch {
await new Promise((r) => setTimeout(r, 1000));
// 服务未起:连接被拒
}
// 就绪等待必须每轮都退避:启动期返回 503/500 等非 ok 状态时,
// 若只在 catch 里 sleep,30 次重试会在毫秒内跑完并误报「服务未就绪」。
await new Promise((r) => setTimeout(r, 1000));
}
throw new Error(`Server at ${url} did not become ready in time`);
}
@@ -137,14 +154,15 @@ async function runAudit() {
require('fs').writeFileSync(reportPath, JSON.stringify(results, null, 2));
console.log(`\n📝 详细报告已保存: ${reportPath}`);
// process.exit() 不会执行 finally,所以两处出口都得自己收服服务再退出。
stopServer(server);
process.exit(totalViolations > 0 ? 1 : 0);
} catch (error) {
console.error('审计执行失败:', error);
stopServer(server);
process.exit(1);
} finally {
if (server) {
server.kill('SIGTERM');
}
stopServer(server);
}
}