@react-native/gradle-plugin 0.74.85 → 0.74.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/build.gradle.kts +2 -75
  2. package/package.json +4 -3
  3. package/react-native-gradle-plugin/build.gradle.kts +84 -0
  4. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/TestReactExtension.kt +12 -0
  5. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/BundleHermesCTaskTest.kt +434 -0
  6. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTaskTest.kt +212 -0
  7. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTaskTest.kt +192 -0
  8. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/BuildCodegenCLITaskTest.kt +27 -0
  9. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PrepareBoostTaskTest.kt +105 -0
  10. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PrepareGlogTaskTest.kt +130 -0
  11. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PrepareJSCTaskTest.kt +128 -0
  12. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PreparePrefabHeadersTaskTest.kt +201 -0
  13. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/utils/PrefabPreprocessingEntryTest.kt +25 -0
  14. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tests/OsRule.kt +52 -0
  15. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tests/TaskTestUtils.kt +69 -0
  16. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tests/WithOs.kt +17 -0
  17. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/AgpConfiguratorUtilsTest.kt +65 -0
  18. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/BackwardCompatUtilsTest.kt +43 -0
  19. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/DependencyUtilsTest.kt +404 -0
  20. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/FileUtilsTest.kt +45 -0
  21. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/JsonUtilsTest.kt +126 -0
  22. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/KotlinStdlibCompatUtilsTest.kt +82 -0
  23. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/NdkConfiguratorUtilsTest.kt +46 -0
  24. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/OsTest.kt +86 -0
  25. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/PathUtilsTest.kt +325 -0
  26. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/ProjectUtilsTest.kt +533 -0
  27. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/TaskUtilsTest.kt +77 -0
  28. package/settings-plugin/build.gradle.kts +50 -0
  29. package/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsPlugin.kt +24 -0
  30. package/settings.gradle.kts +6 -1
  31. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/ReactExtension.kt +0 -0
  32. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/ReactPlugin.kt +0 -0
  33. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/ReactRootProjectPlugin.kt +0 -0
  34. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/TaskConfiguration.kt +0 -0
  35. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt +0 -0
  36. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/model/ModelCodegenConfig.kt +0 -0
  37. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/model/ModelCodegenConfigAndroid.kt +0 -0
  38. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/model/ModelPackageJson.kt +0 -0
  39. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt +0 -0
  40. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt +0 -0
  41. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTask.kt +0 -0
  42. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/BuildCodegenCLITask.kt +0 -0
  43. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareBoostTask.kt +0 -0
  44. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareGlogTask.kt +0 -0
  45. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareJSCTask.kt +0 -0
  46. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PreparePrefabHeadersTask.kt +0 -0
  47. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/utils/PrefabPreprocessingEntry.kt +0 -0
  48. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +0 -0
  49. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt +0 -0
  50. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +0 -0
  51. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/FileUtils.kt +0 -0
  52. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt +0 -0
  53. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/JsonUtils.kt +0 -0
  54. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/KotlinStdlibCompatUtils.kt +0 -0
  55. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt +0 -0
  56. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/Os.kt +0 -0
  57. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/PathUtils.kt +0 -0
  58. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/ProjectUtils.kt +0 -0
  59. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/PropertyUtils.kt +0 -0
  60. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/TaskUtils.kt +0 -0
