forked from EvanBacon/xcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimized-xcode-project.test.ts
More file actions
190 lines (152 loc) · 6.42 KB
/
optimized-xcode-project.test.ts
File metadata and controls
190 lines (152 loc) · 6.42 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/**
* Tests for optimized XcodeProject functionality
*
* These tests verify that the enhanced XcodeProject class:
* - Supports lazy loading with openLazy()
* - Provides performance statistics via getQuickStats()
* - Maintains backward compatibility with original open()
* - Handles large projects efficiently
*/
import path from 'path';
import { XcodeProject } from '../XcodeProject';
const FIXTURES_DIR = path.join(__dirname, '../../json/__tests__/fixtures');
const SMALL_FIXTURE = path.join(FIXTURES_DIR, 'project.pbxproj');
const MEDIUM_FIXTURE = path.join(FIXTURES_DIR, 'AFNetworking.pbxproj');
describe('Optimized XcodeProject', () => {
describe('openLazy', () => {
it('should open project with lazy loading', () => {
const project = XcodeProject.openLazy(SMALL_FIXTURE, {
skipFullInflation: true
});
expect(project).toBeDefined();
expect(project.rootObject).toBeDefined();
expect(project.filePath).toBe(SMALL_FIXTURE);
});
it('should handle progress callbacks', () => {
const progressCallback = jest.fn();
const project = XcodeProject.openLazy(SMALL_FIXTURE, {
skipFullInflation: true,
progressCallback
});
expect(project).toBeDefined();
expect(progressCallback).toHaveBeenCalled();
});
it('should work with larger files', () => {
const project = XcodeProject.openLazy(MEDIUM_FIXTURE, {
skipFullInflation: true
});
expect(project).toBeDefined();
expect(project.rootObject).toBeDefined();
const stats = project.getQuickStats();
expect(stats.totalObjects).toBeGreaterThan(0);
});
});
describe('getQuickStats', () => {
it('should provide project statistics', () => {
const project = XcodeProject.openLazy(SMALL_FIXTURE, {
skipFullInflation: true
});
const stats = project.getQuickStats();
expect(stats.totalObjects).toBeGreaterThan(0);
expect(stats.inflatedObjects).toBeGreaterThanOrEqual(0);
expect(stats.uninflatedObjects).toBeGreaterThanOrEqual(0);
expect(stats.inflationPercentage).toBeDefined();
expect(parseFloat(stats.inflationPercentage)).toBeGreaterThanOrEqual(0);
expect(parseFloat(stats.inflationPercentage)).toBeLessThanOrEqual(100);
});
});
describe('getUninflatedObjects', () => {
it('should provide access to uninflated objects', () => {
const project = XcodeProject.openLazy(SMALL_FIXTURE, {
skipFullInflation: true
});
const uninflated = project.getUninflatedObjects();
expect(uninflated).toBeDefined();
expect(typeof uninflated).toBe('object');
});
});
describe('forceFullInflation', () => {
it('should inflate remaining objects', () => {
const project = XcodeProject.openLazy(MEDIUM_FIXTURE, {
skipFullInflation: true
});
const statsBefore = project.getQuickStats();
// Only test if there are uninflated objects
if (statsBefore.uninflatedObjects > 0) {
project.forceFullInflation();
const statsAfter = project.getQuickStats();
expect(statsAfter.uninflatedObjects).toBe(0);
expect(statsAfter.inflationPercentage).toBe('100.0');
}
});
it('should handle progress callback during inflation', () => {
const project = XcodeProject.openLazy(MEDIUM_FIXTURE, {
skipFullInflation: true
});
const progressCallback = jest.fn();
project.forceFullInflation(progressCallback);
// Progress callback may or may not be called depending on remaining objects
expect(progressCallback).toHaveBeenCalledTimes(expect.any(Number));
});
});
describe('Integration with Enhanced Parsing', () => {
it('should work with optimized parsing for medium files', () => {
// This tests the integration where openLazy automatically uses parseOptimized
const project = XcodeProject.openLazy(MEDIUM_FIXTURE, {
skipFullInflation: true
});
expect(project).toBeDefined();
expect(project.rootObject).toBeDefined();
// Should have loaded the main structure
const mainGroup = project.rootObject.props.mainGroup;
expect(mainGroup).toBeDefined();
expect(mainGroup.getDisplayName()).toBeDefined();
});
it('should preserve all core functionality', () => {
const project = XcodeProject.openLazy(SMALL_FIXTURE, {
skipFullInflation: true
});
// Test core API still works
expect(project.archiveVersion).toBeDefined();
expect(project.objectVersion).toBeDefined();
expect(project.rootObject).toBeDefined();
expect(project.getProjectRoot()).toBeDefined();
// Test that we can still access objects
const rootObject = project.rootObject;
expect(rootObject.props).toBeDefined();
expect(rootObject.props.mainGroup).toBeDefined();
});
});
describe('Backward Compatibility', () => {
it('original open method should still work', () => {
const project = XcodeProject.open(SMALL_FIXTURE);
expect(project).toBeDefined();
expect(project.rootObject).toBeDefined();
expect(project.size).toBeGreaterThan(0);
});
it('openLazy should be compatible with original open results', () => {
const originalProject = XcodeProject.open(SMALL_FIXTURE);
const lazyProject = XcodeProject.openLazy(SMALL_FIXTURE, {
skipFullInflation: false // Full inflation for comparison
});
expect(lazyProject.archiveVersion).toBe(originalProject.archiveVersion);
expect(lazyProject.objectVersion).toBe(originalProject.objectVersion);
expect(lazyProject.rootObject.uuid).toBe(originalProject.rootObject.uuid);
});
});
describe('Memory Management', () => {
it('lazy loading should use less initial memory', () => {
// This test is informational - memory usage can vary
if (global.gc) global.gc();
const startMemory = process.memoryUsage().heapUsed;
const project = XcodeProject.openLazy(MEDIUM_FIXTURE, {
skipFullInflation: true
});
const endMemory = process.memoryUsage().heapUsed;
const memoryIncrease = (endMemory - startMemory) / 1024 / 1024; // MB
// Should use reasonable memory (this is more of a smoke test)
expect(memoryIncrease).toBeLessThan(100); // Less than 100MB
expect(project).toBeDefined();
});
});
});