[Gradle, JS] Add test on dependencies clash

^KT-40093 fixed
This commit is contained in:
Ilya Goncharov
2020-07-08 12:04:55 +03:00
parent 2e2a5a0156
commit 3d9353f7f5
8 changed files with 121 additions and 5 deletions
@@ -9,10 +9,7 @@ import com.google.gson.Gson
import org.gradle.api.logging.LogLevel
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
import org.jetbrains.kotlin.gradle.targets.js.ir.KLIB_TYPE
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProjectModules
import org.jetbrains.kotlin.gradle.targets.js.npm.PackageJson
import org.jetbrains.kotlin.gradle.targets.js.npm.fromSrcPackageJson
import org.jetbrains.kotlin.gradle.targets.js.npm.*
import org.jetbrains.kotlin.gradle.tasks.USING_JS_INCREMENTAL_COMPILATION_MESSAGE
import org.jetbrains.kotlin.gradle.tasks.USING_JS_IR_BACKEND_MESSAGE
import org.jetbrains.kotlin.gradle.util.*
@@ -678,5 +675,37 @@ abstract class AbstractKotlin2JsGradlePluginIT(private val irBackend: Boolean) :
}
}
@Test
fun testUpdatingPackageJsonOnDependenciesClash() = with(Project("kotlin-js-dependencies-clash")) {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
fun assertFileVersion(
packageJson: PackageJson,
dependency: String
) {
val version = packageJson.dependencies[dependency]!!
assertTrue("${packageJson.name} must have $dependency with file version, but $version found") {
version.isFileVersion()
}
}
build("packageJson", "rootPackageJson", "kotlinNpmInstall") {
assertSuccessful()
fun getPackageJson(subProject: String) =
fileInWorkingDir("build/js/packages/kotlin-js-dependencies-clash-$subProject")
.resolve(NpmProject.PACKAGE_JSON)
.let {
Gson().fromJson(it.readText(), PackageJson::class.java)
}
val basePackageJson = getPackageJson("base")
val libPackageJson = getPackageJson("lib")
val dependency = "kotlinx-coroutines-core"
assertFileVersion(basePackageJson, dependency)
assertFileVersion(libPackageJson, dependency)
}
}
}
@@ -0,0 +1,18 @@
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType.BOTH as BOTH_TYPE
plugins {
kotlin("js")
}
dependencies {
implementation(kotlin("stdlib-js"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.5")
}
kotlin {
js {
useCommonJs()
nodejs {
}
}
}
@@ -0,0 +1,14 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package com.example
fun best(): Int {
return 42
}
fun simpleBest(): Int {
return 73
}
@@ -0,0 +1,13 @@
plugins {
kotlin("js").version("<pluginMarkerVersion>").apply(false)
}
group = "com.example"
version = "1.0"
allprojects {
repositories {
mavenLocal()
jcenter()
}
}
@@ -0,0 +1,17 @@
plugins {
kotlin("js")
}
dependencies {
implementation(kotlin("stdlib-js"))
implementation(project(":base"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.7")
}
kotlin {
target {
useCommonJs()
nodejs {
}
}
}
@@ -0,0 +1,14 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package com.example
fun answer(): Int {
return best()
}
fun sheldon(): Int {
return simpleBest()
}
@@ -0,0 +1,11 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
}
rootProject.name = "kotlin-js-dependencies-clash"
include("base")
include("lib")
@@ -142,7 +142,7 @@ internal fun onlyNameNpmDependency(
throw IllegalArgumentException("NPM dependency '$name' doesn't have version. Please, set version explicitly.")
}
internal fun String.isFileVersion() =
fun String.isFileVersion() =
startsWith(FILE_VERSION_PREFIX)
internal fun fileVersion(directory: File): String =