refactor: dedupe test and script helpers

This commit is contained in:
Peter Steinberger
2026-03-24 15:47:44 +00:00
parent 66e954858b
commit 781295c14b
56 changed files with 2277 additions and 3522 deletions

View File

@@ -1,50 +1,15 @@
import {
collectVitestFileDurations,
readJsonFile,
runVitestJsonReport,
} from "./test-report-utils.mjs";
formatMs,
loadVitestReportFromArgs,
parseVitestReportArgs,
} from "./lib/vitest-report-cli-utils.mjs";
import { collectVitestFileDurations } from "./test-report-utils.mjs";
function parseArgs(argv) {
const args = {
config: "vitest.unit.config.ts",
limit: 20,
reportPath: "",
};
for (let i = 0; i < argv.length; i += 1) {
const arg = argv[i];
if (arg === "--config") {
args.config = argv[i + 1] ?? args.config;
i += 1;
continue;
}
if (arg === "--limit") {
const parsed = Number.parseInt(argv[i + 1] ?? "", 10);
if (Number.isFinite(parsed) && parsed > 0) {
args.limit = parsed;
}
i += 1;
continue;
}
if (arg === "--report") {
args.reportPath = argv[i + 1] ?? "";
i += 1;
continue;
}
}
return args;
}
function formatMs(value) {
return `${value.toFixed(1)}ms`;
}
const opts = parseArgs(process.argv.slice(2));
const reportPath = runVitestJsonReport({
config: opts.config,
reportPath: opts.reportPath,
prefix: "openclaw-vitest-hotspots",
const opts = parseVitestReportArgs(process.argv.slice(2), {
config: "vitest.unit.config.ts",
limit: 20,
});
const report = readJsonFile(reportPath);
const report = loadVitestReportFromArgs(opts, "openclaw-vitest-hotspots");
const fileResults = collectVitestFileDurations(report).toSorted(
(a, b) => b.durationMs - a.durationMs,
);