[test] Enable Gradle integration testing for JS sourcemaps
This commit is contained in:
+109
-20
@@ -615,48 +615,137 @@ abstract class AbstractKotlin2JsGradlePluginIT(protected val irBackend: Boolean)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@DisplayName("source map is generated")
|
@DisplayName("source map is generated")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
|
fun testKotlinJsSourceMap(gradleVersion: GradleVersion) {
|
||||||
|
project("kotlin2JsProjectWithSourceMap", gradleVersion) {
|
||||||
|
build(if (irBackend) "compileDevelopmentExecutableKotlinJs" else "compileKotlinJs") {
|
||||||
|
val mapFilePath = projectPath
|
||||||
|
.resolve("build/js/packages/$projectName-app/kotlin/$projectName-app.js.map")
|
||||||
|
assertFileContains(
|
||||||
|
mapFilePath,
|
||||||
|
"\"../../../../../app/src/main/kotlin/main.kt\"",
|
||||||
|
"\"../../../../../lib/src/main/kotlin/foo.kt\"",
|
||||||
|
"\"sourcesContent\":[null",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("prefix is added to paths in source map")
|
||||||
@DisabledIf(
|
@DisabledIf(
|
||||||
"org.jetbrains.kotlin.gradle.AbstractKotlin2JsGradlePluginIT#getIrBackend",
|
"org.jetbrains.kotlin.gradle.AbstractKotlin2JsGradlePluginIT#getIrBackend",
|
||||||
disabledReason = "Source maps are not supported in IR backend"
|
disabledReason = "Source maps are not supported in IR backend"
|
||||||
)
|
)
|
||||||
fun testKotlinJsSourceMap(gradleVersion: GradleVersion) {
|
@GradleTest
|
||||||
project("kotlin2JsNoOutputFileProject", gradleVersion) {
|
fun testKotlinJsSourceMapCustomPrefix(gradleVersion: GradleVersion) {
|
||||||
buildGradle.appendText(
|
project("kotlin2JsProjectWithSourceMap", gradleVersion) {
|
||||||
|
buildGradleKts.appendText(
|
||||||
"""
|
"""
|
||||||
|
|project("app") {
|
||||||
|
| tasks.withType<KotlinJsCompile> {
|
||||||
|
| kotlinOptions.sourceMapPrefix = "appPrefix/"
|
||||||
|
| }
|
||||||
|
|}
|
||||||
|
|
|
||||||
|
|project("lib") {
|
||||||
|
| tasks.withType<KotlinJsCompile> {
|
||||||
|
| kotlinOptions.sourceMapPrefix = "libPrefix/"
|
||||||
|
| }
|
||||||
|
|}
|
||||||
|
|
|
|
||||||
|compileKotlin2Js.kotlinOptions.sourceMap = true
|
|
||||||
|compileKotlin2Js.kotlinOptions.sourceMapPrefix = "prefixprefix/"
|
|
||||||
|compileKotlin2Js.kotlinOptions.outputFile = "${'$'}{buildDir}/kotlin2js/main/app.js"
|
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
)
|
)
|
||||||
|
build(if (irBackend) "compileDevelopmentExecutableKotlinJs" else "compileKotlinJs") {
|
||||||
|
val mapFilePath = projectPath
|
||||||
|
.resolve("build/js/packages/$projectName-app/kotlin/$projectName-app.js.map")
|
||||||
|
assertFileContains(
|
||||||
|
mapFilePath,
|
||||||
|
"\"appPrefix/src/main/kotlin/main.kt\"",
|
||||||
|
"\"appPrefix/libPrefix/src/main/kotlin/foo.kt\"",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
build("build") {
|
@DisplayName("path in source maps are remapped for custom outputFile")
|
||||||
val mapFilePath = projectPath.resolve("build/kotlin2js/main/app.js.map")
|
@DisabledIf(
|
||||||
assertFileExists(mapFilePath)
|
"org.jetbrains.kotlin.gradle.AbstractKotlin2JsGradlePluginIT#getIrBackend",
|
||||||
val sourceFilePath = "prefixprefix/src/main/kotlin/example/Dummy.kt"
|
disabledReason = "Source maps are not supported in IR backend"
|
||||||
assertFileContains(mapFilePath, "\"$sourceFilePath\"")
|
)
|
||||||
|
@GradleTest
|
||||||
|
fun testKotlinJsSourceMapCustomOutputFile(gradleVersion: GradleVersion) {
|
||||||
|
project("kotlin2JsProjectWithSourceMap", gradleVersion) {
|
||||||
|
val taskSelector = if (irBackend)
|
||||||
|
"named<KotlinJsIrLink>(\"compileDevelopmentExecutableKotlinJs\")"
|
||||||
|
else
|
||||||
|
"withType<KotlinJsCompile>"
|
||||||
|
buildGradleKts.appendText(
|
||||||
|
"""
|
||||||
|
|project("app") {
|
||||||
|
| tasks.$taskSelector {
|
||||||
|
| kotlinOptions.outputFile = "${'$'}{buildDir}/kotlin2js/app.js"
|
||||||
|
| }
|
||||||
|
|}
|
||||||
|
|
|
||||||
|
""".trimMargin()
|
||||||
|
)
|
||||||
|
build(if (irBackend) "compileDevelopmentExecutableKotlinJs" else "compileKotlinJs") {
|
||||||
|
val mapFilePath = subProject("app").projectPath
|
||||||
|
.resolve("build/kotlin2js/app.js.map")
|
||||||
|
assertFileContains(
|
||||||
|
mapFilePath,
|
||||||
|
"\"../../src/main/kotlin/main.kt\"",
|
||||||
|
"\"../../../../../lib/src/main/kotlin/foo.kt\"",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("source map is not generated when disabled")
|
||||||
|
@GradleTest
|
||||||
|
fun testKotlinJsSourceMapDisabled(gradleVersion: GradleVersion) {
|
||||||
|
project("kotlin2JsProjectWithSourceMap", gradleVersion) {
|
||||||
|
buildGradleKts.appendText(
|
||||||
|
"""
|
||||||
|
|allprojects {
|
||||||
|
| tasks.withType<KotlinJsCompile> {
|
||||||
|
| kotlinOptions.sourceMap = false
|
||||||
|
| }
|
||||||
|
|}
|
||||||
|
|
|
||||||
|
""".trimMargin()
|
||||||
|
)
|
||||||
|
build(if (irBackend) "compileDevelopmentExecutableKotlinJs" else "compileKotlinJs") {
|
||||||
|
val jsFilePath = projectPath.resolve("build/js/packages/$projectName-app/kotlin/$projectName-app.js")
|
||||||
|
assertFileExists(jsFilePath)
|
||||||
|
assertFileNotExists(Path("$jsFilePath.map"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("sources can be embedded into source map")
|
@DisplayName("sources can be embedded into source map")
|
||||||
@GradleTest
|
|
||||||
@DisabledIf(
|
@DisabledIf(
|
||||||
"org.jetbrains.kotlin.gradle.AbstractKotlin2JsGradlePluginIT#getIrBackend",
|
"org.jetbrains.kotlin.gradle.AbstractKotlin2JsGradlePluginIT#getIrBackend",
|
||||||
disabledReason = "Source maps are not supported in IR backend"
|
disabledReason = "Source maps are not supported in IR backend"
|
||||||
)
|
)
|
||||||
fun testKotlinJsSourceMapInline(gradleVersion: GradleVersion) {
|
@GradleTest
|
||||||
project("kotlin2JsProjectWithSourceMapInline", gradleVersion) {
|
fun testKotlinJsSourceMapEmbedSources(gradleVersion: GradleVersion) {
|
||||||
build("build") {
|
project("kotlin2JsProjectWithSourceMap", gradleVersion) {
|
||||||
val mapFilePath = subProject("app").kotlinClassesDir().resolve("app.js.map")
|
buildGradleKts.appendText(
|
||||||
assertFileExists(mapFilePath)
|
"""
|
||||||
|
|allprojects {
|
||||||
|
| tasks.withType<KotlinJsCompile> {
|
||||||
|
| kotlinOptions.sourceMapEmbedSources = "always"
|
||||||
|
| }
|
||||||
|
|}
|
||||||
|
|
|
||||||
|
""".trimMargin()
|
||||||
|
)
|
||||||
|
build(if (irBackend) "compileDevelopmentExecutableKotlinJs" else "compileKotlinJs") {
|
||||||
|
val mapFilePath = projectPath.resolve("build/js/packages/$projectName-app/kotlin/$projectName-app.js.map")
|
||||||
assertFileContains(
|
assertFileContains(
|
||||||
mapFilePath,
|
mapFilePath,
|
||||||
"\"./src/main/kotlin/main.kt\"",
|
|
||||||
"\"./src/main/kotlin/foo.kt\"",
|
|
||||||
"\"fun main(args: Array<String>) {",
|
"\"fun main(args: Array<String>) {",
|
||||||
"\"inline fun foo(): String {",
|
"\"inline fun foo(): String {",
|
||||||
)
|
)
|
||||||
|
|||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
|
||||||
|
import kotlin.text.toBoolean
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("js")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
apply(plugin = "org.jetbrains.kotlin.js")
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val useIrBackend = (findProperty("kotlin.js.useIrBackend") as? String?)?.toBoolean() ?: false
|
||||||
|
|
||||||
|
val backend = if (useIrBackend) {
|
||||||
|
KotlinJsCompilerType.IR
|
||||||
|
} else {
|
||||||
|
KotlinJsCompilerType.LEGACY
|
||||||
|
}
|
||||||
|
|
||||||
|
project("lib") {
|
||||||
|
kotlin {
|
||||||
|
js(backend) {
|
||||||
|
browser()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project("app") {
|
||||||
|
kotlin {
|
||||||
|
js(backend) {
|
||||||
|
browser()
|
||||||
|
binaries.executable()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
implementation(project(":lib"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<KotlinJsCompile>() {
|
||||||
|
kotlinOptions.sourceMap = true
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
rootProject.name = "kotlin2JsProjectWithSourceMap"
|
||||||
|
include "app", "lib"
|
||||||
-37
@@ -1,37 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenLocal()
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
allprojects {
|
|
||||||
plugins.apply('org.jetbrains.kotlin.platform.js')
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenLocal()
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
|
|
||||||
}
|
|
||||||
|
|
||||||
compileKotlin2Js {
|
|
||||||
kotlinOptions.freeCompilerArgs = [ "-Xskip-metadata-version-check" ]
|
|
||||||
kotlinOptions.sourceMap = true
|
|
||||||
kotlinOptions.sourceMapPrefix = "./"
|
|
||||||
kotlinOptions.sourceMapEmbedSources = "always"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
project("app") {
|
|
||||||
dependencies {
|
|
||||||
implementation project(":lib")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
include ':app', ':lib'
|
|
||||||
Reference in New Issue
Block a user