Files
novalon-website/config/test/itest/global-teardown.js
T
zhangxiang 6bb7c557ee 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
  配置收敛。
2026-09-28 10:48:08 +08:00

60 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// @ts-nocheck
/**
* 集成测试 globalTeardown:删除一次性临时库,并最终复验项目数据源从未被打开或写入。
* 若发现指纹漂移,这里直接抛错让整条流水线变红 —— 安全保证必须是可失败的断言,
* 而不是日志里的温馨提示。
*/
const fs = require('fs');
const path = require('path');
const guard = require('./env.js');
function stamp(msg) {
console.log(`[itest:teardown] ${msg}`);
}
module.exports = async function globalTeardown() {
let manifest = null;
try {
manifest = JSON.parse(fs.readFileSync(guard.MANIFEST_PATH, 'utf8'));
} catch {
stamp('未找到 manifest(globalSetup 可能未执行);仍执行清理与守卫');
}
const now = guard.devDbBaselines();
if (manifest?.baseline) {
const drift = Object.keys(manifest.baseline).filter(
(k) => !guard.sameFingerprint(manifest.baseline[k], now[k]),
);
if (drift.length > 0) {
throw new Error(
`[itest:teardown] 安全事故:项目数据源在集成测试期间被改动 → ${JSON.stringify(drift, null, 2)}`,
);
}
}
for (const f of [
guard.DB_PATH,
`${guard.DB_PATH}-journal`,
`${guard.DB_PATH}-wal`,
`${guard.DB_PATH}-shm`,
guard.DDL_PATH,
guard.MANIFEST_PATH,
`${guard.MANIFEST_PATH}.apply.json`,
`${guard.MANIFEST_PATH}.baseline.json`,
]) {
if (!f.startsWith(`${guard.TMP_REALPATH}${path.sep}`)) {
throw new Error(`[itest:teardown] 拒绝删除非临时目录文件 ${f}`);
}
try {
fs.rmSync(f);
stamp(`removed ${f}`);
} catch {
/* 已不存在 */
}
}
stamp(`project dbs after run = ${JSON.stringify(now)}`);
stamp('守卫通过:prisma/dev.db / dev.db / data.db 的 inode+size+mtime 与运行前完全一致');
};