-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.func.test.js
84 lines (74 loc) · 2.4 KB
/
index.func.test.js
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
let RNHotPatching = require('./index');
// default mocks
jest.mock('react-native', () => ({
Platform: {
OS: 'android'
}
}));
jest.mock('react-native-dynamic-bundle', () => ({
getActiveBundle: () => '1.0.0',
getBundles: () => ({}),
registerBundle: () => {},
setActiveBundle: () => {}
}));
jest.mock('react-native-fs', () => ({
downloadFile: () => ({
promise: () => {}
}),
exists: () => true,
mkdir: () => {}
}));
jest.mock('react-native-zip-archive', () => ({
unzip: () => {}
}));
describe('React Native Hot Patching: Functional', () => {
beforeEach(() => {
jest.resetModules();
});
describe('getCurrentAppVersion()', () => {
it('should return bundle version if it is greater than package.json version using semver compare not JS string compare', async () => {
jest.mock('react-native-dynamic-bundle', () => ({
getActiveBundle: () => '1.0.10'
}));
RNHotPatching = require('./index');
const result = await RNHotPatching.getCurrentAppVersion('1.0.9');
expect(result).toEqual('1.0.10');
});
});
describe('removeStaleBundles()', () => {
it('should remove stale bundles if bundle version is less than package.json version using semver compare not JS string compare', async () => {
const mockRNDBUnregisterBundle = jest.fn();
jest.mock('react-native-dynamic-bundle', () => ({
getBundles: () => ({
'1.0.9': 'PATH_TO_REMOVE'
}),
unregisterBundle: mockRNDBUnregisterBundle
}));
jest.mock('react-native-fs', () => ({
exists: jest.fn(() => true),
unlink: jest.fn(),
DocumentDirectoryPath: 'ANY_PATH'
}));
RNHotPatching = require('./index');
await RNHotPatching.removeStaleBundles('1.0.10');
expect(mockRNDBUnregisterBundle).toHaveBeenCalledWith('1.0.9');
});
it('should not remove stale bundles if bundle version is greater or equal than package.json version using semver compare not JS string compare', async () => {
const mockRNDBUnregisterBundle = jest.fn();
jest.mock('react-native-dynamic-bundle', () => ({
getBundles: () => ({
'1.0.10': 'PATH_TO_REMOVE'
}),
unregisterBundle: mockRNDBUnregisterBundle
}));
jest.mock('react-native-fs', () => ({
exists: jest.fn(() => true),
unlink: jest.fn(),
DocumentDirectoryPath: 'ANY_PATH'
}));
RNHotPatching = require('./index');
await RNHotPatching.removeStaleBundles('1.0.9');
expect(mockRNDBUnregisterBundle).not.toHaveBeenCalledWith();
});
});
});