[K/JS] Fix file extension inside the JS KGP to run tests with ES modules ^KT-63719 Fixed

This commit is contained in:
Artem Kobzar
2023-12-12 14:52:26 +00:00
committed by Space Team
parent 4c7ad7eeb5
commit 0b1c4b836a
9 changed files with 129 additions and 4 deletions
@@ -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"
)
}
}
}
}
@@ -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>
@@ -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()
}
}
@@ -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
}
@@ -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())
}
}