Skip to content

Commit a5b8b25

Browse files
committed
Refactor webApp test projects to use predefined build configurations.
1 parent 6df4a96 commit a5b8b25

9 files changed

Lines changed: 311 additions & 128 deletions

gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/WebCompatibilityDistributionTest.kt

Lines changed: 61 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import org.jetbrains.compose.test.utils.GradlePluginTestBase
44
import org.jetbrains.compose.test.utils.TestProject
55
import org.jetbrains.compose.test.utils.checkExists
66
import org.jetbrains.compose.test.utils.checks
7-
import org.jetbrains.compose.test.utils.modify
87
import org.junit.jupiter.api.Test
8+
import kotlin.test.Ignore
99
import kotlin.test.assertEquals
1010
import 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
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
plugins {
2+
id("org.jetbrains.kotlin.multiplatform")
3+
id("org.jetbrains.kotlin.plugin.compose")
4+
id("org.jetbrains.compose")
5+
id("co.touchlab.kmmbridge").version("0.5.7")
6+
}
7+
8+
kotlin {
9+
js {
10+
browser { }
11+
binaries.executable()
12+
}
13+
14+
wasmJs {
15+
browser { }
16+
binaries.executable()
17+
}
18+
19+
sourceSets {
20+
commonMain.dependencies {
21+
implementation(compose.runtime)
22+
}
23+
24+
val webMain by creating { dependsOn(commonMain.get()) }
25+
jsMain { dependsOn(webMain) }
26+
wasmJsMain { dependsOn(webMain) }
27+
}
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
plugins {
2+
id("org.jetbrains.kotlin.multiplatform")
3+
id("org.jetbrains.compose")
4+
id("org.jetbrains.kotlin.plugin.compose")
5+
}
6+
7+
kotlin {
8+
js {
9+
browser {
10+
commonWebpackConfig { outputFileName = "myApp.js" }
11+
}
12+
binaries.executable()
13+
}
14+
15+
wasmJs {
16+
browser {
17+
commonWebpackConfig { outputFileName = "myApp.js" }
18+
}
19+
binaries.executable()
20+
}
21+
22+
sourceSets {
23+
commonMain.dependencies {
24+
implementation(compose.runtime)
25+
}
26+
27+
val webMain by creating { dependsOn(commonMain.get()) }
28+
jsMain { dependsOn(webMain) }
29+
wasmJsMain { dependsOn(webMain) }
30+
}
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
plugins {
2+
id("org.jetbrains.kotlin.multiplatform")
3+
id("org.jetbrains.compose")
4+
id("org.jetbrains.kotlin.plugin.compose")
5+
}
6+
7+
kotlin {
8+
js {
9+
browser { }
10+
}
11+
12+
wasmJs {
13+
browser { }
14+
}
15+
16+
sourceSets {
17+
commonMain.dependencies {
18+
implementation(compose.runtime)
19+
}
20+
21+
val webMain by creating { dependsOn(commonMain.get()) }
22+
jsMain { dependsOn(webMain) }
23+
wasmJsMain { dependsOn(webMain) }
24+
}
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
plugins {
2+
id("org.jetbrains.kotlin.multiplatform")
3+
id("org.jetbrains.compose")
4+
id("org.jetbrains.kotlin.plugin.compose")
5+
}
6+
7+
kotlin {
8+
js {
9+
browser { }
10+
binaries.executable()
11+
}
12+
13+
sourceSets {
14+
commonMain.dependencies {
15+
implementation(compose.runtime)
16+
}
17+
18+
val webMain by creating { dependsOn(commonMain.get()) }
19+
jsMain { dependsOn(webMain) }
20+
}
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
plugins {
2+
id("org.jetbrains.kotlin.multiplatform")
3+
id("org.jetbrains.compose")
4+
id("org.jetbrains.kotlin.plugin.compose")
5+
}
6+
7+
kotlin {
8+
js("webJs") {
9+
browser { }
10+
binaries.executable()
11+
}
12+
13+
wasmJs("webWasm") {
14+
browser { }
15+
binaries.executable()
16+
}
17+
18+
sourceSets {
19+
commonMain.dependencies {
20+
implementation(compose.runtime)
21+
}
22+
23+
val webMain by creating { dependsOn(commonMain.get()) }
24+
val webJsMain by getting { dependsOn(webMain) }
25+
val webWasmMain by getting { dependsOn(webMain) }
26+
}
27+
}

0 commit comments

Comments
 (0)