51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import * as path from 'path';
|
|
import * as fs from 'fs-extra';
|
|
import * as os from 'os';
|
|
import simpleGit from 'simple-git';
|
|
|
|
export async function setupTestRepo(): Promise<string> {
|
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gas-test-'));
|
|
const repoDir = path.join(tempDir, 'test-repo');
|
|
|
|
fs.ensureDirSync(repoDir);
|
|
|
|
const git = simpleGit(repoDir);
|
|
await git.init();
|
|
await git.addConfig('user.email', 'test@example.com');
|
|
await git.addConfig('user.name', 'Test User');
|
|
|
|
fs.writeFileSync(path.join(repoDir, 'README.md'), '# Test Repository\n');
|
|
await git.add('.');
|
|
await git.commit('Initial commit');
|
|
|
|
return repoDir;
|
|
}
|
|
|
|
export async function cleanupTestRepo(repoDir: string): Promise<void> {
|
|
await fs.remove(path.dirname(repoDir));
|
|
}
|
|
|
|
export function createMockGit() {
|
|
return {
|
|
branch: jest.fn().mockResolvedValue({ current: 'main', all: ['main', 'develop'] }),
|
|
status: jest.fn().mockResolvedValue({
|
|
modified: [],
|
|
created: [],
|
|
deleted: [],
|
|
staged: [],
|
|
conflicted: []
|
|
}),
|
|
diff: jest.fn().mockResolvedValue(''),
|
|
raw: jest.fn().mockResolvedValue(''),
|
|
add: jest.fn().mockResolvedValue({}),
|
|
commit: jest.fn().mockResolvedValue({}),
|
|
checkout: jest.fn().mockResolvedValue({}),
|
|
pull: jest.fn().mockResolvedValue({}),
|
|
stash: jest.fn().mockResolvedValue({}),
|
|
log: jest.fn().mockResolvedValue({ latest: null }),
|
|
worktree: jest.fn().mockResolvedValue({}),
|
|
init: jest.fn().mockResolvedValue({}),
|
|
addConfig: jest.fn().mockResolvedValue({})
|
|
};
|
|
}
|