Files
openclaw-zero-token/scripts/test-report-utils.test.ts
sjhu 571e14a236 feat: upgrade to upstream v2026.3.28
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
2026-03-30 17:58:12 +08:00

72 lines
2.2 KiB
TypeScript

import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import {
collectVitestFileDurations,
normalizeTrackedRepoPath,
tryReadJsonFile,
} from "../../scripts/test-report-utils.mjs";
describe("scripts/test-report-utils normalizeTrackedRepoPath", () => {
it("normalizes repo-local absolute paths to repo-relative slash paths", () => {
const absoluteFile = path.join(process.cwd(), "src", "tools", "example.test.ts");
expect(normalizeTrackedRepoPath(absoluteFile)).toBe("src/tools/example.test.ts");
});
it("preserves external absolute paths as normalized absolute paths", () => {
const externalFile = path.join(path.parse(process.cwd()).root, "tmp", "outside.test.ts");
expect(normalizeTrackedRepoPath(externalFile)).toBe(externalFile.split(path.sep).join("/"));
});
});
describe("scripts/test-report-utils collectVitestFileDurations", () => {
it("extracts per-file durations and applies file normalization", () => {
const report = {
testResults: [
{
name: path.join(process.cwd(), "src", "alpha.test.ts"),
startTime: 100,
endTime: 460,
assertionResults: [{}, {}],
},
{
name: "src/zero.test.ts",
startTime: 300,
endTime: 300,
assertionResults: [{}],
},
],
};
expect(collectVitestFileDurations(report, normalizeTrackedRepoPath)).toEqual([
{
file: "src/alpha.test.ts",
durationMs: 360,
testCount: 2,
},
]);
});
});
describe("scripts/test-report-utils tryReadJsonFile", () => {
it("returns the fallback when the file is missing", () => {
const missingPath = path.join(os.tmpdir(), `openclaw-missing-${Date.now()}.json`);
expect(tryReadJsonFile(missingPath, { ok: true })).toEqual({ ok: true });
});
it("reads valid JSON files", () => {
const tempPath = path.join(os.tmpdir(), `openclaw-json-${Date.now()}.json`);
fs.writeFileSync(tempPath, JSON.stringify({ ok: true }));
try {
expect(tryReadJsonFile(tempPath, null)).toEqual({ ok: true });
} finally {
fs.unlinkSync(tempPath);
}
});
});