@@ -4,8 +4,8 @@ import org.jetbrains.compose.test.utils.GradlePluginTestBase
44import org.jetbrains.compose.test.utils.TestProject
55import org.jetbrains.compose.test.utils.checkExists
66import org.jetbrains.compose.test.utils.checks
7- import org.jetbrains.compose.test.utils.modify
87import org.junit.jupiter.api.Test
8+ import kotlin.test.Ignore
99import kotlin.test.assertEquals
1010import kotlin.test.assertTrue
1111
@@ -33,6 +33,11 @@ class WebCompatibilityDistributionTest : GradlePluginTestBase() {
3333 }
3434 }
3535
36+ private fun TestProject.replaceBuildConfig (caseName : String ) {
37+ file(" build.gradle.kts" ).delete()
38+ file(" build.gradle.kts.${caseName} " ).renameTo(file(" build.gradle.kts" ))
39+ }
40+
3641 @Test
3742 fun checkWebCompatibilityDistribution () {
3843 with (testProject(" application/webApp" )) {
@@ -59,17 +64,7 @@ class WebCompatibilityDistributionTest : GradlePluginTestBase() {
5964 @Test
6065 fun testWebJsOnly () {
6166 with (testProject(" application/webApp" )) {
62- file(" build.gradle.kts" ).modify {
63- // delete wasm target
64- it.replace("""
65- | wasmJs {
66- | browser { }
67- | binaries.executable()
68- | }
69- """ .trimMargin(), " " )
70- .replace(" wasmJsMain { dependsOn(webMain) }" , " " )
71- }
72-
67+ replaceBuildConfig(" WebJsOnly" )
7368 gradle(" :composeCompatibilityBrowserDistribution" ).checks {
7469 check.taskSkipped(" :composeCompatibilityBrowserDistribution" )
7570 check.taskSuccessful(" :jsBrowserDistribution" )
@@ -81,17 +76,7 @@ class WebCompatibilityDistributionTest : GradlePluginTestBase() {
8176 @Test
8277 fun testWebWasmOnly () {
8378 with (testProject(" application/webApp" )) {
84- file(" build.gradle.kts" ).modify {
85- // delete js target
86- it.replace("""
87- | js {
88- | browser { }
89- | binaries.executable()
90- | }
91- """ .trimMargin(), " " )
92- .replace(" jsMain { dependsOn(webMain) }" , " " )
93- }
94-
79+ replaceBuildConfig(" WebWasmOnly" )
9580 gradle(" :composeCompatibilityBrowserDistribution" ).checks {
9681 check.taskSkipped(" :composeCompatibilityBrowserDistribution" )
9782 check.taskSuccessful(" :wasmJsBrowserDistribution" )
@@ -103,10 +88,7 @@ class WebCompatibilityDistributionTest : GradlePluginTestBase() {
10388 @Test
10489 fun testWebJsNonExecutable () {
10590 with (testProject(" application/webApp" )) {
106- file(" build.gradle.kts" ).modify {
107- it.replace(" binaries.executable()" , " " )
108- }
109-
91+ replaceBuildConfig(" WebJsNonExecutable" )
11092 gradle(" :composeCompatibilityBrowserDistribution" ).checks {
11193 check.taskSkipped(" :composeCompatibilityBrowserDistribution" )
11294 check.logContains(" no js and wasm distributions found, both are required for compatibility" )
@@ -117,10 +99,7 @@ class WebCompatibilityDistributionTest : GradlePluginTestBase() {
11799 @Test
118100 fun testWebSingleExecutable () {
119101 with (testProject(" application/webApp" )) {
120- file(" build.gradle.kts" ).modify {
121- it.replaceFirst(" binaries.executable()" , " " )
122- }
123-
102+ replaceBuildConfig(" WebSingleExecutable" )
124103 gradle(" :composeCompatibilityBrowserDistribution" ).checks {
125104 check.taskSkipped(" :composeCompatibilityBrowserDistribution" )
126105 check.logContains(" no js and wasm distributions found, both are required for compatibility" )
@@ -131,13 +110,7 @@ class WebCompatibilityDistributionTest : GradlePluginTestBase() {
131110 @Test
132111 fun testWebJsWasmNonStandardTargetNames () {
133112 with (testProject(" application/webApp" )) {
134- file(" build.gradle.kts" ).modify {
135- it
136- .replace(" js {" , " js(\" webJs\" ) {" )
137- .replace(" wasmJs {" , " wasmJs(\" webWasm\" ) {" )
138- .replace(" jsMain {" , " val webJsMain by getting {" )
139- .replace(" wasmJsMain {" , " val webWasmMain by getting {" )
140- }
113+ replaceBuildConfig(" WebJsWasmNonStandardTargetNames" )
141114 file(" src/jsMain" ).renameTo(file(" src/webJsMain" ))
142115 file(" src/wasmJsMain" ).renameTo(file(" src/webWasmMain" ))
143116
@@ -161,100 +134,35 @@ class WebCompatibilityDistributionTest : GradlePluginTestBase() {
161134 }
162135 }
163136
164- // @Test
165- // fun testWebJsWasmNonStandardBundleNames() {
166- // with(testProject("application/webApp")) {
167- // file("build.gradle.kts").modify {
168- // it
169- // .replace(
170- // """
171- // | js {
172- // | browser { }
173- // | binaries.executable()
174- // | }
175- // """.trimMargin(),
176- // """
177- // | js {
178- // | browser {
179- // | commonWebpackConfig { outputFileName = "myJsApp.js" }
180- // | }
181- // | binaries.executable()
182- // | }
183- // """.trimMargin(),
184- // )
185- // }
186- //
187- // gradle(":composeCompatibilityBrowserDistribution").checks {
188- // check.taskSuccessful(":composeCompatibilityBrowserDistribution")
189- // check.taskSuccessful(":jsBrowserDistribution")
190- // check.taskSuccessful(":wasmJsBrowserDistribution")
191- // }
192- // assertCompatibilityDistribution(
193- // expectedFileNames = setOf(
194- // "composeApp.js",
195- // "composeResources",
196- // "index.html",
197- // "myJsApp.js",
198- // "myJsApp.js.map",
199- // "originWasmComposeApp.js",
200- // "originWasmComposeApp.js.map",
201- // "styles.css"
202- // )
203- // )
204- // }
205- // }
206-
207137 @Test
208- fun testWebJsWasmRepacked () {
138+ @Ignore(" WebPack outputFileName doesn't reflect a real name of the bundle." )
139+ fun testWebJsWasmNonStandardBundleNames () {
209140 with (testProject(" application/webApp" )) {
210- file(" build.gradle.kts" ).modify {
211- it + """
212- val wasmRepack = tasks.register<RepackTask>("wasmRepack") {
213- sourceFiles.from(project.tasks.named("wasmJsBrowserDistribution").map { it.outputs.files })
214- outputDir.set(project.layout.buildDirectory.dir("dist/repackedWasm"))
215- }
216-
217- val jsRepack = tasks.register<RepackTask>("jsRepack") {
218- sourceFiles.from(project.tasks.named("jsBrowserDistribution").map { it.outputs.files })
219- outputDir.set(project.layout.buildDirectory.dir("dist/repackedJs"))
220- }
221-
222- project.tasks.withType<org.jetbrains.compose.web.tasks.WebCompatibilityTask>().configureEach {
223- jsOutputName.set("repackedApp.js")
224- wasmOutputName.set("repackedApp.js")
225- jsDistFiles.setFrom(jsRepack)
226- wasmDistFiles.setFrom(wasmRepack)
227- }
228-
229- abstract class RepackTask : DefaultTask() {
230- @get:Inject
231- internal abstract val fileOperations: FileSystemOperations
232-
233- @get:InputFiles
234- abstract val sourceFiles: ConfigurableFileCollection
235-
236- @get:OutputDirectory
237- abstract val outputDir: DirectoryProperty
238-
239- @TaskAction
240- fun run() {
241- fileOperations.copy {
242- from(sourceFiles) {
243- this.rename { name ->
244- when (name) {
245- "composeApp.js" -> "repackedApp.js"
246- "composeApp.js.map" -> "repackedApp.js.map"
247- else -> name
248- }
249- }
250- }
251- into(outputDir)
252- }
253- }
254- }
255- """ .trimIndent()
141+ replaceBuildConfig(" WebJsWasmNonStandardBundleNames" )
142+ gradle(" :composeCompatibilityBrowserDistribution" ).checks {
143+ check.taskSuccessful(" :composeCompatibilityBrowserDistribution" )
144+ check.taskSuccessful(" :jsBrowserDistribution" )
145+ check.taskSuccessful(" :wasmJsBrowserDistribution" )
256146 }
147+ assertCompatibilityDistribution(
148+ expectedFileNames = setOf (
149+ " myApp.js" ,
150+ " composeResources" ,
151+ " index.html" ,
152+ " originJsMyApp.js" ,
153+ " originJsMyApp.js.map" ,
154+ " originWasmMyApp.js" ,
155+ " originWasmMyApp.js.map" ,
156+ " styles.css"
157+ )
158+ )
159+ }
160+ }
257161
162+ @Test
163+ fun testWebJsWasmRepacked () {
164+ with (testProject(" application/webApp" )) {
165+ replaceBuildConfig(" WebJsWasmRepacked" )
258166 gradle(" :composeCompatibilityBrowserDistribution" ).checks {
259167 check.taskSuccessful(" :composeCompatibilityBrowserDistribution" )
260168 check.taskSuccessful(" :jsBrowserDistribution" )
@@ -276,4 +184,29 @@ class WebCompatibilityDistributionTest : GradlePluginTestBase() {
276184 )
277185 }
278186 }
187+
188+ // https://youtrack.jetbrains.com/issue/CMP-8760
189+ @Test
190+ fun checkWebAppWithKmmBridge () {
191+ with (testProject(" application/webApp" )) {
192+ replaceBuildConfig(" WebAppWithKmmBridge" )
193+ gradle(" :composeCompatibilityBrowserDistribution" ).checks {
194+ check.taskSuccessful(" :composeCompatibilityBrowserDistribution" )
195+ check.taskSuccessful(" :jsBrowserDistribution" )
196+ check.taskSuccessful(" :wasmJsBrowserDistribution" )
197+ }
198+ assertCompatibilityDistribution(
199+ expectedFileNames = setOf (
200+ " composeApp.js" ,
201+ " composeResources" ,
202+ " index.html" ,
203+ " originJsComposeApp.js" ,
204+ " originJsComposeApp.js.map" ,
205+ " originWasmComposeApp.js" ,
206+ " originWasmComposeApp.js.map" ,
207+ " styles.css"
208+ )
209+ )
210+ }
211+ }
279212}
0 commit comments