[Gradle, JS] Add Gradle integration tests with language version 2.0
^KT-56740 fixed
This commit is contained in:
committed by
Space Team
parent
7a4c688b5c
commit
f204a34909
-70
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.gradle
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonNull
|
||||
import com.google.gson.JsonObject
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.testkit.runner.BuildResult
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||
@@ -20,7 +19,6 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.fromSrcPackageJson
|
||||
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockCopyTask.Companion.STORE_YARN_LOCK_NAME
|
||||
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockCopyTask.Companion.UPGRADE_YARN_LOCK
|
||||
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockCopyTask.Companion.YARN_LOCK_MISMATCH_MESSAGE
|
||||
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.testbase.*
|
||||
import org.jetbrains.kotlin.gradle.testbase.TestVersions.Gradle.G_7_6
|
||||
@@ -1026,51 +1024,6 @@ abstract class AbstractKotlin2JsGradlePluginIT(protected val irBackend: Boolean)
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("incremental compilation for js works")
|
||||
@GradleTest
|
||||
fun testIncrementalCompilation(gradleVersion: GradleVersion) {
|
||||
val buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)
|
||||
project("kotlin2JsICProject", gradleVersion, buildOptions = buildOptions) {
|
||||
build("compileKotlinJs", "compileTestKotlinJs") {
|
||||
checkIrCompilationMessage()
|
||||
assertOutputContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
assertCompiledKotlinSources(projectPath.allKotlinFiles.relativizeTo(projectPath), output)
|
||||
}
|
||||
|
||||
build("compileKotlinJs", "compileTestKotlinJs") {
|
||||
assertCompiledKotlinSources(emptyList(), output)
|
||||
}
|
||||
|
||||
val modifiedFile = subProject("lib").kotlinSourcesDir().resolve("A.kt") ?: error("No A.kt file in test project")
|
||||
modifiedFile.modify {
|
||||
it.replace("val x = 0", "val x = \"a\"")
|
||||
}
|
||||
build("compileKotlinJs", "compileTestKotlinJs") {
|
||||
checkIrCompilationMessage()
|
||||
assertOutputContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
val affectedFiles = listOf("A.kt", "useAInLibMain.kt", "useAInAppMain.kt", "useAInAppTest.kt").mapNotNull {
|
||||
projectPath.findInPath(it)
|
||||
}
|
||||
assertCompiledKotlinSources(affectedFiles.relativizeTo(projectPath), output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("non-incremental compilation works")
|
||||
@GradleTest
|
||||
fun testIncrementalCompilationDisabled(gradleVersion: GradleVersion) {
|
||||
val jsOptions = defaultJsOptions.run {
|
||||
if (irBackend) copy(incrementalJsKlib = false) else copy(incrementalJs = false)
|
||||
}
|
||||
val options = defaultBuildOptions.copy(jsOptions = jsOptions)
|
||||
project("kotlin2JsICProject", gradleVersion, buildOptions = options) {
|
||||
build("compileKotlinJs", "compileTestKotlinJs") {
|
||||
checkIrCompilationMessage()
|
||||
assertOutputDoesNotContain(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("smoke test of org.jetbrains.kotlin.js plugin")
|
||||
@GradleTest
|
||||
@DisabledIf(
|
||||
@@ -1734,29 +1687,6 @@ abstract class AbstractKotlin2JsGradlePluginIT(protected val irBackend: Boolean)
|
||||
Gson().fromJson(it.readText(), PackageJson::class.java)
|
||||
}
|
||||
|
||||
@DisplayName("incremental compilation with multiple js modules after frontend compilation error works")
|
||||
@GradleTest
|
||||
fun testIncrementalCompilationWithMultipleModulesAfterCompilationError(gradleVersion: GradleVersion) {
|
||||
val buildOptions = defaultBuildOptions.copy(jsOptions = defaultJsOptions.copy(incrementalJsKlib = true))
|
||||
project("kotlin-js-ir-ic-multiple-artifacts", gradleVersion, buildOptions = buildOptions) {
|
||||
build("compileKotlinJs")
|
||||
|
||||
val libKt = subProject("lib").kotlinSourcesDir().resolve("Lib.kt") ?: error("No Lib.kt file in test project")
|
||||
val appKt = subProject("app").kotlinSourcesDir().resolve("App.kt") ?: error("No App.kt file in test project")
|
||||
|
||||
libKt.modify { it.replace("fun answer", "func answe") } // introduce compilation error
|
||||
buildAndFail("compileKotlinJs")
|
||||
libKt.modify { it.replace("func answe", "fun answer") } // revert compilation error
|
||||
appKt.modify { it.replace("Sheldon:", "Sheldon :") } // some change for incremental compilation
|
||||
build("compileKotlinJs", buildOptions = buildOptions.copy(logLevel = LogLevel.DEBUG)) {
|
||||
assertOutputContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
assertTasksUpToDate(":lib:compileKotlinJs")
|
||||
assertTasksExecuted(":app:compileKotlinJs")
|
||||
assertCompiledKotlinSources(listOf(appKt).relativizeTo(projectPath), output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("smoothly fail npm install")
|
||||
@GradleTest
|
||||
fun testFailNpmInstall(gradleVersion: GradleVersion) {
|
||||
|
||||
+18
-3
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import java.io.File
|
||||
import kotlin.io.path.appendText
|
||||
@@ -18,20 +19,34 @@ import kotlin.test.assertFalse
|
||||
import kotlin.test.assertNotEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@DisplayName("Incremental compilation tests for Kotlin JS IR backend with 2.0")
|
||||
@JsGradlePluginTests
|
||||
class Kotlin2FirJsIrBeIncrementalCompilationIT : Kotlin2JsIrBeIncrementalCompilationIT() {
|
||||
override val defaultBuildOptions: BuildOptions
|
||||
get() = super.defaultBuildOptions.copy(
|
||||
languageVersion = "2.0"
|
||||
)
|
||||
|
||||
@Disabled("Not found way to fail BE compilation with successful FE 2.0 compilation")
|
||||
override fun testRebuildAfterError(gradleVersion: GradleVersion) {
|
||||
super.testRebuildAfterError(gradleVersion)
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Incremental compilation tests for Kotlin JS IR backend")
|
||||
@JsGradlePluginTests
|
||||
class Kotlin2JsIrBeIncrementalCompilationIT : KGPBaseTest() {
|
||||
open class Kotlin2JsIrBeIncrementalCompilationIT : KGPBaseTest() {
|
||||
override val defaultBuildOptions = BuildOptions(
|
||||
jsOptions = BuildOptions.JsOptions(
|
||||
jsCompilerType = KotlinJsCompilerType.IR,
|
||||
incrementalJsKlib = true,
|
||||
incrementalJsIr = true
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
@DisplayName("Test rebuild after backend error")
|
||||
@GradleTest
|
||||
fun testRebuildAfterError(gradleVersion: GradleVersion) {
|
||||
open fun testRebuildAfterError(gradleVersion: GradleVersion) {
|
||||
project("kotlin-js-ir-ic-rebuild-after-error", gradleVersion) {
|
||||
fun readCacheFiles(): Map<String, Int> {
|
||||
val cacheFiles = mutableMapOf<String, Int>()
|
||||
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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 org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.testkit.runner.BuildResult
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||
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.testbase.*
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import kotlin.io.path.*
|
||||
import kotlin.test.*
|
||||
|
||||
@JsGradlePluginTests
|
||||
open class KotlinJsIr10IncrementalGradlePluginIT : AbstractKotlinJsIncrementalGradlePluginIT(
|
||||
irBackend = true
|
||||
)
|
||||
|
||||
@JsGradlePluginTests
|
||||
class KotlinJsFirIncrementalGradlePluginIT : KotlinJsIr10IncrementalGradlePluginIT() {
|
||||
override val defaultBuildOptions: BuildOptions
|
||||
get() = super.defaultBuildOptions.copy(
|
||||
languageVersion = "2.0"
|
||||
)
|
||||
}
|
||||
|
||||
@JsGradlePluginTests
|
||||
open class KotlinJsLegacy10IncrementalGradlePluginIT : AbstractKotlinJsIncrementalGradlePluginIT(
|
||||
irBackend = false
|
||||
)
|
||||
|
||||
@JsGradlePluginTests
|
||||
abstract class AbstractKotlinJsIncrementalGradlePluginIT(
|
||||
protected val irBackend: Boolean
|
||||
) : KGPBaseTest() {
|
||||
@Suppress("DEPRECATION")
|
||||
private val defaultJsOptions = BuildOptions.JsOptions(
|
||||
useIrBackend = irBackend,
|
||||
jsCompilerType = if (irBackend) KotlinJsCompilerType.IR else KotlinJsCompilerType.LEGACY
|
||||
)
|
||||
|
||||
override val defaultBuildOptions =
|
||||
super.defaultBuildOptions.copy(
|
||||
jsOptions = defaultJsOptions,
|
||||
)
|
||||
|
||||
protected fun BuildResult.checkIrCompilationMessage() {
|
||||
if (irBackend) {
|
||||
assertOutputContains(USING_JS_IR_BACKEND_MESSAGE)
|
||||
} else {
|
||||
assertOutputDoesNotContain(USING_JS_IR_BACKEND_MESSAGE)
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("incremental compilation for js works")
|
||||
@GradleTest
|
||||
fun testIncrementalCompilation(gradleVersion: GradleVersion) {
|
||||
val buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)
|
||||
project("kotlin2JsICProject", gradleVersion, buildOptions = buildOptions) {
|
||||
build("compileKotlinJs", "compileTestKotlinJs") {
|
||||
checkIrCompilationMessage()
|
||||
assertOutputContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
assertCompiledKotlinSources(projectPath.allKotlinFiles.relativizeTo(projectPath), output)
|
||||
}
|
||||
|
||||
build("compileKotlinJs", "compileTestKotlinJs") {
|
||||
assertCompiledKotlinSources(emptyList(), output)
|
||||
}
|
||||
|
||||
val modifiedFile = subProject("lib").kotlinSourcesDir().resolve("A.kt") ?: error("No A.kt file in test project")
|
||||
modifiedFile.modify {
|
||||
it.replace("val x = 0", "val x = \"a\"")
|
||||
}
|
||||
build("compileKotlinJs", "compileTestKotlinJs") {
|
||||
checkIrCompilationMessage()
|
||||
assertOutputContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
val affectedFiles = listOf("A.kt", "useAInLibMain.kt", "useAInAppMain.kt", "useAInAppTest.kt").mapNotNull {
|
||||
projectPath.findInPath(it)
|
||||
}
|
||||
assertCompiledKotlinSources(affectedFiles.relativizeTo(projectPath), output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("non-incremental compilation works")
|
||||
@GradleTest
|
||||
fun testIncrementalCompilationDisabled(gradleVersion: GradleVersion) {
|
||||
val jsOptions = defaultJsOptions.run {
|
||||
if (irBackend) copy(incrementalJsKlib = false) else copy(incrementalJs = false)
|
||||
}
|
||||
val options = defaultBuildOptions.copy(jsOptions = jsOptions)
|
||||
project("kotlin2JsICProject", gradleVersion, buildOptions = options) {
|
||||
build("compileKotlinJs", "compileTestKotlinJs") {
|
||||
checkIrCompilationMessage()
|
||||
assertOutputDoesNotContain(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("incremental compilation with multiple js modules after frontend compilation error works")
|
||||
@GradleTest
|
||||
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_6)
|
||||
fun testIncrementalCompilationWithMultipleModulesAfterCompilationError(gradleVersion: GradleVersion) {
|
||||
val buildOptions = defaultBuildOptions.copy(jsOptions = defaultJsOptions.copy(incrementalJsKlib = true))
|
||||
project("kotlin-js-ir-ic-multiple-artifacts", gradleVersion, buildOptions = buildOptions) {
|
||||
build("compileKotlinJs")
|
||||
|
||||
val libKt = subProject("lib").kotlinSourcesDir().resolve("Lib.kt") ?: error("No Lib.kt file in test project")
|
||||
val appKt = subProject("app").kotlinSourcesDir().resolve("App.kt") ?: error("No App.kt file in test project")
|
||||
|
||||
libKt.modify { it.replace("fun answer", "func answe") } // introduce compilation error
|
||||
buildAndFail("compileKotlinJs")
|
||||
libKt.modify { it.replace("func answe", "fun answer") } // revert compilation error
|
||||
appKt.modify { it.replace("Sheldon:", "Sheldon :") } // some change for incremental compilation
|
||||
build("compileKotlinJs", buildOptions = buildOptions.copy(logLevel = LogLevel.DEBUG)) {
|
||||
assertOutputContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
assertTasksUpToDate(":lib:compileKotlinJs")
|
||||
assertTasksExecuted(":app:compileKotlinJs")
|
||||
assertCompiledKotlinSources(listOf(appKt).relativizeTo(projectPath), output)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user