30 lines
912 B
JavaScript
30 lines
912 B
JavaScript
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { spawnSync } from "node:child_process";
|
|
|
|
export function makeTempDir(prefix = "codex-plugin-test-") {
|
|
return fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
}
|
|
|
|
export function writeExecutable(filePath, source) {
|
|
fs.writeFileSync(filePath, source, { encoding: "utf8", mode: 0o755 });
|
|
}
|
|
|
|
export function run(command, args, options = {}) {
|
|
return spawnSync(command, args, {
|
|
cwd: options.cwd,
|
|
env: options.env,
|
|
encoding: "utf8",
|
|
input: options.input
|
|
});
|
|
}
|
|
|
|
export function initGitRepo(cwd) {
|
|
run("git", ["init", "-b", "main"], { cwd });
|
|
run("git", ["config", "user.name", "Codex Plugin Tests"], { cwd });
|
|
run("git", ["config", "user.email", "tests@example.com"], { cwd });
|
|
run("git", ["config", "commit.gpgsign", "false"], { cwd });
|
|
run("git", ["config", "tag.gpgsign", "false"], { cwd });
|
|
}
|