[K/Wasm] Generate .d.ts tests for K/Wasm in the same way as we do for K/JS ^KT-65778 Fixed

This commit is contained in:
Artem Kobzar
2024-03-05 15:33:56 +00:00
committed by Space Team
parent c2023142f5
commit 8d4948c3ee
310 changed files with 1643 additions and 1370 deletions
@@ -1,39 +0,0 @@
// CHECK_TYPESCRIPT_DECLARATIONS
// TARGET_BACKEND: WASM
// MODULE: main
// FILE: generics.kt
@JsExport
fun <T: JsAny?> simple(x: T): T = x
@JsExport
fun <A: JsAny?, B: JsAny?> second(a: A, b: B): B = b
@JsExport
fun <T: JsNumber> simpleWithConstraint(x: T): T = x
external interface Foo<T: JsAny> : JsAny {
val foo: T
}
external interface Bar : JsAny {
val bar: JsString
}
external object Baz : JsAny {
val baz: JsBoolean
}
fun getBaz(x: Foo<JsBigInt>): JsAny = js("({ baz: x.foo > 0n })")
@JsExport
fun <A, B> complexConstraint(x: A): B where A: Foo<JsBigInt>, A: Bar, B: Baz = getBaz(x).unsafeCast<B>()
// FILE: entry.mjs
import { simple, second, simpleWithConstraint, complexConstraint } from "./index.mjs";
if (simple("OK") != "OK") throw new Error("Unexpected result from `simple` function")
if (second(1, "OK") != "OK") throw new Error("Unexpected result from `second` function")
if (simpleWithConstraint(42) != 42) throw new Error("Unexpected result from `simpleConstraint` function")
if (JSON.stringify(complexConstraint({ foo: 1n, bar: "bar" })) != "{\"baz\":true}") throw new Error("Unexpected result from `complexConstraint` function")
+7 -24
View File
@@ -117,6 +117,7 @@ abstract class MochaTestTask : NpmTask(), VerificationTask
val testDataDir = project(":js:js.translator").projectDir.resolve("testData") val testDataDir = project(":js:js.translator").projectDir.resolve("testData")
val typescriptTestsDir = testDataDir.resolve("typescript-export") val typescriptTestsDir = testDataDir.resolve("typescript-export")
val jsTestsDir = typescriptTestsDir.resolve("js")
val installTsDependencies by task<NpmTask> { val installTsDependencies by task<NpmTask> {
val packageLockFile = testDataDir.resolve("package-lock.json") val packageLockFile = testDataDir.resolve("package-lock.json")
@@ -129,30 +130,12 @@ val installTsDependencies by task<NpmTask> {
args.set(listOf("install")) args.set(listOf("install"))
} }
fun parallel(tasksToRun: List<TaskProvider<*>>, beforeAll: TaskProvider<*>? = null, afterAll: TaskProvider<*>? = null): RegisteringDomainObjectDelegateProviderWithAction<out TaskContainer, Task> {
return tasks.registering {
tasksToRun.forEach { dependsOn(it) }
if (afterAll != null) {
finalizedBy(afterAll)
}
}.apply {
if (beforeAll != null) {
tasksToRun.forEach {
it.configure {
dependsOn(beforeAll)
}
}
}
}
}
val exportFileDirPostfix = "-in-exported-file" val exportFileDirPostfix = "-in-exported-file"
fun generateJsExportOnFileTestFor(dir: String): TaskProvider<Copy> = tasks.register<Copy>("generate-js-export-on-file-for-$dir") { fun generateJsExportOnFileTestFor(dir: String): TaskProvider<Copy> = tasks.register<Copy>("generate-js-export-on-file-for-$dir") {
val dirPostfix = exportFileDirPostfix val dirPostfix = exportFileDirPostfix
val inputDir = fileTree(typescriptTestsDir.resolve(dir)) val inputDir = fileTree(jsTestsDir.resolve(dir))
val outputDir = typescriptTestsDir.resolve("$dir$dirPostfix") val outputDir = jsTestsDir.resolve("$dir$dirPostfix")
inputs.files(inputDir.matching { inputs.files(inputDir.matching {
include("**/*.kt") include("**/*.kt")
@@ -191,7 +174,7 @@ fun generateJsExportOnFileTestFor(dir: String): TaskProvider<Copy> = tasks.regis
} }
fun generateTypeScriptTestFor(dir: String): TaskProvider<NpmTask> = tasks.register<NpmTask>("generate-ts-for-$dir") { fun generateTypeScriptTestFor(dir: String): TaskProvider<NpmTask> = tasks.register<NpmTask>("generate-ts-for-$dir") {
val baseDir = typescriptTestsDir.resolve(dir) val baseDir = jsTestsDir.resolve(dir)
val mainTsFile = fileTree(baseDir).files.find { it.name.endsWith("__main.ts") } ?: return@register val mainTsFile = fileTree(baseDir).files.find { it.name.endsWith("__main.ts") } ?: return@register
val mainJsFile = baseDir.resolve("${mainTsFile.nameWithoutExtension}.js") val mainJsFile = baseDir.resolve("${mainTsFile.nameWithoutExtension}.js")
@@ -201,12 +184,12 @@ fun generateTypeScriptTestFor(dir: String): TaskProvider<NpmTask> = tasks.regist
outputs.file(mainJsFile) outputs.file(mainJsFile)
outputs.upToDateWhen { mainJsFile.exists() } outputs.upToDateWhen { mainJsFile.exists() }
args.set(listOf("run", "generateTypeScriptTests", "--", "./typescript-export/$dir/tsconfig.json")) args.set(listOf("run", "generateTypeScriptTests", "--", "./typescript-export/js/$dir/tsconfig.json"))
} }
val generateTypeScriptTests by parallel( val generateTypeScriptTests by parallel(
beforeAll = installTsDependencies, beforeAll = installTsDependencies,
tasksToRun = typescriptTestsDir.listFiles { it: File -> tasksToRun = jsTestsDir.listFiles { it: File ->
it.isDirectory && it.isDirectory &&
!it.path.endsWith("module-systems") && !it.path.endsWith("module-systems") &&
!it.path.endsWith("module-systems-in-exported-file") !it.path.endsWith("module-systems-in-exported-file")
@@ -215,7 +198,7 @@ val generateTypeScriptTests by parallel(
) )
val generateTypeScriptJsExportOnFileTests by parallel( val generateTypeScriptJsExportOnFileTests by parallel(
typescriptTestsDir jsTestsDir
.listFiles { it: File -> .listFiles { it: File ->
it.isDirectory && it.isDirectory &&
!it.path.endsWith("selective-export") && !it.path.endsWith("selective-export") &&
@@ -140,11 +140,11 @@ fun main(args: Array<String>) {
} }
testClass<AbstractIrJsTypeScriptExportTest> { testClass<AbstractIrJsTypeScriptExportTest> {
model("typescript-export/", pattern = "^([^_](.+))\\.kt$") model("typescript-export/js/", pattern = "^([^_](.+))\\.kt$")
} }
testClass<AbstractIrJsES6TypeScriptExportTest> { testClass<AbstractIrJsES6TypeScriptExportTest> {
model("typescript-export/", pattern = "^([^_](.+))\\.kt$") model("typescript-export/js/", pattern = "^([^_](.+))\\.kt$")
} }
testClass<AbstractJsIrLineNumberTest> { testClass<AbstractJsIrLineNumberTest> {
@@ -164,11 +164,11 @@ fun main(args: Array<String>) {
} }
testClass<AbstractFirJsTypeScriptExportTest> { testClass<AbstractFirJsTypeScriptExportTest> {
model("typescript-export/", pattern = "^([^_](.+))\\.kt$") model("typescript-export/js/", pattern = "^([^_](.+))\\.kt$")
} }
testClass<AbstractFirJsES6TypeScriptExportTest> { testClass<AbstractFirJsES6TypeScriptExportTest> {
model("typescript-export/", pattern = "^([^_](.+))\\.kt$") model("typescript-export/js/", pattern = "^([^_](.+))\\.kt$")
} }
testClass<AbstractFirJsLineNumberTest> { testClass<AbstractFirJsLineNumberTest> {
@@ -101,7 +101,7 @@ open class AbstractIrJsCodegenInlineTest : AbstractJsIrTest(
) )
open class AbstractIrJsTypeScriptExportTest : AbstractJsIrTest( open class AbstractIrJsTypeScriptExportTest : AbstractJsIrTest(
pathToTestDir = "${JsEnvironmentConfigurator.TEST_DATA_DIR_PATH}/typescript-export/", pathToTestDir = "${JsEnvironmentConfigurator.TEST_DATA_DIR_PATH}/typescript-export/js/",
testGroupOutputDirPrefix = "typescript-export/ir/" testGroupOutputDirPrefix = "typescript-export/ir/"
) { ) {
override fun configure(builder: TestConfigurationBuilder) { override fun configure(builder: TestConfigurationBuilder) {
@@ -111,7 +111,7 @@ open class AbstractIrJsTypeScriptExportTest : AbstractJsIrTest(
} }
open class AbstractIrJsES6TypeScriptExportTest : AbstractJsIrES6Test( open class AbstractIrJsES6TypeScriptExportTest : AbstractJsIrES6Test(
pathToTestDir = "${JsEnvironmentConfigurator.TEST_DATA_DIR_PATH}/typescript-export/", pathToTestDir = "${JsEnvironmentConfigurator.TEST_DATA_DIR_PATH}/typescript-export/js/",
testGroupOutputDirPrefix = "typescript-export/ir-es6/" testGroupOutputDirPrefix = "typescript-export/ir-es6/"
) { ) {
override fun configure(builder: TestConfigurationBuilder) { override fun configure(builder: TestConfigurationBuilder) {
@@ -9,7 +9,6 @@ import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil; import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TargetBackend; import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata; import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
@@ -108,14 +107,4 @@ public class FirJsCodegenWasmJsInteropTestGenerated extends AbstractFirJsCodegen
public void testVararg() { public void testVararg() {
runTest("compiler/testData/codegen/boxWasmJsInterop/vararg.kt"); runTest("compiler/testData/codegen/boxWasmJsInterop/vararg.kt");
} }
@Nested
@TestMetadata("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations")
@TestDataPath("$PROJECT_ROOT")
public class TypeScriptDeclarations {
@Test
public void testAllFilesPresentInTypeScriptDeclarations() {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
}
} }
@@ -9,7 +9,6 @@ import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil; import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TargetBackend; import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata; import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
@@ -108,14 +107,4 @@ public class FirJsES6CodegenWasmJsInteropTestGenerated extends AbstractFirJsES6C
public void testVararg() { public void testVararg() {
runTest("compiler/testData/codegen/boxWasmJsInterop/vararg.kt"); runTest("compiler/testData/codegen/boxWasmJsInterop/vararg.kt");
} }
@Nested
@TestMetadata("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations")
@TestDataPath("$PROJECT_ROOT")
public class TypeScriptDeclarations {
@Test
public void testAllFilesPresentInTypeScriptDeclarations() {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
}
} }
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -9,7 +9,6 @@ import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil; import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TargetBackend; import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata; import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
@@ -108,14 +107,4 @@ public class IrCodegenWasmJsInteropJsTestGenerated extends AbstractIrCodegenWasm
public void testVararg() { public void testVararg() {
runTest("compiler/testData/codegen/boxWasmJsInterop/vararg.kt"); runTest("compiler/testData/codegen/boxWasmJsInterop/vararg.kt");
} }
@Nested
@TestMetadata("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations")
@TestDataPath("$PROJECT_ROOT")
public class TypeScriptDeclarations {
@Test
public void testAllFilesPresentInTypeScriptDeclarations() {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
}
} }
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,4 +0,0 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -1,3 +0,0 @@
{
"extends": "../common.tsconfig.json"
}
@@ -1,3 +0,0 @@
{
"extends": "../common.tsconfig.json"
}
@@ -1,3 +0,0 @@
{
"extends": "../common.tsconfig.json"
}
@@ -1,3 +0,0 @@
{
"extends": "../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"strict": true,
"newLine": "lf",
"lib": ["es2015", "dom"]
}
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../../common.tsconfig.json"
}

Some files were not shown because too many files have changed in this diff Show More