Skip to content

Commit badeadf

Browse files
committed
fix(tests): normalize tmp paths in worktree tests
1 parent 4b999f0 commit badeadf

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

tests/lib/worktree.test.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
22
import { join } from 'path';
3+
import { realpathSync } from 'fs';
34
import { homedir, tmpdir } from 'os';
45
import {
56
listWorktrees,
@@ -13,8 +14,9 @@ import {
1314
} from '../../src/lib/worktree';
1415
import type { WorktreeInfo } from '../../src/lib/providers/worktree-provider';
1516

16-
const TEST_REPO_DIR = join(tmpdir(), '.tmp-test-repo');
17-
const TEST_WORKTREE_DIR = join(tmpdir(), '.tmp-test-worktrees');
17+
const TEST_TMP_DIR = realpathSync(tmpdir());
18+
const TEST_REPO_DIR = join(TEST_TMP_DIR, '.tmp-test-repo');
19+
const TEST_WORKTREE_DIR = join(TEST_TMP_DIR, '.tmp-test-worktrees');
1820

1921
async function exec(
2022
args: string[],
@@ -111,7 +113,7 @@ describe('worktree', () => {
111113
describe('createWorktree', () => {
112114
it('should create a worktree for a new branch', async () => {
113115
const fs = await import('fs');
114-
const worktreePath = fs.realpathSync(join(TEST_WORKTREE_DIR, 'test-branch'));
116+
const worktreePath = join(TEST_WORKTREE_DIR, 'test-branch');
115117
const result = await createWorktree({
116118
branch: 'test-branch',
117119
basePath: worktreePath,
@@ -127,8 +129,7 @@ describe('worktree', () => {
127129
TEST_REPO_DIR,
128130
);
129131

130-
const fs = await import('fs');
131-
const worktreePath = fs.realpathSync(join(TEST_WORKTREE_DIR, 'existing-branch'));
132+
const worktreePath = join(TEST_WORKTREE_DIR, 'existing-branch');
132133
const result = await createWorktree({
133134
branch: 'existing-branch',
134135
basePath: worktreePath,
@@ -141,7 +142,7 @@ describe('worktree', () => {
141142
const fs = await import('fs');
142143
fs.writeFileSync(join(TEST_REPO_DIR, '.env.example'), 'KEY=value');
143144

144-
const worktreePath = fs.realpathSync(join(TEST_WORKTREE_DIR, 'hook-copy'));
145+
const worktreePath = join(TEST_WORKTREE_DIR, 'hook-copy');
145146
await createWorktree({
146147
branch: 'hook-copy',
147148
basePath: worktreePath,
@@ -164,7 +165,7 @@ describe('worktree', () => {
164165
fs.mkdirSync(nodeModulesDir, { recursive: true });
165166
fs.writeFileSync(join(nodeModulesDir, 'marker'), 'exists');
166167

167-
const worktreePath = fs.realpathSync(join(TEST_WORKTREE_DIR, 'hook-symlink'));
168+
const worktreePath = join(TEST_WORKTREE_DIR, 'hook-symlink');
168169
await createWorktree({
169170
branch: 'hook-symlink',
170171
basePath: worktreePath,
@@ -179,7 +180,7 @@ describe('worktree', () => {
179180

180181
it('should run postCreate commands', async () => {
181182
const fs = await import('fs');
182-
const worktreePath = fs.realpathSync(join(TEST_WORKTREE_DIR, 'hook-cmd'));
183+
const worktreePath = join(TEST_WORKTREE_DIR, 'hook-cmd');
183184
await createWorktree({
184185
branch: 'hook-cmd',
185186
basePath: worktreePath,
@@ -194,8 +195,7 @@ describe('worktree', () => {
194195

195196
describe('removeWorktree', () => {
196197
it('should remove a clean worktree', async () => {
197-
const fs = await import('fs');
198-
const worktreePath = fs.realpathSync(join(TEST_WORKTREE_DIR, 'to-remove'));
198+
const worktreePath = join(TEST_WORKTREE_DIR, 'to-remove');
199199
await createWorktree({
200200
branch: 'to-remove',
201201
basePath: worktreePath,
@@ -210,7 +210,7 @@ describe('worktree', () => {
210210

211211
it('should refuse to remove dirty worktree without force', async () => {
212212
const fs = await import('fs');
213-
const worktreePath = fs.realpathSync(join(TEST_WORKTREE_DIR, 'dirty-wt'));
213+
const worktreePath = join(TEST_WORKTREE_DIR, 'dirty-wt');
214214
await createWorktree({
215215
branch: 'dirty-wt',
216216
basePath: worktreePath,
@@ -225,7 +225,7 @@ describe('worktree', () => {
225225

226226
it('should remove dirty worktree with force=true', async () => {
227227
const fs = await import('fs');
228-
const worktreePath = fs.realpathSync(join(TEST_WORKTREE_DIR, 'force-remove'));
228+
const worktreePath = join(TEST_WORKTREE_DIR, 'force-remove');
229229
await createWorktree({
230230
branch: 'force-remove',
231231
basePath: worktreePath,
@@ -243,8 +243,7 @@ describe('worktree', () => {
243243

244244
describe('getWorktreeForBranch', () => {
245245
it('should find worktree by branch name', async () => {
246-
const fs = await import('fs');
247-
const worktreePath = fs.realpathSync(join(TEST_WORKTREE_DIR, 'find-branch'));
246+
const worktreePath = join(TEST_WORKTREE_DIR, 'find-branch');
248247
await createWorktree({
249248
branch: 'find-branch',
250249
basePath: worktreePath,
@@ -298,8 +297,7 @@ describe('worktree', () => {
298297

299298
it('should create and remove worktrees through provider', async () => {
300299
const provider = new GitWorktreeProvider();
301-
const fs = await import('fs');
302-
const worktreePath = fs.realpathSync(join(TEST_WORKTREE_DIR, 'provider-test'));
300+
const worktreePath = join(TEST_WORKTREE_DIR, 'provider-test');
303301

304302
const path = await provider.create({
305303
branch: 'provider-test',

0 commit comments

Comments
 (0)