|
| 1 | +/* |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +package com.facebook.react |
| 9 | + |
| 10 | +import com.android.build.gradle.AppExtension |
| 11 | +import org.gradle.testfixtures.ProjectBuilder |
| 12 | +import org.junit.Assert.assertTrue |
| 13 | +import org.junit.Test |
| 14 | + |
| 15 | +class ReactPluginTest { |
| 16 | + |
| 17 | + @Test |
| 18 | + fun reactPlugin_withApplyAppPluginSetToTrue_addsARelevantTask() { |
| 19 | + val project = ProjectBuilder.builder().build() |
| 20 | + project.plugins.apply("com.android.application") |
| 21 | + project.plugins.apply("com.facebook.react") |
| 22 | + |
| 23 | + project.extensions.getByType(AppExtension::class.java).apply { compileSdkVersion(30) } |
| 24 | + project.extensions.getByType(ReactExtension::class.java).apply { |
| 25 | + applyAppPlugin.set(true) |
| 26 | + cliPath.set(".") |
| 27 | + } |
| 28 | + |
| 29 | + // We check if the App Plugin si applied by finding one of the added task. |
| 30 | + assertTrue(project.getTasksByName("bundleDebugJsAndAssets", false).isNotEmpty()) |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + fun reactPlugin_withApplyAppPluginSetToFalse_doesNotApplyTheAppPlugin() { |
| 35 | + val project = ProjectBuilder.builder().build() |
| 36 | + project.plugins.apply("com.android.application") |
| 37 | + project.plugins.apply("com.facebook.react") |
| 38 | + |
| 39 | + project.extensions.getByType(AppExtension::class.java).apply { compileSdkVersion(30) } |
| 40 | + project.extensions.getByType(ReactExtension::class.java).apply { applyAppPlugin.set(false) } |
| 41 | + |
| 42 | + assertTrue(project.getTasksByName("bundleDebugJsAndAssets", false).isEmpty()) |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + fun reactPlugin_withApplyAppPluginSetToFalse_codegenPluginIsApplied() { |
| 47 | + val project = ProjectBuilder.builder().build() |
| 48 | + project.plugins.apply("com.android.application") |
| 49 | + project.plugins.apply("com.facebook.react") |
| 50 | + |
| 51 | + project.extensions.getByType(AppExtension::class.java).apply { compileSdkVersion(30) } |
| 52 | + project.extensions.getByType(ReactExtension::class.java).apply { applyAppPlugin.set(false) } |
| 53 | + |
| 54 | + assertTrue(project.getTasksByName("buildCodegenCLI", false).isNotEmpty()) |
| 55 | + } |
| 56 | +} |
0 commit comments