@@ -0,0 +1,212 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and 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.tasks
9
+
10
+ import com.facebook.react.tests.*
11
+ import com.facebook.react.tests.createProject
12
+ import com.facebook.react.tests.createTestTask
13
+ import java.io.File
14
+ import org.junit.Assert.assertEquals
15
+ import org.junit.Assert.assertTrue
16
+ import org.junit.Rule
17
+ import org.junit.Test
18
+ import org.junit.rules.TemporaryFolder
19
+
20
+ class GenerateCodegenArtifactsTaskTest {
21
+
22
+ @get:Rule val tempFolder = TemporaryFolder()
23
+
24
+ @get:Rule val osRule = OsRule()
25
+
26
+ @Test
27
+ fun generateCodegenSchema_inputFiles_areSetCorrectly() {
28
+ val outputDir = tempFolder.newFolder("output")
29
+
30
+ val task = createTestTask<GenerateCodegenArtifactsTask> { it.generatedSrcDir.set(outputDir) }
31
+
32
+ assertEquals(File(outputDir, "schema.json"), task.generatedSchemaFile.get().asFile)
33
+ }
34
+
35
+ @Test
36
+ fun generateCodegenSchema_outputFile_isSetCorrectly() {
37
+ val outputDir = tempFolder.newFolder("output")
38
+
39
+ val task = createTestTask<GenerateCodegenArtifactsTask> { it.generatedSrcDir.set(outputDir) }
40
+
41
+ assertEquals(File(outputDir, "java"), task.generatedJavaFiles.get().asFile)
42
+ assertEquals(File(outputDir, "jni"), task.generatedJniFiles.get().asFile)
43
+ }
44
+
45
+ @Test
46
+ fun generateCodegenSchema_simpleProperties_areInsideInput() {
47
+ val packageJsonFile = tempFolder.newFile("package.json")
48
+
49
+ val task =
50
+ createTestTask<GenerateCodegenArtifactsTask> {
51
+ it.nodeExecutableAndArgs.set(listOf("npm", "help"))
52
+ it.codegenJavaPackageName.set("com.example.test")
53
+ it.libraryName.set("example-test")
54
+ it.packageJsonFile.set(packageJsonFile)
55
+ }
56
+
57
+ assertEquals(listOf("npm", "help"), task.nodeExecutableAndArgs.get())
58
+ assertEquals("com.example.test", task.codegenJavaPackageName.get())
59
+ assertEquals("example-test", task.libraryName.get())
60
+ assertTrue(task.inputs.properties.containsKey("nodeExecutableAndArgs"))
61
+ assertTrue(task.inputs.properties.containsKey("codegenJavaPackageName"))
62
+ assertTrue(task.inputs.properties.containsKey("libraryName"))
63
+ }
64
+
65
+ @Test
66
+ @WithOs(OS.LINUX)
67
+ fun setupCommandLine_willSetupCorrectly() {
68
+ val reactNativeDir = tempFolder.newFolder("node_modules/react-native/")
69
+ val outputDir = tempFolder.newFolder("output")
70
+
71
+ val task =
72
+ createTestTask<GenerateCodegenArtifactsTask> {
73
+ it.reactNativeDir.set(reactNativeDir)
74
+ it.generatedSrcDir.set(outputDir)
75
+ it.nodeExecutableAndArgs.set(listOf("--verbose"))
76
+ }
77
+
78
+ task.setupCommandLine("example-test", "com.example.test")
79
+
80
+ assertEquals(
81
+ listOf(
82
+ "--verbose",
83
+ File(reactNativeDir, "scripts/generate-specs-cli.js").toString(),
84
+ "--platform",
85
+ "android",
86
+ "--schemaPath",
87
+ File(outputDir, "schema.json").toString(),
88
+ "--outputDir",
89
+ outputDir.toString(),
90
+ "--libraryName",
91
+ "example-test",
92
+ "--javaPackageName",
93
+ "com.example.test",
94
+ ),
95
+ task.commandLine.toMutableList())
96
+ }
97
+
98
+ @Test
99
+ @WithOs(OS.WIN)
100
+ fun setupCommandLine_onWindows_willSetupCorrectly() {
101
+ val reactNativeDir = tempFolder.newFolder("node_modules/react-native/")
102
+ val outputDir = tempFolder.newFolder("output")
103
+
104
+ val project = createProject()
105
+ val task =
106
+ createTestTask<GenerateCodegenArtifactsTask>(project) {
107
+ it.reactNativeDir.set(reactNativeDir)
108
+ it.generatedSrcDir.set(outputDir)
109
+ it.nodeExecutableAndArgs.set(listOf("--verbose"))
110
+ }
111
+
112
+ task.setupCommandLine("example-test", "com.example.test")
113
+
114
+ assertEquals(
115
+ listOf(
116
+ "cmd",
117
+ "/c",
118
+ "--verbose",
119
+ File(reactNativeDir, "scripts/generate-specs-cli.js")
120
+ .relativeTo(project.projectDir)
121
+ .path,
122
+ "--platform",
123
+ "android",
124
+ "--schemaPath",
125
+ File(outputDir, "schema.json").relativeTo(project.projectDir).path,
126
+ "--outputDir",
127
+ outputDir.relativeTo(project.projectDir).path,
128
+ "--libraryName",
129
+ "example-test",
130
+ "--javaPackageName",
131
+ "com.example.test",
132
+ ),
133
+ task.commandLine.toMutableList())
134
+ }
135
+
136
+ @Test
137
+ fun resolveTaskParameters_withConfigInPackageJson_usesIt() {
138
+ val packageJsonFile =
139
+ tempFolder.newFile("package.json").apply {
140
+ // language=JSON
141
+ writeText(
142
+ """
143
+ {
144
+ "name": "@a/library",
145
+ "codegenConfig": {
146
+ "name": "an-awesome-library",
147
+ "android": {
148
+ "javaPackageName": "com.awesome.package"
149
+ }
150
+ }
151
+ }
152
+ """
153
+ .trimIndent())
154
+ }
155
+
156
+ val task =
157
+ createTestTask<GenerateCodegenArtifactsTask> {
158
+ it.packageJsonFile.set(packageJsonFile)
159
+ it.codegenJavaPackageName.set("com.example.ignored")
160
+ it.libraryName.set("a-library-name-that-is-ignored")
161
+ }
162
+
163
+ val (libraryName, javaPackageName) = task.resolveTaskParameters()
164
+
165
+ assertEquals("an-awesome-library", libraryName)
166
+ assertEquals("com.awesome.package", javaPackageName)
167
+ }
168
+
169
+ @Test
170
+ fun resolveTaskParameters_withConfigMissingInPackageJson_usesGradleOne() {
171
+ val packageJsonFile =
172
+ tempFolder.newFile("package.json").apply {
173
+ // language=JSON
174
+ writeText(
175
+ """
176
+ {
177
+ "name": "@a/library",
178
+ "codegenConfig": {
179
+ }
180
+ }
181
+ """
182
+ .trimIndent())
183
+ }
184
+
185
+ val task =
186
+ createTestTask<GenerateCodegenArtifactsTask> {
187
+ it.packageJsonFile.set(packageJsonFile)
188
+ it.codegenJavaPackageName.set("com.example.test")
189
+ it.libraryName.set("a-library-name-from-gradle")
190
+ }
191
+
192
+ val (libraryName, javaPackageName) = task.resolveTaskParameters()
193
+
194
+ assertEquals("a-library-name-from-gradle", libraryName)
195
+ assertEquals("com.example.test", javaPackageName)
196
+ }
197
+
198
+ @Test
199
+ fun resolveTaskParameters_withMissingPackageJson_usesGradleOne() {
200
+ val task =
201
+ createTestTask<GenerateCodegenArtifactsTask> {
202
+ it.packageJsonFile.set(File(tempFolder.root, "package.json"))
203
+ it.codegenJavaPackageName.set("com.example.test")
204
+ it.libraryName.set("a-library-name-from-gradle")
205
+ }
206
+
207
+ val (libraryName, javaPackageName) = task.resolveTaskParameters()
208
+
209
+ assertEquals("a-library-name-from-gradle", libraryName)
210
+ assertEquals("com.example.test", javaPackageName)
211
+ }
212
+ }
@@ -0,0 +1,192 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and 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.tasks
9
+
10
+ import com.facebook.react.tests.*
11
+ import com.facebook.react.tests.createProject
12
+ import com.facebook.react.tests.createTestTask
13
+ import java.io.File
14
+ import org.junit.Assert.*
15
+ import org.junit.Rule
16
+ import org.junit.Test
17
+ import org.junit.rules.TemporaryFolder
18
+
19
+ class GenerateCodegenSchemaTaskTest {
20
+
21
+ @get:Rule val tempFolder = TemporaryFolder()
22
+
23
+ @get:Rule val osRule = OsRule()
24
+
25
+ @Test
26
+ fun generateCodegenSchema_inputFiles_areSetCorrectly() {
27
+ val jsRootDir =
28
+ tempFolder.newFolder("js").apply {
29
+ File(this, "file.js").createNewFile()
30
+ File(this, "file.ts").createNewFile()
31
+ File(this, "ignore.txt").createNewFile()
32
+ }
33
+
34
+ val task = createTestTask<GenerateCodegenSchemaTask> { it.jsRootDir.set(jsRootDir) }
35
+
36
+ assertEquals(jsRootDir, task.jsInputFiles.dir)
37
+ assertEquals(setOf("**/*.js", "**/*.ts"), task.jsInputFiles.includes)
38
+ assertEquals(2, task.jsInputFiles.files.size)
39
+ assertEquals(
40
+ setOf(File(jsRootDir, "file.js"), File(jsRootDir, "file.ts")), task.jsInputFiles.files)
41
+ }
42
+
43
+ @Test
44
+ fun generateCodegenSchema_inputFilesInExcludedPath_areExcluded() {
45
+ fun File.createFileAndPath() {
46
+ parentFile.mkdirs()
47
+ createNewFile()
48
+ }
49
+
50
+ val jsRootDir =
51
+ tempFolder.newFolder("js").apply {
52
+ File(this, "afolder/includedfile.js").createFileAndPath()
53
+ // Those files should be excluded due to their filepath
54
+ File(this, "afolder/build/generated/source/codegen/anotherfolder/excludedfile.js")
55
+ .createFileAndPath()
56
+ File(this, "afolder/build/generated/assets/react/anotherfolder/excludedfile.js")
57
+ .createFileAndPath()
58
+ File(this, "afolder/build/generated/res/react/anotherfolder/excludedfile.js")
59
+ .createFileAndPath()
60
+ File(this, "afolder/build/generated/sourcemaps/react/anotherfolder/excludedfile.js")
61
+ .createFileAndPath()
62
+ File(this, "afolder/build/intermediates/sourcemaps/react/anotherfolder/excludedfile.js")
63
+ .createFileAndPath()
64
+ }
65
+
66
+ val task = createTestTask<GenerateCodegenSchemaTask> { it.jsRootDir.set(jsRootDir) }
67
+
68
+ assertEquals(jsRootDir, task.jsInputFiles.dir)
69
+ assertEquals(
70
+ setOf(
71
+ "**/build/**/*",
72
+ ),
73
+ task.jsInputFiles.excludes)
74
+ assertEquals(1, task.jsInputFiles.files.size)
75
+ assertEquals(setOf(File(jsRootDir, "afolder/includedfile.js")), task.jsInputFiles.files)
76
+ }
77
+
78
+ @Test
79
+ fun generateCodegenSchema_outputFile_isSetCorrectly() {
80
+ val outputDir = tempFolder.newFolder("output")
81
+
82
+ val task = createTestTask<GenerateCodegenSchemaTask> { it.generatedSrcDir.set(outputDir) }
83
+
84
+ assertEquals(File(outputDir, "schema.json"), task.generatedSchemaFile.get().asFile)
85
+ }
86
+
87
+ @Test
88
+ fun generateCodegenSchema_nodeExecutablesArgs_areInsideInput() {
89
+ val task =
90
+ createTestTask<GenerateCodegenSchemaTask> {
91
+ it.nodeExecutableAndArgs.set(listOf("npm", "help"))
92
+ }
93
+
94
+ assertEquals(listOf("npm", "help"), task.nodeExecutableAndArgs.get())
95
+ assertTrue(task.inputs.properties.containsKey("nodeExecutableAndArgs"))
96
+ }
97
+
98
+ @Test
99
+ fun wipeOutputDir_willCreateOutputDir() {
100
+ val task =
101
+ createTestTask<GenerateCodegenSchemaTask> {
102
+ it.generatedSrcDir.set(File(tempFolder.root, "output"))
103
+ }
104
+
105
+ task.wipeOutputDir()
106
+
107
+ assertTrue(File(tempFolder.root, "output").exists())
108
+ assertEquals(0, File(tempFolder.root, "output").listFiles()?.size)
109
+ }
110
+
111
+ @Test
112
+ fun wipeOutputDir_willWipeOutputDir() {
113
+ val outputDir =
114
+ tempFolder.newFolder("output").apply { File(this, "some-generated-file").createNewFile() }
115
+
116
+ val task = createTestTask<GenerateCodegenSchemaTask> { it.generatedSrcDir.set(outputDir) }
117
+
118
+ task.wipeOutputDir()
119
+
120
+ assertTrue(outputDir.exists())
121
+ assertEquals(0, outputDir.listFiles()?.size)
122
+ }
123
+
124
+ @Test
125
+ @WithOs(OS.LINUX)
126
+ fun setupCommandLine_willSetupCorrectly() {
127
+ val codegenDir = tempFolder.newFolder("codegen")
128
+ val jsRootDir = tempFolder.newFolder("js")
129
+ val outputDir = tempFolder.newFolder("output")
130
+
131
+ val task =
132
+ createTestTask<GenerateCodegenSchemaTask> {
133
+ it.codegenDir.set(codegenDir)
134
+ it.jsRootDir.set(jsRootDir)
135
+ it.generatedSrcDir.set(outputDir)
136
+ it.nodeExecutableAndArgs.set(listOf("node", "--verbose"))
137
+ }
138
+
139
+ task.setupCommandLine()
140
+
141
+ assertEquals(
142
+ listOf(
143
+ "node",
144
+ "--verbose",
145
+ File(codegenDir, "lib/cli/combine/combine-js-to-schema-cli.js").toString(),
146
+ "--platform",
147
+ "android",
148
+ "--exclude",
149
+ "NativeSampleTurboModule",
150
+ File(outputDir, "schema.json").toString(),
151
+ jsRootDir.toString(),
152
+ ),
153
+ task.commandLine.toMutableList())
154
+ }
155
+
156
+ @Test
157
+ @WithOs(OS.WIN)
158
+ fun setupCommandLine_onWindows_willSetupCorrectly() {
159
+ val codegenDir = tempFolder.newFolder("codegen")
160
+ val jsRootDir = tempFolder.newFolder("js")
161
+ val outputDir = tempFolder.newFolder("output")
162
+
163
+ val project = createProject()
164
+ val task =
165
+ createTestTask<GenerateCodegenSchemaTask>(project) {
166
+ it.codegenDir.set(codegenDir)
167
+ it.jsRootDir.set(jsRootDir)
168
+ it.generatedSrcDir.set(outputDir)
169
+ it.nodeExecutableAndArgs.set(listOf("node", "--verbose"))
170
+ }
171
+
172
+ task.setupCommandLine()
173
+
174
+ assertEquals(
175
+ listOf(
176
+ "cmd",
177
+ "/c",
178
+ "node",
179
+ "--verbose",
180
+ File(codegenDir, "lib/cli/combine/combine-js-to-schema-cli.js")
181
+ .relativeTo(project.projectDir)
182
+ .path,
183
+ "--platform",
184
+ "android",
185
+ "--exclude",
186
+ "NativeSampleTurboModule",
187
+ File(outputDir, "schema.json").relativeTo(project.projectDir).path,
188
+ jsRootDir.relativeTo(project.projectDir).path,
189
+ ),
190
+ task.commandLine.toMutableList())
191
+ }
192
+ }
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and 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.tasks.internal
9
+
10
+ import com.facebook.react.tests.createTestTask
11
+ import org.junit.Assert.assertEquals
12
+ import org.junit.Rule
13
+ import org.junit.Test
14
+ import org.junit.rules.TemporaryFolder
15
+
16
+ class BuildCodegenCLITaskTest {
17
+
18
+ @get:Rule val tempFolder = TemporaryFolder()
19
+
20
+ @Test
21
+ fun buildCodegenCli_bashWindowsHome_isSetCorrectly() {
22
+ val bashPath = tempFolder.newFile("bash").absolutePath
23
+ val task = createTestTask<BuildCodegenCLITask> { it.bashWindowsHome.set(bashPath) }
24
+
25
+ assertEquals(bashPath, task.bashWindowsHome.get())
26
+ }
27
+ }
@@ -0,0 +1,105 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and 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.tasks.internal
9
+
10
+ import com.facebook.react.tests.createProject
11
+ import com.facebook.react.tests.createTestTask
12
+ import java.io.*
13
+ import org.junit.Assert.*
14
+ import org.junit.Rule
15
+ import org.junit.Test
16
+ import org.junit.rules.TemporaryFolder
17
+
18
+ class PrepareBoostTaskTest {
19
+
20
+ @get:Rule val tempFolder = TemporaryFolder()
21
+
22
+ @Test(expected = IllegalStateException::class)
23
+ fun prepareBoostTask_withMissingConfiguration_fails() {
24
+ val task = createTestTask<PrepareBoostTask>()
25
+
26
+ task.taskAction()
27
+ }
28
+
29
+ @Test
30
+ fun prepareBoostTask_copiesCMakefile() {
31
+ val boostpath = tempFolder.newFolder("boostpath")
32
+ val output = tempFolder.newFolder("output")
33
+ val project = createProject()
34
+ val task =
35
+ createTestTask<PrepareBoostTask>(project = project) {
36
+ it.boostPath.setFrom(boostpath)
37
+ it.boostVersion.set("1.0.0")
38
+ it.outputDir.set(output)
39
+ }
40
+ File(project.projectDir, "src/main/jni/third-party/boost/CMakeLists.txt").apply {
41
+ parentFile.mkdirs()
42
+ createNewFile()
43
+ }
44
+ task.taskAction()
45
+
46
+ assertTrue(output.listFiles()!!.any { it.name == "CMakeLists.txt" })
47
+ }
48
+
49
+ @Test
50
+ fun prepareBoostTask_copiesAsmFiles() {
51
+ val boostpath = tempFolder.newFolder("boostpath")
52
+ val output = tempFolder.newFolder("output")
53
+ val task =
54
+ createTestTask<PrepareBoostTask>() {
55
+ it.boostPath.setFrom(boostpath)
56
+ it.boostVersion.set("1.0.0")
57
+ it.outputDir.set(output)
58
+ }
59
+ File(boostpath, "asm/asm.S").apply {
60
+ parentFile.mkdirs()
61
+ createNewFile()
62
+ }
63
+ task.taskAction()
64
+
65
+ assertTrue(File(output, "asm/asm.S").exists())
66
+ }
67
+
68
+ @Test
69
+ fun prepareBoostTask_copiesBoostSourceFiles() {
70
+ val boostpath = tempFolder.newFolder("boostpath")
71
+ val output = tempFolder.newFolder("output")
72
+ val task =
73
+ createTestTask<PrepareBoostTask> {
74
+ it.boostPath.setFrom(boostpath)
75
+ it.boostVersion.set("1.0.0")
76
+ it.outputDir.set(output)
77
+ }
78
+ File(boostpath, "boost_1.0.0/boost/config.hpp").apply {
79
+ parentFile.mkdirs()
80
+ createNewFile()
81
+ }
82
+ task.taskAction()
83
+
84
+ assertTrue(File(output, "boost_1.0.0/boost/config.hpp").exists())
85
+ }
86
+
87
+ @Test
88
+ fun prepareBoostTask_copiesVersionlessBoostSourceFiles() {
89
+ val boostpath = tempFolder.newFolder("boostpath")
90
+ val output = tempFolder.newFolder("output")
91
+ val task =
92
+ createTestTask<PrepareBoostTask> {
93
+ it.boostPath.setFrom(boostpath)
94
+ it.boostVersion.set("1.0.0")
95
+ it.outputDir.set(output)
96
+ }
97
+ File(boostpath, "boost/boost/config.hpp").apply {
98
+ parentFile.mkdirs()
99
+ createNewFile()
100
+ }
101
+ task.taskAction()
102
+
103
+ assertTrue(File(output, "boost_1.0.0/boost/config.hpp").exists())
104
+ }
105
+ }
@@ -0,0 +1,130 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and 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.tasks.internal
9
+
10
+ import com.facebook.react.tests.createProject
11
+ import com.facebook.react.tests.createTestTask
12
+ import java.io.*
13
+ import org.junit.Assert.*
14
+ import org.junit.Rule
15
+ import org.junit.Test
16
+ import org.junit.rules.TemporaryFolder
17
+
18
+ class PrepareGlogTaskTest {
19
+
20
+ @get:Rule val tempFolder = TemporaryFolder()
21
+
22
+ @Test(expected = IllegalStateException::class)
23
+ fun prepareGlogTask_withMissingConfiguration_fails() {
24
+ val task = createTestTask<PrepareGlogTask>()
25
+
26
+ task.taskAction()
27
+ }
28
+
29
+ @Test
30
+ fun prepareGlogTask_copiesCMakefile() {
31
+ val glogpath = tempFolder.newFolder("glogpath")
32
+ val output = tempFolder.newFolder("output")
33
+ val project = createProject()
34
+ val task =
35
+ createTestTask<PrepareGlogTask>(project = project) {
36
+ it.glogPath.setFrom(glogpath)
37
+ it.glogVersion.set("1.0.0")
38
+ it.outputDir.set(output)
39
+ }
40
+ File(project.projectDir, "src/main/jni/third-party/glog/CMakeLists.txt").apply {
41
+ parentFile.mkdirs()
42
+ createNewFile()
43
+ }
44
+ task.taskAction()
45
+
46
+ assertTrue(output.listFiles()!!.any { it.name == "CMakeLists.txt" })
47
+ }
48
+
49
+ @Test
50
+ fun prepareGlogTask_copiesConfigHeaderFile() {
51
+ val glogpath = tempFolder.newFolder("glogpath")
52
+ val output = tempFolder.newFolder("output")
53
+ val project = createProject()
54
+ val task =
55
+ createTestTask<PrepareGlogTask>(project = project) {
56
+ it.glogPath.setFrom(glogpath)
57
+ it.glogVersion.set("1.0.0")
58
+ it.outputDir.set(output)
59
+ }
60
+ File(project.projectDir, "src/main/jni/third-party/glog/config.h").apply {
61
+ parentFile.mkdirs()
62
+ createNewFile()
63
+ }
64
+ task.taskAction()
65
+
66
+ assertTrue(output.listFiles()!!.any { it.name == "config.h" })
67
+ }
68
+
69
+ @Test
70
+ fun prepareGlogTask_copiesSourceCode() {
71
+ val glogpath = tempFolder.newFolder("glogpath")
72
+ val output = tempFolder.newFolder("output")
73
+ val task =
74
+ createTestTask<PrepareGlogTask> {
75
+ it.glogPath.setFrom(glogpath)
76
+ it.glogVersion.set("1.0.0")
77
+ it.outputDir.set(output)
78
+ }
79
+ File(glogpath, "glog-1.0.0/src/glog.cpp").apply {
80
+ parentFile.mkdirs()
81
+ createNewFile()
82
+ }
83
+
84
+ task.taskAction()
85
+
86
+ assertTrue(File(output, "glog-1.0.0/src/glog.cpp").exists())
87
+ }
88
+
89
+ @Test
90
+ fun prepareGlogTask_replacesTokenCorrectly() {
91
+ val glogpath = tempFolder.newFolder("glogpath")
92
+ val output = tempFolder.newFolder("output")
93
+ val task =
94
+ createTestTask<PrepareGlogTask> {
95
+ it.glogPath.setFrom(glogpath)
96
+ it.glogVersion.set("1.0.0")
97
+ it.outputDir.set(output)
98
+ }
99
+ File(glogpath, "glog-1.0.0/src/glog.h.in").apply {
100
+ parentFile.mkdirs()
101
+ writeText("ac_google_start_namespace")
102
+ }
103
+
104
+ task.taskAction()
105
+
106
+ val expectedFile = File(output, "glog.h")
107
+ assertTrue(expectedFile.exists())
108
+ assertEquals("ac_google_start_namespace", expectedFile.readText())
109
+ }
110
+
111
+ @Test
112
+ fun prepareGlogTask_exportsHeaderCorrectly() {
113
+ val glogpath = tempFolder.newFolder("glogpath")
114
+ val output = tempFolder.newFolder("output")
115
+ val task =
116
+ createTestTask<PrepareGlogTask> {
117
+ it.glogPath.setFrom(glogpath)
118
+ it.glogVersion.set("1.0.0")
119
+ it.outputDir.set(output)
120
+ }
121
+ File(glogpath, "glog-1.0.0/src/logging.h.in").apply {
122
+ parentFile.mkdirs()
123
+ writeText("ac_google_start_namespace")
124
+ }
125
+
126
+ task.taskAction()
127
+
128
+ assertTrue(File(output, "exported/glog/logging.h").exists())
129
+ }
130
+ }