From dc5b47b921fbda45284e4405a7645fcaca7c2401 Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Tue, 17 Aug 2021 19:10:39 +0300 Subject: [PATCH] [Gradle, JS] Add test on valid of webpack config ^KT-48273 fixed --- .../kotlin/gradle/Kotlin2JsGradlePluginIT.kt | 38 ++++++++++++ .../build.gradle.kts | 58 +++++++++++++++++++ .../settings.gradle.kts | 8 +++ .../src/main/kotlin/Simple.kt | 6 ++ 4 files changed, 110 insertions(+) create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin-js-test-webpack-config/build.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin-js-test-webpack-config/settings.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin-js-test-webpack-config/src/main/kotlin/Simple.kt diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt index 1083c75bbf3d1..bb1388b284e47 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt @@ -965,6 +965,44 @@ abstract class AbstractKotlin2JsGradlePluginIT(val irBackend: Boolean) : BaseGra .let { Gson().fromJson(it.readText(), PackageJson::class.java) } + + @Test + fun testWebpackConfig() { + with(Project("kotlin-js-test-webpack-config")) { + setupWorkingDir() + gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl) + + build( + "browserDevelopmentWebpack" + ) { + assertSuccessful() + } + + build( + "checkConfigDevelopmentWebpack", + ) { + assertSuccessful() + } + + build( + "checkConfigProductionWebpack", + ) { + assertSuccessful() + } + + build( + "checkConfigDevelopmentRun", + ) { + assertSuccessful() + } + + build( + "checkConfigProductionRun", + ) { + assertSuccessful() + } + } + } } class GeneralKotlin2JsGradlePluginIT : BaseGradleIT() { diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin-js-test-webpack-config/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin-js-test-webpack-config/build.gradle.kts new file mode 100644 index 0000000000000..ab3babad3d4f9 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin-js-test-webpack-config/build.gradle.kts @@ -0,0 +1,58 @@ +import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject + +plugins { + kotlin("js") version "" +} + +dependencies { + implementation(kotlin("stdlib-js")) +} + +repositories { + mavenLocal() + mavenCentral() +} + +kotlin { + js { + val compilation = compilations.getByName("main") + org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec.create(compilation, "checkConfigDevelopmentWebpack") { + inputFileProperty.set(provider { compilation.npmProject.require("webpack/bin/webpack.js") }.map { RegularFile { File(it) } }) + dependsOn("browserDevelopmentWebpack") + val configFile = tasks.named("browserDevelopmentWebpack").map { it.configFile }.get() + configFile.parentFile.listFiles().forEach { println(it)} + args("configtest") + args(configFile.absolutePath) + } + org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec.create(compilation, "checkConfigProductionWebpack") { + inputFileProperty.set(provider { compilation.npmProject.require("webpack/bin/webpack.js") }.map { RegularFile { File(it) } }) + dependsOn("browserProductionWebpack") + val configFile = tasks.named("browserProductionWebpack").map { it.configFile }.get() + args("configtest") + args(configFile.absolutePath) + } + org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec.create(compilation, "checkConfigDevelopmentRun") { + inputFileProperty.set(provider { compilation.npmProject.require("webpack/bin/webpack.js") }.map { RegularFile { File(it) } }) + dependsOn("browserDevelopmentRun") + val configFile = tasks.named("browserDevelopmentRun").map { it.configFile }.get() + args("configtest") + args(configFile.absolutePath) + } + org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec.create(compilation, "checkConfigProductionRun") { + inputFileProperty.set(provider { compilation.npmProject.require("webpack/bin/webpack.js") }.map { RegularFile { File(it) } }) + dependsOn("browserProductionRun") + val configFile = tasks.named("browserProductionRun").map { it.configFile }.get() + args("configtest") + args(configFile.absolutePath) + } + binaries.executable() + browser { + webpackTask { + generateConfigOnly = true + } + runTask { + generateConfigOnly = true + } + } + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin-js-test-webpack-config/settings.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin-js-test-webpack-config/settings.gradle.kts new file mode 100644 index 0000000000000..dcb66c03adb24 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin-js-test-webpack-config/settings.gradle.kts @@ -0,0 +1,8 @@ +pluginManagement { + repositories { + mavenLocal() + gradlePluginPortal() + } +} + +rootProject.name = "kotlin-js-test-webpack-config" \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin-js-test-webpack-config/src/main/kotlin/Simple.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin-js-test-webpack-config/src/main/kotlin/Simple.kt new file mode 100644 index 0000000000000..4dac81088ad8c --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin-js-test-webpack-config/src/main/kotlin/Simple.kt @@ -0,0 +1,6 @@ + +fun main() { + console.log("Hello, ${greet()}") +} + +fun greet() = "world" \ No newline at end of file