@@ -18,14 +18,14 @@ class JsonUtilsTest {
18
18
@get:Rule val tempFolder = TemporaryFolder ()
19
19
20
20
@Test
21
- fun withInvalidJson_returnsNull () {
21
+ fun fromPackageJson_withInvalidJson_returnsNull () {
22
22
val invalidJson = createJsonFile(""" ¯\_(ツ)_/¯""" )
23
23
24
24
assertNull(JsonUtils .fromPackageJson(invalidJson))
25
25
}
26
26
27
27
@Test
28
- fun withEmptyJson_returnsEmptyObject () {
28
+ fun fromPackageJson_withEmptyJson_returnsEmptyObject () {
29
29
val invalidJson = createJsonFile(""" {}""" )
30
30
31
31
val parsed = JsonUtils .fromPackageJson(invalidJson)
@@ -35,7 +35,7 @@ class JsonUtilsTest {
35
35
}
36
36
37
37
@Test
38
- fun withOldJsonConfig_returnsAnEmptyLibrary () {
38
+ fun fromPackageJson_withOldJsonConfig_returnsAnEmptyLibrary () {
39
39
val oldJsonConfig =
40
40
createJsonFile(
41
41
"""
@@ -62,7 +62,7 @@ class JsonUtilsTest {
62
62
}
63
63
64
64
@Test
65
- fun withValidJson_parsesCorrectly () {
65
+ fun fromPackageJson_withValidJson_parsesCorrectly () {
66
66
val validJson =
67
67
createJsonFile(
68
68
"""
@@ -121,6 +121,185 @@ class JsonUtilsTest {
121
121
assertEquals(" 1000.0.0" , parsed.version)
122
122
}
123
123
124
+ @Test
125
+ fun fromAutolinkingConfigJson_withInvalidJson_returnsNull () {
126
+ val invalidJson = createJsonFile(""" ¯\_(ツ)_/¯""" )
127
+
128
+ assertNull(JsonUtils .fromAutolinkingConfigJson(invalidJson))
129
+ }
130
+
131
+ @Test
132
+ fun fromAutolinkingConfigJson_withSimpleJson_returnsIt () {
133
+ val validJson =
134
+ createJsonFile(
135
+ """
136
+ {
137
+ "reactNativeVersion": "1000.0.0"
138
+ }
139
+ """
140
+ .trimIndent())
141
+ val parsed = JsonUtils .fromAutolinkingConfigJson(validJson)!!
142
+
143
+ assertEquals(" 1000.0.0" , parsed.reactNativeVersion)
144
+ }
145
+
146
+ @Test
147
+ fun fromAutolinkingConfigJson_withProjectSpecified_canParseIt () {
148
+ val validJson =
149
+ createJsonFile(
150
+ """
151
+ {
152
+ "reactNativeVersion": "1000.0.0",
153
+ "project": {
154
+ "ios": {
155
+ "sourceDir": "./packages/rn-tester",
156
+ "xcodeProject": {
157
+ "name": "RNTesterPods.xcworkspace",
158
+ "isWorkspace": true
159
+ },
160
+ "automaticPodsInstallation": false
161
+ },
162
+ "android": {
163
+ "sourceDir": "./packages/rn-tester",
164
+ "appName": "RN-Tester",
165
+ "packageName": "com.facebook.react.uiapp",
166
+ "applicationId": "com.facebook.react.uiapp",
167
+ "mainActivity": ".RNTesterActivity",
168
+ "watchModeCommandParams": [
169
+ "--mode HermesDebug"
170
+ ],
171
+ "dependencyConfiguration": "implementation"
172
+ }
173
+ }
174
+ }
175
+ """
176
+ .trimIndent())
177
+ val parsed = JsonUtils .fromAutolinkingConfigJson(validJson)!!
178
+
179
+ assertEquals(" ./packages/rn-tester" , parsed.project!! .android!! .sourceDir)
180
+ assertEquals(" RN-Tester" , parsed.project!! .android!! .appName)
181
+ assertEquals(" com.facebook.react.uiapp" , parsed.project!! .android!! .packageName)
182
+ assertEquals(" com.facebook.react.uiapp" , parsed.project!! .android!! .applicationId)
183
+ assertEquals(" .RNTesterActivity" , parsed.project!! .android!! .mainActivity)
184
+ assertEquals(" --mode HermesDebug" , parsed.project!! .android!! .watchModeCommandParams!! [0 ])
185
+ assertEquals(" implementation" , parsed.project!! .android!! .dependencyConfiguration)
186
+ }
187
+
188
+ @Test
189
+ fun fromAutolinkingConfigJson_withDependenciesSpecified_canParseIt () {
190
+ val validJson =
191
+ createJsonFile(
192
+ """
193
+ {
194
+ "reactNativeVersion": "1000.0.0",
195
+ "dependencies": {
196
+ "@react-native/oss-library-example": {
197
+ "root": "./node_modules/@react-native/oss-library-example",
198
+ "name": "@react-native/oss-library-example",
199
+ "platforms": {
200
+ "ios": {
201
+ "podspecPath": "./node_modules/@react-native/oss-library-example/OSSLibraryExample.podspec",
202
+ "version": "0.0.1",
203
+ "configurations": [],
204
+ "scriptPhases": []
205
+ },
206
+ "android": {
207
+ "sourceDir": "./node_modules/@react-native/oss-library-example/android",
208
+ "packageImportPath": "import com.facebook.react.osslibraryexample.OSSLibraryExamplePackage;",
209
+ "packageInstance": "new OSSLibraryExamplePackage()",
210
+ "buildTypes": ["staging", "debug", "release"],
211
+ "libraryName": "OSSLibraryExampleSpec",
212
+ "componentDescriptors": [
213
+ "SampleNativeComponentComponentDescriptor"
214
+ ],
215
+ "cmakeListsPath": "./node_modules/@react-native/oss-library-example/android/build/generated/source/codegen/jni/CMakeLists.txt",
216
+ "cxxModuleCMakeListsModuleName": null,
217
+ "cxxModuleCMakeListsPath": null,
218
+ "cxxModuleHeaderName": null,
219
+ "dependencyConfiguration": "implementation"
220
+ }
221
+ }
222
+ }
223
+ }
224
+ }
225
+ """
226
+ .trimIndent())
227
+ val parsed = JsonUtils .fromAutolinkingConfigJson(validJson)!!
228
+
229
+ assertEquals(
230
+ " ./node_modules/@react-native/oss-library-example" ,
231
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!! .root)
232
+ assertEquals(
233
+ " @react-native/oss-library-example" ,
234
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!! .name)
235
+ assertEquals(
236
+ " react-native_oss-library-example" ,
237
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!! .nameCleansed)
238
+ assertEquals(
239
+ " ./node_modules/@react-native/oss-library-example/android" ,
240
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!!
241
+ .platforms!!
242
+ .android!!
243
+ .sourceDir)
244
+ assertEquals(
245
+ " import com.facebook.react.osslibraryexample.OSSLibraryExamplePackage;" ,
246
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!!
247
+ .platforms!!
248
+ .android!!
249
+ .packageImportPath)
250
+ assertEquals(
251
+ " new OSSLibraryExamplePackage()" ,
252
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!!
253
+ .platforms!!
254
+ .android!!
255
+ .packageInstance)
256
+ assertEquals(
257
+ listOf (" staging" , " debug" , " release" ),
258
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!!
259
+ .platforms!!
260
+ .android!!
261
+ .buildTypes)
262
+ assertEquals(
263
+ " OSSLibraryExampleSpec" ,
264
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!!
265
+ .platforms!!
266
+ .android!!
267
+ .libraryName)
268
+ assertEquals(
269
+ listOf (" SampleNativeComponentComponentDescriptor" ),
270
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!!
271
+ .platforms!!
272
+ .android!!
273
+ .componentDescriptors)
274
+ assertEquals(
275
+ " ./node_modules/@react-native/oss-library-example/android/build/generated/source/codegen/jni/CMakeLists.txt" ,
276
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!!
277
+ .platforms!!
278
+ .android!!
279
+ .cmakeListsPath)
280
+ assertNull(
281
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!!
282
+ .platforms!!
283
+ .android!!
284
+ .cxxModuleHeaderName)
285
+ assertNull(
286
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!!
287
+ .platforms!!
288
+ .android!!
289
+ .cxxModuleCMakeListsPath)
290
+ assertNull(
291
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!!
292
+ .platforms!!
293
+ .android!!
294
+ .cxxModuleCMakeListsModuleName)
295
+ assertEquals(
296
+ " implementation" ,
297
+ parsed.dependencies!! [" @react-native/oss-library-example" ]!!
298
+ .platforms!!
299
+ .android!!
300
+ .dependencyConfiguration)
301
+ }
302
+
124
303
private fun createJsonFile (@Language(" JSON" ) input : String ) =
125
304
tempFolder.newFile().apply { writeText(input) }
126
305
}
0 commit comments