-
Notifications
You must be signed in to change notification settings - Fork 907
/
Copy pathpods.test.ts
149 lines (120 loc) · 3.45 KB
/
pods.test.ts
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
import path from 'path';
import {writeFiles, getTempDirectory, cleanup} from '../../../../jest/helpers';
import installPods from '../tools/installPods';
import resolvePods, {
compareMd5Hashes,
getPlatformDependencies,
} from '../tools/pods';
const mockGet = jest.fn();
const mockSet = jest.fn();
jest.mock('@react-native-community/cli-tools', () => ({
...Object.assign(jest.requireActual('@react-native-community/cli-tools')),
cacheManager: {
get: mockGet,
set: mockSet,
},
}));
jest.mock('../tools/installPods', () => jest.fn());
const dependencyHash = 'd41d8cd98f00b204e9800998ecf8427e';
const packageJson = {
name: 'test-package',
dependencies: {dep1: '1.0.0'},
devDependencies: {dep2: '1.0.0'},
};
const commonDepConfig = {
root: '',
platforms: {
ios: {
podspecPath: '',
version: '1.0.0',
scriptPhases: [],
configurations: [],
},
},
};
const dependenciesConfig = {
dep1: {
name: 'dep1',
...commonDepConfig,
},
dep2: {
name: 'dep2',
...commonDepConfig,
},
};
const DIR = getTempDirectory('root_test');
const createTempFiles = (rest?: Record<string, string>) => {
writeFiles(DIR, {
'package.json': JSON.stringify(packageJson),
'ios/Podfile': '',
...rest,
});
};
beforeEach(async () => {
cleanup(DIR);
jest.resetAllMocks();
});
describe('compareMd5Hashes', () => {
it('should return false if hashes are different', () => {
const result = compareMd5Hashes('hash1', 'hash2');
expect(result).toBe(false);
});
it('should return true if hashes are the same', () => {
const result = compareMd5Hashes('hash', 'hash');
expect(result).toBe(true);
});
});
describe('getPlatformDependencies', () => {
it('should return only dependencies with native code', () => {
const result = getPlatformDependencies(dependenciesConfig, 'ios');
});
});
describe('resolvePods', () => {
it('should install pods if they are not installed', async () => {
createTempFiles();
await resolvePods(DIR, path.join(DIR, 'ios'), {}, 'ios');
expect(installPods).toHaveBeenCalled();
});
it('should install pods when force option is set to true', async () => {
createTempFiles();
await resolvePods(DIR, path.join(DIR, 'ios'), {}, 'ios', {
forceInstall: true,
});
expect(installPods).toHaveBeenCalled();
});
it('should install pods when there is no cached hash of dependencies', async () => {
createTempFiles();
await resolvePods(DIR, path.join(DIR, 'ios'), {}, 'ios');
expect(mockSet).toHaveBeenCalledWith(
packageJson.name,
'dependencies',
dependencyHash,
);
});
it('should skip pods installation if the cached hash and current hash are the same', async () => {
createTempFiles({
'ios/Pods/Manifest.lock': '',
'ios/Podfile.lock': `PODFILE CHECKSUM: ${dependencyHash}`,
});
mockGet.mockImplementation(() => dependencyHash);
await resolvePods(DIR, path.join(DIR, 'ios'), {}, 'ios');
expect(installPods).not.toHaveBeenCalled();
});
it('should install pods if the cached hash and current hash are different', async () => {
createTempFiles();
mockGet.mockImplementation(() => dependencyHash);
await resolvePods(
DIR,
path.join(DIR, 'ios'),
{
dep1: {
name: 'dep1',
...commonDepConfig,
},
},
'ios',
);
expect(installPods).toHaveBeenCalled();
});
});