-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathconfig.test.ts
More file actions
105 lines (87 loc) · 3.05 KB
/
Copy pathconfig.test.ts
File metadata and controls
105 lines (87 loc) · 3.05 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
103
104
105
import { fileURLToPath } from 'node:url';
import fs from 'node:fs';
import path from 'node:path';
import { afterEach, describe, expect, it, vi } from 'vitest';
import {
isBrownieInstalled,
loadConfig,
getBrowniePackagePath,
getSwiftOutputPath,
} 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('returns empty config when brownie config missing', () => {
tempDir = createTempPackageJson({});
mockCwd.mockReturnValue(tempDir);
const config = loadConfig();
expect(config).toEqual({});
});
it('loads empty config', () => {
tempDir = createTempPackageJson({
brownie: {},
});
mockCwd.mockReturnValue(tempDir);
const config = loadConfig();
expect(config).toEqual({});
});
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');
});
});
describe('isBrownieInstalled', () => {
it('returns false when brownie is not installed', () => {
expect(isBrownieInstalled('/nonexistent/path')).toBe(false);
});
it('returns true when brownie is installed', () => {
const rnAppPath = path.resolve(__dirname, '../../../../../apps/RNApp');
expect(isBrownieInstalled(rnAppPath)).toBe(true);
});
});
describe('getBrowniePackagePath', () => {
it('resolves brownie package path from project with brownie dependency', () => {
const rnAppPath = path.resolve(__dirname, '../../../../../apps/RNApp');
const browniePath = getBrowniePackagePath(rnAppPath);
expect(browniePath).toContain('brownie');
expect(fs.existsSync(path.join(browniePath, 'package.json'))).toBe(true);
});
});
describe('getSwiftOutputPath', () => {
it('returns path to ios/Generated inside brownie package', () => {
const rnAppPath = path.resolve(__dirname, '../../../../../apps/RNApp');
const outputPath = getSwiftOutputPath(rnAppPath);
expect(outputPath).toContain('brownie');
expect(outputPath).toContain(path.join('ios', 'Generated'));
});
});