rra/ilgonmic/after-test-promise
[JS] Node downloading for js ir integration kotlin test [JS] Fix API of Promise [JS IR] Promise symbol as lazy2 [JS] Support legacy compiler aftertest with promises [JS IR] Generate finally for promised tests [JS] Setup it tests for JS IR kotlin-test Merge-request: KT-MR-5168 ^KT-49738 fixed
This commit is contained in:
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
@@ -0,0 +1,127 @@
|
||||
import com.moowork.gradle.node.npm.NpmTask
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
|
||||
import java.io.FileOutputStream
|
||||
|
||||
plugins {
|
||||
kotlin("js")
|
||||
id("com.github.node-gradle.node") version "2.2.0"
|
||||
}
|
||||
|
||||
description = "Kotlin-test integration tests for JS IR"
|
||||
|
||||
node {
|
||||
version = "16.13.0"
|
||||
download = true
|
||||
}
|
||||
|
||||
val jsMainSources by task<Sync> {
|
||||
from("$rootDir/libraries/kotlin.test/js/it/src")
|
||||
into("$buildDir/jsMainSources")
|
||||
}
|
||||
|
||||
val jsSources by task<Sync> {
|
||||
from("$rootDir/libraries/kotlin.test/js/it/js")
|
||||
into("$buildDir/jsSources")
|
||||
}
|
||||
|
||||
val ignoreTestFailures by extra(project.kotlinBuildProperties.ignoreTestFailures)
|
||||
|
||||
kotlin {
|
||||
js(IR) {
|
||||
nodejs {
|
||||
testTask {
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val test by getting {
|
||||
kotlin.srcDir(jsMainSources.get().destinationDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val nodeModules by configurations.registering {
|
||||
extendsFrom(configurations["api"])
|
||||
attributes {
|
||||
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage::class.java, KotlinUsages.KOTLIN_RUNTIME))
|
||||
attribute(KotlinPlatformType.attribute, KotlinPlatformType.js)
|
||||
}
|
||||
}
|
||||
|
||||
val compileTestDevelopmentExecutableKotlinJs = tasks.named<KotlinJsIrLink>("compileTestDevelopmentExecutableKotlinJs")
|
||||
|
||||
val populateNodeModules = tasks.register<Copy>("populateNodeModules") {
|
||||
dependsOn("compileTestDevelopmentExecutableKotlinJs")
|
||||
dependsOn(nodeModules)
|
||||
from(compileTestDevelopmentExecutableKotlinJs.map { it.destinationDir })
|
||||
|
||||
from {
|
||||
nodeModules.get().map {
|
||||
// WORKAROUND: Some JS IR jars were absent and caused this task to fail.
|
||||
// They don't contain .js thus we can skip them.
|
||||
if (it.exists()) {
|
||||
zipTree(it.absolutePath).matching { include("*.js") }
|
||||
} else it
|
||||
}
|
||||
}
|
||||
|
||||
into("${buildDir}/node_modules")
|
||||
}
|
||||
|
||||
fun createFrameworkTest(name: String): TaskProvider<NpmTask> {
|
||||
return tasks.register("test$name", NpmTask::class.java) {
|
||||
dependsOn(compileTestDevelopmentExecutableKotlinJs, populateNodeModules, "npmInstall")
|
||||
val lowerName = name.toLowerCase()
|
||||
val tcOutput = "$buildDir/tc-${lowerName}.log"
|
||||
val stdOutput = "$buildDir/test-${lowerName}.log"
|
||||
val errOutput = "$buildDir/test-${lowerName}.err.log"
|
||||
// inputs.files(sourceSets.test.output)
|
||||
inputs.dir("${buildDir}/node_modules")
|
||||
outputs.files(tcOutput, stdOutput, errOutput)
|
||||
|
||||
setArgs(listOf("run", "test-$lowerName"))
|
||||
// args("run")
|
||||
// args("test-$lowerName")
|
||||
group = "verification"
|
||||
|
||||
setExecOverrides(closureOf<ExecSpec> {
|
||||
isIgnoreExitValue = true
|
||||
standardOutput = FileOutputStream(stdOutput)
|
||||
errorOutput = FileOutputStream(errOutput)
|
||||
})
|
||||
doLast {
|
||||
println(file(tcOutput).readText())
|
||||
if (result.exitValue != 0/* && !rootProject.ignoreTestFailures*/) {
|
||||
throw GradleException("$name integration test failed")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val frameworkTests = listOf(
|
||||
// "Jest",
|
||||
"Jasmine",
|
||||
"Mocha",
|
||||
"Qunit",
|
||||
// "Tape"
|
||||
).map {
|
||||
createFrameworkTest(it)
|
||||
}
|
||||
|
||||
tasks.check {
|
||||
frameworkTests.forEach { dependsOn(it) }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":kotlin-test:kotlin-test-js-ir"))
|
||||
}
|
||||
|
||||
tasks.named("compileTestKotlinJs") {
|
||||
dependsOn(jsMainSources)
|
||||
dependsOn(jsSources)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"scripts": {
|
||||
"test-jasmine": "jasmine build/jsSources/jasmine-reporter.js build/compileSync/test/testDevelopmentExecutable/kotlin/kotlin-kotlin-test-js-ir-it-test.js",
|
||||
"test-jest": "jest",
|
||||
"test-mocha": "mocha --reporter build/jsSources/mocha-reporter.js build/compileSync/test/testDevelopmentExecutable/kotlin/kotlin-kotlin-test-js-ir-it-test.js",
|
||||
"test-qunit": "qunit -c build/jsSources/qunit-reporter.js -t build/compileSync/test/testDevelopmentExecutable/kotlin/kotlin-kotlin-test-js-ir-it-test.js",
|
||||
"test-tape": "tape build/jsSources/tape-reporter.js build/jsSources/tape-plugin.js build/compileSync/test/testDevelopmentExecutable/kotlin/kotlin-kotlin-test-js-ir-it-test.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jasmine": "^2.9.0",
|
||||
"jest": "^20.0.4",
|
||||
"mocha": "^3.4.2",
|
||||
"qunit": "^1.0.0",
|
||||
"tape": "~4.10.0"
|
||||
},
|
||||
"jest": {
|
||||
"testResultsProcessor": "<rootDir>/build/jsSources/jest-reporter.js",
|
||||
"testRegex": "-test\\.js$"
|
||||
}
|
||||
}
|
||||
@@ -44,14 +44,22 @@ class AsyncTest {
|
||||
|
||||
var log = ""
|
||||
|
||||
var afterLog = ""
|
||||
|
||||
@BeforeTest
|
||||
fun before() {
|
||||
log = ""
|
||||
}
|
||||
|
||||
// Until bootstrap update
|
||||
@AfterTest
|
||||
fun after() {
|
||||
// assertEquals(afterLog, "after")
|
||||
}
|
||||
|
||||
fun promise(v: Int) = Promise<Int> { resolve, reject ->
|
||||
log += "a"
|
||||
js("setTimeout")({ log += "c"; resolve(v) }, 100)
|
||||
js("setTimeout")({ log += "c"; afterLog += "after"; resolve(v) }, 100)
|
||||
log += "b"
|
||||
}
|
||||
|
||||
|
||||
@@ -283,6 +283,8 @@ public open external class Promise<out T> {
|
||||
|
||||
public open fun <S> catch(onRejected: (kotlin.Throwable) -> S): kotlin.js.Promise<S>
|
||||
|
||||
public open fun finally(onFinally: () -> kotlin.Unit): kotlin.js.Promise<T>
|
||||
|
||||
@kotlin.internal.LowPriorityInOverloadResolution
|
||||
public open fun <S> then(onFulfilled: ((T) -> S)?): kotlin.js.Promise<S>
|
||||
|
||||
|
||||
@@ -282,6 +282,8 @@ public open external class Promise<out T> {
|
||||
|
||||
public open fun <S> catch(onRejected: (kotlin.Throwable) -> S): kotlin.js.Promise<S>
|
||||
|
||||
public open fun finally(onFinally: () -> kotlin.Unit): kotlin.js.Promise<T>
|
||||
|
||||
@kotlin.internal.LowPriorityInOverloadResolution
|
||||
public open fun <S> then(onFulfilled: ((T) -> S)?): kotlin.js.Promise<S>
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ public open external class Promise<out T>(executor: (resolve: (T) -> Unit, rejec
|
||||
|
||||
public open fun <S> catch(onRejected: (Throwable) -> S): Promise<S>
|
||||
|
||||
public open fun finally(onFinally: () -> Unit): Promise<T>
|
||||
|
||||
companion object {
|
||||
public fun <S> all(promise: Array<out Promise<S>>): Promise<Array<out S>>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user