-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathutils.spec.ts
153 lines (143 loc) · 4.13 KB
/
utils.spec.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
150
151
152
153
import { PACKAGE_NAMES } from '../constants'
import '../releases/__mocks__/index'
import {
getVersionsContentInDiff,
removeAppPathPrefix,
replaceAppDetails,
getChangelogURL,
} from '../utils'
describe('getVersionsContentInDiff', () => {
it('returns the versions in the provided range', () => {
const versions = getVersionsContentInDiff({
packageName: PACKAGE_NAMES.RN,
fromVersion: '0.57.0',
toVersion: '0.59.0',
})
expect(versions).toEqual([{ version: '0.59' }, { version: '0.58' }])
})
it('returns the versions in the provided range with release candidates', () => {
const versions = getVersionsContentInDiff({
packageName: PACKAGE_NAMES.RN,
fromVersion: '0.56.0',
toVersion: '0.59.0-rc.1',
})
expect(versions).toEqual([
{ version: '0.59' },
{ version: '0.58' },
{ version: '0.57' },
])
})
it('returns the versions in the provided range with patches specified', () => {
const versions = getVersionsContentInDiff({
packageName: PACKAGE_NAMES.RN,
fromVersion: '0.57.2',
toVersion: '0.59.9',
})
expect(versions).toEqual([{ version: '0.59' }, { version: '0.58' }])
})
})
describe('getChangelogURL', () => {
const { RN, RNM, RNW } = PACKAGE_NAMES
test.each([
[
RN,
'0.71.7',
'https://github.com/facebook/react-native/blob/main/CHANGELOG.md#v0717',
],
[
RN,
'0.71.6',
'https://github.com/facebook/react-native/blob/main/CHANGELOG.md#v0716',
],
[
RNM,
'0.71.5',
'https://github.com/microsoft/react-native-macos/releases/tag/v0.71.5',
],
[
RNW,
'0.71.4',
'https://github.com/microsoft/react-native-windows/releases/tag/react-native-windows_v0.71.4',
],
])('getChangelogURL("%s", "%s") -> %s', (packageName, version, url) => {
expect(getChangelogURL({ packageName, version })).toEqual(url)
})
})
describe('replaceAppDetails ', () => {
test.each([
// Don't change anything if no app name or package is passed.
[
'RnDiffApp/ios/RnDiffApp/main.m',
'',
'',
'RnDiffApp/ios/RnDiffApp/main.m',
],
[
'android/app/src/debug/java/com/rndiffapp/ReactNativeFlipper.java',
'',
'',
'android/app/src/debug/java/com/rndiffapp/ReactNativeFlipper.java',
],
[
'location = "group:RnDiffApp.xcodeproj">',
'',
'',
'location = "group:RnDiffApp.xcodeproj">',
],
// Update Java file path with correct app name and package.
[
'android/app/src/debug/java/com/rndiffapp/ReactNativeFlipper.java',
'SuperApp',
'au.org.mycorp',
'android/app/src/debug/java/au/org/mycorp/ReactNativeFlipper.java',
],
// Update the app details in file contents.
[
'location = "group:RnDiffApp.xcodeproj">',
'MyFancyApp',
'',
'location = "group:MyFancyApp.xcodeproj">',
],
[
'applicationId "com.rndiffapp"',
'ACoolApp',
'net.foobar',
'applicationId "net.foobar"',
],
// Don't accidentally pick up other instances of "com" such as in domain
// names, or android or facebook packages.
[
'apply plugin: "com.android.application"',
'ACoolApp',
'net.foobar',
'apply plugin: "com.android.application"',
],
[
'* https://github.com/facebook/react-native',
'ACoolApp',
'net.foobar',
'* https://github.com/facebook/react-native',
],
])(
'replaceAppDetails("%s", "%s", "%s") -> %s',
(path, appName, appPackage, newPath) => {
expect(replaceAppDetails(path, appName, appPackage)).toEqual(newPath)
}
)
})
describe('removeAppPathPrefix', () => {
test.each([
['RnDiffApp/package.json', 'package.json'],
['RnDiffApp/RnDiffApp.ts', 'RnDiffApp.ts'],
])('removeAppPathPrefix("%s") -> "%s"', (path, newPath) => {
expect(removeAppPathPrefix(path)).toEqual(newPath)
})
test('removeAppPathPrefix custom AppName', () => {
expect(removeAppPathPrefix('RnDiffApp/package.json', '')).toEqual(
'RnDiffApp/package.json'
)
expect(removeAppPathPrefix('Foobar/package.json', 'Foobar')).toEqual(
'package.json'
)
})
})