Skip to content

Commit

Permalink
[Gradle, JS] Add test on valid of webpack config
Browse files Browse the repository at this point in the history
^KT-48273 fixed
  • Loading branch information
ilgonmic authored and Space committed Aug 18, 2021
1 parent af32a88 commit dc5b47b
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject

plugins {
kotlin("js") version "<pluginMarkerVersion>"
}

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<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack>("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<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack>("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<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack>("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<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack>("browserProductionRun").map { it.configFile }.get()
args("configtest")
args(configFile.absolutePath)
}
binaries.executable()
browser {
webpackTask {
generateConfigOnly = true
}
runTask {
generateConfigOnly = true
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
}

rootProject.name = "kotlin-js-test-webpack-config"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

fun main() {
console.log("Hello, ${greet()}")
}

fun greet() = "world"

0 comments on commit dc5b47b

Please sign in to comment.