Skip to content

Commit 95725fa

Browse files
committed
chore: wip
1 parent 4537b7d commit 95725fa

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

test/configuration-migration.test.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
11
import type { MigrationResult } from '../src/setup'
22
import { afterEach, beforeEach, describe, expect, it, spyOn } from 'bun:test'
33
import fs from 'node:fs'
4+
import { tmpdir } from 'node:os'
5+
import { join } from 'node:path'
46
import { ConfigurationMigrator } from '../src/setup'
57

68
describe('Configuration Migration & Import System', () => {
79
let migrator: ConfigurationMigrator
10+
let testDir: string
11+
let originalCwd: string
812

913
beforeEach(() => {
14+
// Create a temporary directory for each test
15+
testDir = fs.mkdtempSync(join(tmpdir(), 'buddy-config-test-'))
16+
originalCwd = process.cwd()
17+
process.chdir(testDir)
18+
1019
migrator = new ConfigurationMigrator()
1120
})
1221

1322
afterEach(() => {
14-
// Clean up test files - DO NOT DELETE the real package.json!
15-
const testFiles = ['renovate.json', '.renovaterc', 'test-package.json', '.github/dependabot.yml']
16-
testFiles.forEach((file) => {
17-
if (fs.existsSync(file)) {
18-
try {
19-
fs.unlinkSync(file)
20-
}
21-
catch {
22-
// Ignore cleanup errors
23-
}
23+
// Change back to original directory and clean up
24+
try {
25+
process.chdir(originalCwd)
26+
} catch {
27+
// If we can't change back, try a safe directory
28+
try {
29+
process.chdir(tmpdir())
30+
} catch {
31+
process.chdir('/')
2432
}
25-
})
33+
}
34+
35+
if (fs.existsSync(testDir)) {
36+
fs.rmSync(testDir, { recursive: true, force: true })
37+
}
2638
})
2739

2840
describe('Tool Detection', () => {

test/dependency-files-integration.test.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { BuddyBotConfig, PackageUpdate } from '../src/types'
22
import { afterAll, beforeAll, describe, expect, it } from 'bun:test'
3-
import { existsSync, unlinkSync, writeFileSync } from 'node:fs'
3+
import { existsSync, mkdtempSync, rmSync, unlinkSync, writeFileSync } from 'node:fs'
4+
import { tmpdir } from 'node:os'
5+
import { join } from 'node:path'
46
import { Buddy } from '../src/buddy'
57
import { isDependencyFile, parseDependencyFile, updateDependencyFile } from '../src/utils/dependency-file-parser'
68

@@ -10,7 +12,9 @@ describe('Dependency Files Integration Tests', () => {
1012
packages: { strategy: 'all' },
1113
}
1214

13-
const testDepsFile = 'test-deps.yaml'
15+
let testDir: string
16+
let testDepsFile: string
17+
let originalCwd: string
1418
const testDepsContent = `dependencies:
1519
lodash: ^4.17.20
1620
react: ^17.0.0
@@ -19,14 +23,21 @@ devDependencies:
1923
typescript: ^4.9.0`
2024

2125
beforeAll(() => {
26+
// Create a temporary directory for test files
27+
testDir = mkdtempSync(join(tmpdir(), 'buddy-deps-test-'))
28+
originalCwd = process.cwd()
29+
process.chdir(testDir)
30+
31+
testDepsFile = 'test-deps.yaml'
2232
// Create a test dependency file
2333
writeFileSync(testDepsFile, testDepsContent)
2434
})
2535

2636
afterAll(() => {
27-
// Clean up test files
28-
if (existsSync(testDepsFile)) {
29-
unlinkSync(testDepsFile)
37+
// Change back to original directory and clean up
38+
process.chdir(originalCwd)
39+
if (existsSync(testDir)) {
40+
rmSync(testDir, { recursive: true, force: true })
3041
}
3142
})
3243

0 commit comments

Comments
 (0)