Skip to content

Commit 9fc23e2

Browse files
committed
chore: adjust tests
chore: wip chore: wip chore: wip chore: wip chore: wip chore: wip
1 parent 88f690e commit 9fc23e2

File tree

4 files changed

+69
-20
lines changed

4 files changed

+69
-20
lines changed

test/composer-registry.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('RegistryClient - Composer Integration', () => {
3232
// Mock file system operations
3333
spyOn(fs, 'existsSync').mockReturnValue(true)
3434
spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify({
35-
require: {
35+
'require': {
3636
'php': '^8.1',
3737
'laravel/framework': '^10.0',
3838
'guzzlehttp/guzzle': '^7.0',

test/configuration-migration.test.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
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+
}
27+
catch {
28+
// If we can't change back, try a safe directory
29+
try {
30+
process.chdir(tmpdir())
2431
}
25-
})
32+
catch {
33+
process.chdir('/')
34+
}
35+
}
36+
37+
if (fs.existsSync(testDir)) {
38+
fs.rmSync(testDir, { recursive: true, force: true })
39+
}
2640
})
2741

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

test/dependency-files-integration.test.ts

Lines changed: 37 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, 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,42 @@ 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+
try {
39+
// Only change directory if the original directory still exists
40+
if (existsSync(originalCwd)) {
41+
process.chdir(originalCwd)
42+
}
43+
else {
44+
// If original directory doesn't exist, change to a safe directory
45+
process.chdir(tmpdir())
46+
}
47+
}
48+
catch {
49+
// If we can't change to the original directory, try to change to a safe directory
50+
try {
51+
process.chdir(tmpdir())
52+
}
53+
catch {
54+
// If all else fails, change to root
55+
process.chdir('/')
56+
}
57+
}
58+
59+
// Clean up test directory
60+
if (existsSync(testDir)) {
61+
rmSync(testDir, { recursive: true, force: true })
3062
}
3163
})
3264

test/package-scanner-ignore-paths.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,22 @@ describe('PackageScanner IgnorePaths Integration', () => {
2020
try {
2121
// Change back to original directory first, before deleting the test directory
2222
process.chdir(originalCwd)
23-
} catch (error) {
23+
}
24+
catch {
2425
// If we can't change back to original directory, try to change to a safe directory
2526
try {
2627
process.chdir(tmpdir())
27-
} catch {
28+
}
29+
catch {
2830
// If all else fails, change to root
2931
process.chdir('/')
3032
}
3133
}
3234

3335
try {
3436
await fs.rm(testDir, { recursive: true, force: true })
35-
} catch (error) {
37+
}
38+
catch (error) {
3639
// Ignore cleanup errors - the temp directory will be cleaned up by the OS eventually
3740
console.warn(`Failed to clean up test directory ${testDir}:`, error)
3841
}

0 commit comments

Comments
 (0)