-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathconfig.test.ts
More file actions
102 lines (85 loc) · 2.73 KB
/
config.test.ts
File metadata and controls
102 lines (85 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { fileURLToPath } from 'node:url';
import fs from 'node:fs';
import path from 'node:path';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { loadConfig } from '../config.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const FIXTURES_DIR = path.join(__dirname, '../__fixtures__');
const mockCwd = vi.spyOn(process, 'cwd');
function createTempPackageJson(config: object): string {
const tempDir = fs.mkdtempSync(path.join(FIXTURES_DIR, 'temp-'));
const packageJsonPath = path.join(tempDir, 'package.json');
fs.writeFileSync(packageJsonPath, JSON.stringify(config, null, 2));
return tempDir;
}
function cleanupTempDir(dir: string): void {
fs.rmSync(dir, { recursive: true, force: true });
}
describe('loadConfig', () => {
let tempDir: string | null = null;
afterEach(() => {
if (tempDir) {
cleanupTempDir(tempDir);
tempDir = null;
}
mockCwd.mockReset();
});
it('throws when package.json not found', () => {
mockCwd.mockReturnValue('/nonexistent/path');
expect(() => loadConfig()).toThrow('package.json not found');
});
it('throws when brownie config missing', () => {
tempDir = createTempPackageJson({});
mockCwd.mockReturnValue(tempDir);
expect(() => loadConfig()).toThrow(
'brownie config not found in package.json'
);
});
it('throws when no output path configured', () => {
tempDir = createTempPackageJson({
brownie: {},
});
mockCwd.mockReturnValue(tempDir);
expect(() => loadConfig()).toThrow(
'At least one output path is required: brownie.swift or brownie.kotlin'
);
});
it('loads config with swift output', () => {
tempDir = createTempPackageJson({
brownie: {
swift: './Generated',
},
});
mockCwd.mockReturnValue(tempDir);
const config = loadConfig();
expect(config).toEqual({
swift: './Generated',
});
});
it('loads config with kotlin output', () => {
tempDir = createTempPackageJson({
brownie: {
kotlin: './Generated',
kotlinPackageName: 'com.example',
},
});
mockCwd.mockReturnValue(tempDir);
const config = loadConfig();
expect(config.kotlin).toBe('./Generated');
expect(config.kotlinPackageName).toBe('com.example');
});
it('loads config with all outputs', () => {
tempDir = createTempPackageJson({
brownie: {
swift: './swift/Generated',
kotlin: './kotlin/Generated',
kotlinPackageName: 'com.example',
},
});
mockCwd.mockReturnValue(tempDir);
const config = loadConfig();
expect(config.swift).toBe('./swift/Generated');
expect(config.kotlin).toBe('./kotlin/Generated');
expect(config.kotlinPackageName).toBe('com.example');
});
});