mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add tests for AndroidConfiguration
Summary: Another small diff to setup some testing for our Gradle Plugin. Specifically this one is also setting up a test environment where we would be able to exercies AGP usages on top of `ProjectBuilder`. This will allow us to verify that an Android project is configured correctly for a React Native build. Changelog: [Internal] [Added] - Add tests for AndroidConfiguration Reviewed By: GijsWeterings Differential Revision: D30839600 fbshipit-source-id: 10e3b3c0fcf5979c2a0eaf64320f87ae58093fbd
This commit is contained in:
committed by
Facebook GitHub Bot
parent
27dd2ecb70
commit
ebcdf511a5
@@ -5,6 +5,9 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import org.gradle.api.internal.classpath.ModuleRegistry
|
||||
import org.gradle.configurationcache.extensions.serviceOf
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "1.4.21"
|
||||
id("java-gradle-plugin")
|
||||
@@ -27,5 +30,12 @@ gradlePlugin {
|
||||
dependencies {
|
||||
implementation(gradleApi())
|
||||
implementation("com.android.tools.build:gradle:4.2.2")
|
||||
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
|
||||
testRuntimeOnly(
|
||||
files(
|
||||
serviceOf<ModuleRegistry>().getModule("gradle-tooling-api-builders").classpath.asFiles.first()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+4
-1
@@ -11,7 +11,8 @@ import com.android.build.gradle.BaseExtension
|
||||
import org.gradle.api.Project
|
||||
|
||||
fun Project.configureDevPorts(androidExt: BaseExtension) {
|
||||
val devServerPort = project.properties["reactNativeDevServerPort"]?.toString() ?: "8081"
|
||||
val devServerPort =
|
||||
project.properties["reactNativeDevServerPort"]?.toString() ?: DEFAULT_DEV_SERVER_PORT
|
||||
val inspectorProxyPort =
|
||||
project.properties["reactNativeInspectorProxyPort"]?.toString() ?: devServerPort
|
||||
|
||||
@@ -20,3 +21,5 @@ fun Project.configureDevPorts(androidExt: BaseExtension) {
|
||||
it.resValue("integer", "react_native_inspector_proxy_port", inspectorProxyPort)
|
||||
}
|
||||
}
|
||||
|
||||
const val DEFAULT_DEV_SERVER_PORT = "8081"
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react
|
||||
|
||||
import com.android.build.gradle.BaseExtension
|
||||
import org.gradle.testfixtures.ProjectBuilder
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class AndroidConfigurationTest {
|
||||
|
||||
@Test
|
||||
fun configureDevPorts_withNoSpecifiedPort_usesDefault() {
|
||||
val project = ProjectBuilder.builder().build()
|
||||
project.pluginManager.apply("com.android.application")
|
||||
val androidExtension = project.extensions.getByType(BaseExtension::class.java)
|
||||
val debug = androidExtension.buildTypes.findByName("debug")
|
||||
val release = androidExtension.buildTypes.findByName("release")
|
||||
|
||||
project.configureDevPorts(androidExtension)
|
||||
|
||||
assertEquals("8081", debug?.resValues?.get("react_native_dev_server_port")?.value)
|
||||
assertEquals("8081", debug?.resValues?.get("react_native_inspector_proxy_port")?.value)
|
||||
assertEquals("8081", release?.resValues?.get("react_native_dev_server_port")?.value)
|
||||
assertEquals("8081", release?.resValues?.get("react_native_inspector_proxy_port")?.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun configureDevPorts_withSpecifiedReactNativeDevServerPort_usesIt() {
|
||||
val project = ProjectBuilder.builder().build()
|
||||
project.pluginManager.apply("com.android.application")
|
||||
val androidExtension = project.extensions.getByType(BaseExtension::class.java)
|
||||
val debug = androidExtension.buildTypes.findByName("debug")
|
||||
val release = androidExtension.buildTypes.findByName("release")
|
||||
|
||||
project.extensions.extraProperties["reactNativeDevServerPort"] = "42424"
|
||||
|
||||
project.configureDevPorts(androidExtension)
|
||||
|
||||
assertEquals("42424", debug?.resValues?.get("react_native_dev_server_port")?.value)
|
||||
assertEquals("42424", debug?.resValues?.get("react_native_inspector_proxy_port")?.value)
|
||||
assertEquals("42424", release?.resValues?.get("react_native_dev_server_port")?.value)
|
||||
assertEquals("42424", release?.resValues?.get("react_native_inspector_proxy_port")?.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun configureDevPorts_withSpecifiedReactNativeInspectorProxyPort_usesIt() {
|
||||
val project = ProjectBuilder.builder().build()
|
||||
project.pluginManager.apply("com.android.application")
|
||||
val androidExtension = project.extensions.getByType(BaseExtension::class.java)
|
||||
val debug = androidExtension.buildTypes.findByName("debug")
|
||||
val release = androidExtension.buildTypes.findByName("release")
|
||||
|
||||
project.extensions.extraProperties["reactNativeInspectorProxyPort"] = "42424"
|
||||
|
||||
project.configureDevPorts(androidExtension)
|
||||
|
||||
assertEquals("8081", debug?.resValues?.get("react_native_dev_server_port")?.value)
|
||||
assertEquals("42424", debug?.resValues?.get("react_native_inspector_proxy_port")?.value)
|
||||
assertEquals("8081", release?.resValues?.get("react_native_dev_server_port")?.value)
|
||||
assertEquals("42424", release?.resValues?.get("react_native_inspector_proxy_port")?.value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user