fix: use pnpm exec for scripted vitest runs

This commit is contained in:
Shakker
2026-04-02 11:15:15 +01:00
committed by Peter Steinberger
parent e1143fb95f
commit 9c4ea016d9
4 changed files with 59 additions and 4 deletions

View File

@@ -1,13 +1,21 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { beforeEach, describe, expect, it, vi } from "vitest";
import {
collectVitestFileDurations,
normalizeTrackedRepoPath,
tryReadJsonFile,
} from "../../scripts/test-report-utils.mjs";
const { spawnSyncMock } = vi.hoisted(() => ({
spawnSyncMock: vi.fn(),
}));
vi.mock("node:child_process", () => ({
spawnSync: spawnSyncMock,
}));
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");
@@ -69,3 +77,41 @@ describe("scripts/test-report-utils tryReadJsonFile", () => {
}
});
});
describe("scripts/test-report-utils runVitestJsonReport", () => {
beforeEach(() => {
vi.resetModules();
spawnSyncMock.mockReset();
});
it("launches Vitest through pnpm exec", async () => {
spawnSyncMock.mockReturnValue({ status: 0 });
const reportPath = path.join(os.tmpdir(), `openclaw-vitest-json-${Date.now()}.json`);
const { runVitestJsonReport } = await import("../../scripts/test-report-utils.mjs");
expect(
runVitestJsonReport({
config: "vitest.unit.config.ts",
reportPath,
}),
).toBe(reportPath);
expect(spawnSyncMock).toHaveBeenCalledWith(
"pnpm",
[
"exec",
"vitest",
"run",
"--config",
"vitest.unit.config.ts",
"--reporter=json",
"--outputFile",
reportPath,
],
expect.objectContaining({
stdio: "inherit",
env: process.env,
}),
);
});
});