(options?: {
existingBranchName?: string;
currentBranchName?: string;
tempDirPrefix?: string;
})
| 29 | } |
| 30 | |
| 31 | async function createWorktreeManagerFixture(options?: { |
| 32 | existingBranchName?: string; |
| 33 | currentBranchName?: string; |
| 34 | tempDirPrefix?: string; |
| 35 | }) { |
| 36 | const rootDir = await fsPromises.realpath( |
| 37 | await fsPromises.mkdtemp( |
| 38 | path.join(os.tmpdir(), options?.tempDirPrefix ?? "worktree-manager-create-") |
| 39 | ) |
| 40 | ); |
| 41 | const projectPath = path.join(rootDir, "repo"); |
| 42 | await fsPromises.mkdir(projectPath, { recursive: true }); |
| 43 | initGitRepo(projectPath); |
| 44 | |
| 45 | if (options?.currentBranchName) { |
| 46 | execSync(`git checkout -b ${options.currentBranchName}`, { cwd: projectPath, stdio: "ignore" }); |
| 47 | } |
| 48 | |
| 49 | if (options?.existingBranchName) { |
| 50 | execSync(`git branch ${options.existingBranchName}`, { cwd: projectPath, stdio: "ignore" }); |
| 51 | } |
| 52 | |
| 53 | const srcBaseDir = path.join(rootDir, "src"); |
| 54 | await fsPromises.mkdir(srcBaseDir, { recursive: true }); |
| 55 | |
| 56 | return { |
| 57 | rootDir, |
| 58 | projectPath, |
| 59 | manager: new WorktreeManager(srcBaseDir), |
| 60 | initLogger: createNullInitLogger(), |
| 61 | cleanup: () => fsPromises.rm(rootDir, { recursive: true, force: true }), |
| 62 | }; |
| 63 | } |
| 64 | |
| 65 | describe("WorktreeManager constructor", () => { |
| 66 | it("should expand tilde in srcBaseDir", () => { |
no test coverage detected