mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
35 lines
1.6 KiB
JavaScript
35 lines
1.6 KiB
JavaScript
// Gate: so kết quả test hiện tại với baseline kết quả đã commit.
|
|
// PASS nếu KHÔNG có test nào pass(baseline) → fail(now). Test mới được phép.
|
|
// Usage: node tests/__baseline__/verify-no-regression.mjs <current-results.json>
|
|
import { readFileSync } from "fs";
|
|
|
|
const resultsPath = process.argv[2];
|
|
if (!resultsPath) { console.error("Missing results.json path"); process.exit(2); }
|
|
|
|
const r = JSON.parse(readFileSync(resultsPath, "utf8"));
|
|
const normalizeTestPath = (filePath) => {
|
|
const normalized = String(filePath || "").replaceAll("\\", "/");
|
|
const testsIndex = normalized.lastIndexOf("/tests/");
|
|
return testsIndex >= 0 ? normalized.slice(testsIndex + 1) : normalized;
|
|
};
|
|
const assertionStatuses = (results) => new Map(results.testResults.flatMap(f =>
|
|
f.assertionResults.map(a => [normalizeTestPath(f.name) + " :: " + a.fullName, a.status])
|
|
));
|
|
|
|
const baseline = JSON.parse(readFileSync(new URL("./baseline-results.json", import.meta.url), "utf8"));
|
|
const baselineStatuses = assertionStatuses(baseline);
|
|
const nowFails = r.testResults.flatMap(f =>
|
|
f.assertionResults.filter(a => a.status === "failed")
|
|
.map(a => normalizeTestPath(f.name) + " :: " + a.fullName)
|
|
);
|
|
|
|
// Regression = test từng pass trong baseline nhưng fail bây giờ.
|
|
const regressions = nowFails.filter(name => baselineStatuses.get(name) === "passed");
|
|
|
|
if (regressions.length) {
|
|
console.error(`\n❌ REGRESSION: ${regressions.length} test pass→fail:\n`);
|
|
regressions.forEach(f => console.error(" - " + f));
|
|
process.exit(1);
|
|
}
|
|
console.log(`✅ No regression. (now fails=${nowFails.length}, baseline assertions=${baselineStatuses.size})`);
|