11package org.jetbrains.compose.test.tests.integration
22
3- import org.jetbrains.compose.test.utils.ChecksWrapper
43import org.jetbrains.compose.test.utils.GradlePluginTestBase
54import org.jetbrains.compose.test.utils.TestProject
65import org.jetbrains.compose.test.utils.checkExists
76import org.jetbrains.compose.test.utils.checks
87import org.junit.jupiter.api.Test
8+ import kotlin.test.Ignore
99import kotlin.test.assertEquals
1010import kotlin.test.assertTrue
1111
1212class WebCompatibilityDistributionTest : GradlePluginTestBase () {
13- private val defaultDistDir = " ./composeApp/build/dist/composeWebCompatibility/productionExecutable"
1413
1514 private fun TestProject.assertCompatibilityDistribution (
16- dirPath : String ,
15+ dirPath : String = "./build/dist/composeWebCompatibility/productionExecutable" ,
1716 expectedFileNames : Set <String >
1817 ) {
1918 file(dirPath).apply {
@@ -34,107 +33,180 @@ class WebCompatibilityDistributionTest : GradlePluginTestBase() {
3433 }
3534 }
3635
37- private fun runTaskAndCheck (projectPath : String , taskName : String , onExecution : ChecksWrapper .(project: TestProject ) -> Unit ) {
38- with (
39- testProject(
40- projectPath,
41- testEnvironment = defaultTestEnvironment.copy()
42- )
43- ) {
44- gradle(taskName).checks {
45- onExecution(this @with)
36+ private fun TestProject.applyBuildConfig (caseName : String ) {
37+ file(" build.gradle.kts.${caseName} " ).renameTo(file(" build.gradle.kts" ))
38+ }
39+
40+ @Test
41+ fun checkWebCompatibilityDistribution () {
42+ with (testProject(" application/webApp" )) {
43+ applyBuildConfig(" WebApp" )
44+ gradle(" :composeCompatibilityBrowserDistribution" ).checks {
45+ check.taskSuccessful(" :composeCompatibilityBrowserDistribution" )
46+ check.taskSuccessful(" :jsBrowserDistribution" )
47+ check.taskSuccessful(" :wasmJsBrowserDistribution" )
4648 }
49+ assertCompatibilityDistribution(
50+ expectedFileNames = setOf (
51+ " composeApp.js" ,
52+ " composeResources" ,
53+ " index.html" ,
54+ " originJsComposeApp.js" ,
55+ " originJsComposeApp.js.map" ,
56+ " originWasmComposeApp.js" ,
57+ " originWasmComposeApp.js.map" ,
58+ " styles.css"
59+ )
60+ )
4761 }
4862 }
4963
50- private fun assertSuccessfulCompatibilityRun (
51- projectPath : String ,
52- successfulTasks : List <String >,
53- distDir : String = defaultDistDir,
54- expectedFiles : Set <String >
55- ) {
56- runTaskAndCheck(projectPath, " :composeApp:composeCompatibilityBrowserDistribution" ) { testProject ->
57- check.taskSuccessful(" :composeApp:composeCompatibilityBrowserDistribution" )
58- successfulTasks.forEach { check.taskSuccessful(it) }
59- testProject.assertCompatibilityDistribution(dirPath = distDir, expectedFileNames = expectedFiles)
64+ @Test
65+ fun testWebJsOnly () {
66+ with (testProject(" application/webApp" )) {
67+ applyBuildConfig(" WebJsOnly" )
68+ gradle(" :composeCompatibilityBrowserDistribution" ).checks {
69+ check.taskSkipped(" :composeCompatibilityBrowserDistribution" )
70+ check.taskSuccessful(" :jsBrowserDistribution" )
71+ check.logContains(" no js and wasm distributions found, both are required for compatibility" )
72+ }
6073 }
6174 }
6275
63- private fun assertSkippedCompatibilityRun (projectPath : String ) {
64- runTaskAndCheck(projectPath, " :composeApp:composeCompatibilityBrowserDistribution" ) {
65- check.taskSkipped(" :composeApp:composeCompatibilityBrowserDistribution" )
76+ @Test
77+ fun testWebWasmOnly () {
78+ with (testProject(" application/webApp" )) {
79+ applyBuildConfig(" WebWasmOnly" )
80+ gradle(" :composeCompatibilityBrowserDistribution" ).checks {
81+ check.taskSkipped(" :composeCompatibilityBrowserDistribution" )
82+ check.taskSuccessful(" :wasmJsBrowserDistribution" )
83+ check.logContains(" no js and wasm distributions found, both are required for compatibility" )
84+ }
6685 }
6786 }
6887
6988 @Test
70- fun testWebJsWasm () = assertSuccessfulCompatibilityRun(
71- projectPath = " application/webJsWasm" ,
72- successfulTasks = listOf (
73- " :composeApp:jsBrowserDistribution" ,
74- " :composeApp:wasmJsBrowserDistribution"
75- ),
76- expectedFiles = setOf (
77- " composeApp.js" ,
78- " composeResources" ,
79- " index.html" ,
80- " originJsComposeApp.js" ,
81- " originJsComposeApp.js.map" ,
82- " originWasmComposeApp.js" ,
83- " originWasmComposeApp.js.map" ,
84- " styles.css"
85- )
86- )
89+ fun testWebJsNonExecutable () {
90+ with (testProject(" application/webApp" )) {
91+ applyBuildConfig(" WebJsNonExecutable" )
92+ gradle(" :composeCompatibilityBrowserDistribution" ).checks {
93+ check.taskSkipped(" :composeCompatibilityBrowserDistribution" )
94+ check.logContains(" no js and wasm distributions found, both are required for compatibility" )
95+ }
96+ }
97+ }
8798
8899 @Test
89- fun testWebJsOnly () = assertSkippedCompatibilityRun(
90- projectPath = " application/webJsOnly"
91- )
100+ fun testWebSingleExecutable () {
101+ with (testProject(" application/webApp" )) {
102+ applyBuildConfig(" WebSingleExecutable" )
103+ gradle(" :composeCompatibilityBrowserDistribution" ).checks {
104+ check.taskSkipped(" :composeCompatibilityBrowserDistribution" )
105+ check.logContains(" no js and wasm distributions found, both are required for compatibility" )
106+ }
107+ }
108+ }
92109
93110 @Test
94- fun testWebWasmOnly () = assertSkippedCompatibilityRun(
95- projectPath = " application/webWasmOnly"
96- )
111+ fun testWebJsWasmNonStandardTargetNames () {
112+ with (testProject(" application/webApp" )) {
113+ applyBuildConfig(" WebJsWasmNonStandardTargetNames" )
114+ file(" src/jsMain" ).renameTo(file(" src/webJsMain" ))
115+ file(" src/wasmJsMain" ).renameTo(file(" src/webWasmMain" ))
116+
117+ gradle(" :composeCompatibilityBrowserDistribution" ).checks {
118+ check.taskSuccessful(" :composeCompatibilityBrowserDistribution" )
119+ check.taskSuccessful(" :webJsBrowserDistribution" )
120+ check.taskSuccessful(" :webWasmBrowserDistribution" )
121+ }
122+ assertCompatibilityDistribution(
123+ expectedFileNames = setOf (
124+ " composeApp.js" ,
125+ " composeResources" ,
126+ " index.html" ,
127+ " originJsComposeApp.js" ,
128+ " originJsComposeApp.js.map" ,
129+ " originWasmComposeApp.js" ,
130+ " originWasmComposeApp.js.map" ,
131+ " styles.css"
132+ )
133+ )
134+ }
135+ }
97136
98137 @Test
99- fun testWebJsNonExecutable () = assertSkippedCompatibilityRun(
100- projectPath = " application/webJsWasmNonExecutable"
101- )
138+ @Ignore(" WebPack outputFileName doesn't reflect a real name of the bundle." )
139+ fun testWebJsWasmNonStandardBundleNames () {
140+ with (testProject(" application/webApp" )) {
141+ applyBuildConfig(" WebJsWasmNonStandardBundleNames" )
142+ gradle(" :composeCompatibilityBrowserDistribution" ).checks {
143+ check.taskSuccessful(" :composeCompatibilityBrowserDistribution" )
144+ check.taskSuccessful(" :jsBrowserDistribution" )
145+ check.taskSuccessful(" :wasmJsBrowserDistribution" )
146+ }
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+ }
102161
103162 @Test
104- fun testWebJsWasmNonStandard () = assertSuccessfulCompatibilityRun(
105- projectPath = " application/webJsWasmNonStandard" ,
106- successfulTasks = listOf (
107- " :composeApp:webJsBrowserDistribution" ,
108- " :composeApp:webWasmBrowserDistribution"
109- ),
110- expectedFiles = setOf (
111- " composeApp.js" ,
112- " composeResources" ,
113- " index.html" ,
114- " originJsComposeApp.js" ,
115- " originJsComposeApp.js.map" ,
116- " originWasmComposeApp.js" ,
117- " originWasmComposeApp.js.map" ,
118- " styles.css"
119- )
120- )
163+ fun testWebJsWasmRepacked () {
164+ with (testProject(" application/webApp" )) {
165+ applyBuildConfig(" WebJsWasmRepacked" )
166+ gradle(" :composeCompatibilityBrowserDistribution" ).checks {
167+ check.taskSuccessful(" :composeCompatibilityBrowserDistribution" )
168+ check.taskSuccessful(" :jsBrowserDistribution" )
169+ check.taskSuccessful(" :wasmJsBrowserDistribution" )
170+ check.taskSuccessful(" :jsRepack" )
171+ check.taskSuccessful(" :wasmRepack" )
172+ }
173+ assertCompatibilityDistribution(
174+ expectedFileNames = setOf (
175+ " composeResources" ,
176+ " index.html" ,
177+ " originJsRepackedApp.js" ,
178+ " originJsRepackedApp.js.map" ,
179+ " originWasmRepackedApp.js" ,
180+ " originWasmRepackedApp.js.map" ,
181+ " repackedApp.js" ,
182+ " styles.css"
183+ )
184+ )
185+ }
186+ }
121187
188+ // https://youtrack.jetbrains.com/issue/CMP-8760
122189 @Test
123- fun testWebJsWasmReconfigured () = assertSuccessfulCompatibilityRun(
124- projectPath = " application/webJsWasmReconfigured" ,
125- successfulTasks = listOf (
126- " :composeApp:wasmRepack" ,
127- " :composeApp:jsRepack"
128- ),
129- expectedFiles = setOf (
130- " composeResources" ,
131- " index.html" ,
132- " originJsRepackedApp.js" ,
133- " originJsRepackedApp.js.map" ,
134- " originWasmRepackedApp.js" ,
135- " originWasmRepackedApp.js.map" ,
136- " repackedApp.js" ,
137- " styles.css"
138- )
139- )
190+ fun checkWebAppWithKmmBridge () {
191+ with (testProject(" application/webApp" )) {
192+ applyBuildConfig(" 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+ }
140212}
0 commit comments