[K/JS] Fix file extension inside the JS KGP to run tests with ES modules ^KT-63719 Fixed
This commit is contained in:
+46
@@ -1859,4 +1859,50 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("Check that nodeTest run tests with commonjs module kind")
|
||||||
|
@GradleTest
|
||||||
|
fun testFailedJsTestWithCommonJs(gradleVersion: GradleVersion) {
|
||||||
|
project("kotlin-js-project-failed-test", gradleVersion) {
|
||||||
|
buildGradle.appendText(
|
||||||
|
"""
|
||||||
|
|
|
||||||
|
|tasks.withType(KotlinJsCompile).configureEach {
|
||||||
|
| kotlinOptions { moduleKind = "commonjs" }
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
)
|
||||||
|
buildAndFail("nodeTest") {
|
||||||
|
assertTasksFailed(":nodeTest")
|
||||||
|
|
||||||
|
assertTestResults(
|
||||||
|
projectPath.resolve("TEST-all.xml"),
|
||||||
|
"nodeTest"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("Check that nodeTest run tests with ESM module kind")
|
||||||
|
@GradleTest
|
||||||
|
fun testFailedJsTestWithESM(gradleVersion: GradleVersion) {
|
||||||
|
project("kotlin-js-project-failed-test", gradleVersion) {
|
||||||
|
buildGradle.appendText(
|
||||||
|
"""
|
||||||
|
|
|
||||||
|
|tasks.withType(KotlinJsCompile).configureEach {
|
||||||
|
| kotlinOptions { moduleKind = "es" }
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
)
|
||||||
|
buildAndFail("nodeTest") {
|
||||||
|
assertTasksFailed(":nodeTest")
|
||||||
|
|
||||||
|
assertTestResults(
|
||||||
|
projectPath.resolve("TEST-all.xml"),
|
||||||
|
"nodeTest"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<results>
|
||||||
|
<testsuite name="Tests" tests="1" skipped="0" failures="1" errors="0" timestamp="..." hostname="..." time="...">
|
||||||
|
<properties />
|
||||||
|
<testcase name="testHello[node]" classname="Tests" time="...">
|
||||||
|
<failure message="..." type="AssertionError">...</failure>
|
||||||
|
</testcase>
|
||||||
|
<system-out />
|
||||||
|
<system-err />
|
||||||
|
</testsuite>
|
||||||
|
</results>
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.js")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("org.jetbrains.kotlin:kotlin-stdlib-js")
|
||||||
|
testImplementation("org.jetbrains.kotlin:kotlin-test-js")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
js {
|
||||||
|
binaries.executable()
|
||||||
|
nodejs()
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
kotlin.tests.individualTaskReports=true
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* 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 getValue(): Int {
|
||||||
|
return 42
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class Tests {
|
||||||
|
@Test
|
||||||
|
fun testHello() {
|
||||||
|
assertEquals(73, com.example.getValue())
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
-1
@@ -12,9 +12,12 @@ import groovy.lang.Closure
|
|||||||
import org.gradle.api.Action
|
import org.gradle.api.Action
|
||||||
import org.gradle.api.attributes.AttributeContainer
|
import org.gradle.api.attributes.AttributeContainer
|
||||||
import org.gradle.api.tasks.TaskProvider
|
import org.gradle.api.tasks.TaskProvider
|
||||||
|
import org.gradle.api.provider.Provider
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptions
|
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptions
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
|
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
|
||||||
import org.jetbrains.kotlin.gradle.plugin.HasCompilerOptions
|
import org.jetbrains.kotlin.gradle.plugin.HasCompilerOptions
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl
|
import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetContainerDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetContainerDsl
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.JsBinary
|
import org.jetbrains.kotlin.gradle.targets.js.ir.JsBinary
|
||||||
@@ -99,4 +102,16 @@ open class KotlinJsCompilation @Inject internal constructor(
|
|||||||
project.configure(this, handler)
|
project.configure(this, handler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal val KotlinJsCompilation.fileExtension: Provider<String>
|
||||||
|
get() {
|
||||||
|
val isWasm = platformType == KotlinPlatformType.wasm
|
||||||
|
return compilerOptions.options.moduleKind.map { moduleKind ->
|
||||||
|
if (isWasm || moduleKind == JsModuleKind.MODULE_ES) {
|
||||||
|
"mjs"
|
||||||
|
} else {
|
||||||
|
"js"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-3
@@ -9,7 +9,10 @@ import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner
|
|||||||
import org.jetbrains.kotlin.gradle.incremental.IncrementalModuleInfoBuildService
|
import org.jetbrains.kotlin.gradle.incremental.IncrementalModuleInfoBuildService
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationInfo
|
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationInfo
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.getExtension
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaTarget
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaTarget
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.fileExtension
|
||||||
import org.jetbrains.kotlin.gradle.plugin.tcs
|
import org.jetbrains.kotlin.gradle.plugin.tcs
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetType
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetType
|
||||||
@@ -40,7 +43,8 @@ internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
|||||||
|
|
||||||
configureAdditionalFreeCompilerArguments(task, compilation)
|
configureAdditionalFreeCompilerArguments(task, compilation)
|
||||||
|
|
||||||
val compilationTarget = compilation.tcs.compilation.target
|
val binaryCompilation = compilation.tcs.compilation
|
||||||
|
val compilationTarget = binaryCompilation.target
|
||||||
if (compilationTarget is KotlinJsTarget ||
|
if (compilationTarget is KotlinJsTarget ||
|
||||||
(compilationTarget is KotlinWithJavaTarget<*, *> && compilationTarget.platformType == KotlinPlatformType.js)
|
(compilationTarget is KotlinWithJavaTarget<*, *> && compilationTarget.platformType == KotlinPlatformType.js)
|
||||||
) {
|
) {
|
||||||
@@ -57,8 +61,10 @@ internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
|||||||
if (task.compilerOptions.outputFile.orNull != null) {
|
if (task.compilerOptions.outputFile.orNull != null) {
|
||||||
task.compilerOptions.outputFile.map { File(it) }
|
task.compilerOptions.outputFile.map { File(it) }
|
||||||
} else {
|
} else {
|
||||||
task.compilerOptions.moduleName.map { name ->
|
task.compilerOptions.moduleName.flatMap { name ->
|
||||||
dir.file(name + compilation.platformType.fileExtension).asFile
|
(binaryCompilation as KotlinJsCompilation).fileExtension.map {
|
||||||
|
dir.file("$name.$it").asFile
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user