Files
oh-my-pi/packages/git-tool/test/helpers.ts
T
can1357 b2c94bef1a refactor(deps): restructured codebase to use centralized pi-utils package
- Created new @oh-my-pi/pi-utils workspace package with shared utilities for logging, process management, stream handling, and temporary directory management.
- Migrated all packages to use centralized logger from @oh-my-pi/pi-utils instead of local winston implementations.
- Replaced custom process spawning and stream reading implementations with standardized cspawn and readLines utilities across all modules.
- Converted synchronous file operations and process spawning to async patterns using Bun shell syntax and fs/promises.
- Added streaming edit abort functionality with configurable setting to abort on patch preview failures.
- Updated test framework from vitest to bun:test across all test suites.
2026-01-20 05:33:21 +01:00

47 lines
1.2 KiB
TypeScript

import { writeFileSync } from "node:fs";
import { join } from "node:path";
import { createTempDirSync } from "@oh-my-pi/pi-utils";
import { type ExecResult, git } from "../src/utils";
export { git, type ExecResult };
export interface TestRepo {
readonly path: string;
run(...args: string[]): ExecResult;
remove(): void;
writeFile(path: string, content: string): void;
}
export function createTestRepo(): TestRepo {
const tempDir = createTempDirSync("@wt-test-");
const repo = {
_tempDir: tempDir,
path: tempDir.path,
remove: () => tempDir.remove(),
run: (...args: string[]) => {
const result = Bun.spawnSync(["git", ...args], {
cwd: tempDir.path,
stdin: "ignore",
stdout: "pipe",
stderr: "pipe",
});
return {
stdout: result.stdout.toString(),
stderr: result.stderr.toString(),
exitCode: result.exitCode,
};
},
writeFile(path: string, content: string) {
writeFileSync(join(tempDir.path, path), content);
},
};
repo.run("init", "-b", "main");
repo.run("config", "user.email", "test@example.com");
repo.run("config", "user.name", "Test User");
return repo;
}
export function writeFile(path: string, content: string) {
writeFileSync(path, content);
}