test(scripts): reuse temp dir helpers in repo fixtures

This commit is contained in:
Vincent Koc
2026-04-06 05:36:33 +01:00
parent b1ae35d602
commit 2272eb9ffa
2 changed files with 9 additions and 17 deletions

View File

@@ -1,11 +1,11 @@
import { execFileSync } from "node:child_process";
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { mkdirSync, writeFileSync } from "node:fs";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { describe, expect, it } from "vitest";
import { createScriptTestHarness } from "./test-helpers.js";
const scriptPath = path.join(process.cwd(), "scripts", "committer");
const tempRepos: string[] = [];
const { createTempDir } = createScriptTestHarness();
function run(cwd: string, command: string, args: string[]) {
return execFileSync(command, args, {
@@ -19,8 +19,7 @@ function git(cwd: string, ...args: string[]) {
}
function createRepo() {
const repo = mkdtempSync(path.join(tmpdir(), "committer-test-"));
tempRepos.push(repo);
const repo = createTempDir("committer-test-");
git(repo, "init", "-q");
git(repo, "config", "user.email", "test@example.com");
@@ -47,15 +46,6 @@ function committedPaths(repo: string) {
return output.split("\n").filter(Boolean).toSorted();
}
afterEach(() => {
while (tempRepos.length > 0) {
const repo = tempRepos.pop();
if (repo) {
rmSync(repo, { force: true, recursive: true });
}
}
});
describe("scripts/committer", () => {
it("accepts supported path argument shapes", () => {
const cases = [

View File

@@ -1,15 +1,17 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { stageBundledPluginRuntimeDeps } from "../../scripts/stage-bundled-plugin-runtime-deps.mjs";
import { createScriptTestHarness } from "./test-helpers.js";
const { createTempDir } = createScriptTestHarness();
describe("stageBundledPluginRuntimeDeps", () => {
function createBundledPluginFixture(params: {
packageJson: Record<string, unknown>;
pluginId?: string;
}) {
const repoRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-runtime-deps-"));
const repoRoot = createTempDir("openclaw-runtime-deps-");
const pluginId = params.pluginId ?? "fixture-plugin";
const pluginDir = path.join(repoRoot, "dist", "extensions", pluginId);
fs.mkdirSync(pluginDir, { recursive: true });