forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnativeVersionUpdaterTest.js
89 lines (82 loc) · 2.19 KB
/
nativeVersionUpdaterTest.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
85
86
87
88
89
const fs = require('fs');
const path = require('path');
const mockFS = require('mock-fs');
const {updateAndroidVersion, generateAndroidVersionCode} = require('../../.github/libs/nativeVersionUpdater');
const BUILD_GRADLE_PATH = path.resolve(__dirname, '../../android/app/build.gradle');
const mockBuildGradle = `
android {
defaultConfig {
versionCode 1000001479
versionName "1.0.1-47"
}
}
`;
beforeAll(() => {
// Override global console to fix bug with mock-fs: https://github.com/tschaub/mock-fs/issues/234
global.console = require('../../__mocks__/console');
// Set up mocked filesystem
mockFS({
[BUILD_GRADLE_PATH]: mockBuildGradle,
});
});
// Restore modules to normal
afterAll(() => {
mockFS.restore();
global.console = require('console');
});
describe('generateAndroidVersionCode', () => {
test.each([
['1.0.1-0', '1001000100'],
['1.0.1-44', '1001000144'],
['10.11.12-35', '1010111235'],
['0.0.1-1', '1000000101'],
['10.99.66-88', '1010996688'],
])('generateAndroidVersionCode(%s) – %s', (input, expected) => {
expect(generateAndroidVersionCode(input)).toBe(expected);
});
});
describe('updateAndroidVersion', () => {
test.each([
[
'1.0.1-47',
'1001000147',
`
android {
defaultConfig {
versionCode 1001000147
versionName "1.0.1-47"
}
}
`,
],
[
'1.0.1-0',
'1001000100',
`
android {
defaultConfig {
versionCode 1001000100
versionName "1.0.1-0"
}
}
`,
],
[
'10.99.66-88',
'1010996688',
`
android {
defaultConfig {
versionCode 1010996688
versionName "10.99.66-88"
}
}
`,
],
])('updateAndroidVersion("%s", "%s")', (versionName, versionCode, expected) =>
updateAndroidVersion(versionName, versionCode).then(() => {
const result = fs.readFileSync(BUILD_GRADLE_PATH, {encoding: 'utf8'}).toString();
expect(result).toBe(expected);
}),
);
});