kotlin-test-js: pass test function result to test framework (e.g. Promise)
This commit is contained in:
@@ -5924,6 +5924,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("returnTestResult.kt")
|
||||||
|
public void testReturnTestResult() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/kotlin.test/returnTestResult.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("simple.kt")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/kotlin.test/simple.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/kotlin.test/simple.kt");
|
||||||
|
|||||||
@@ -104,15 +104,18 @@ class JSTestGenerator(val context: TranslationContext) {
|
|||||||
|
|
||||||
val classVal = innerContext.defineTemporary(classDescriptor.instance(innerContext))
|
val classVal = innerContext.defineTemporary(classDescriptor.instance(innerContext))
|
||||||
|
|
||||||
fun FunctionDescriptor.buildCall() = CallTranslator.buildCall(context, this, emptyList(), classVal).makeStmt()
|
fun FunctionDescriptor.buildCall() = CallTranslator.buildCall(context, this, emptyList(), classVal)
|
||||||
|
|
||||||
functionToTest.body.statements += beforeDescriptors.map { it.buildCall() }
|
functionToTest.body.statements += beforeDescriptors.map { it.buildCall().makeStmt() }
|
||||||
|
|
||||||
functionToTest.body.statements += if (afterDescriptors.isEmpty()) {
|
if (afterDescriptors.isEmpty()) {
|
||||||
functionDescriptor.buildCall()
|
functionToTest.body.statements += JsReturn(functionDescriptor.buildCall())
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JsTry(JsBlock(functionDescriptor.buildCall()), listOf(), JsBlock(afterDescriptors.map { it.buildCall() }))
|
functionToTest.body.statements += JsTry(
|
||||||
|
JsBlock(JsReturn(functionDescriptor.buildCall())),
|
||||||
|
listOf(),
|
||||||
|
JsBlock(afterDescriptors.map { it.buildCall().makeStmt() }))
|
||||||
}
|
}
|
||||||
|
|
||||||
return functionToTest
|
return functionToTest
|
||||||
|
|||||||
+6
-2
@@ -15,8 +15,8 @@ val underscore = kotlin.test.setAdapter(object : FrameworkAdapter {
|
|||||||
context.suite(name, ignored) { suiteFn() }
|
context.suite(name, ignored) { suiteFn() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun test(name: String, ignored: Boolean, testFn: () -> Unit) {
|
override fun test(name: String, ignored: Boolean, testFn: () -> dynamic) {
|
||||||
context.test(name, ignored) { testFn() }
|
context.test(name, ignored) { returned(testFn()) }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -58,6 +58,10 @@ class TestContext {
|
|||||||
record("caught(\"$msg\")")
|
record("caught(\"$msg\")")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun returned(msg: dynamic) = indent {
|
||||||
|
if (msg is String) record("returned(\"$msg\")")
|
||||||
|
}
|
||||||
|
|
||||||
private fun (TestContext.() -> Unit).runSafely() {
|
private fun (TestContext.() -> Unit).runSafely() {
|
||||||
try {
|
try {
|
||||||
this()
|
this()
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
// EXPECTED_REACHABLE_NODES: 1178
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.BeforeTest
|
||||||
|
import kotlin.test.AfterTest
|
||||||
|
|
||||||
|
open class A {
|
||||||
|
@Test fun foo(): String {
|
||||||
|
return "promise"
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun bar() = "future"
|
||||||
|
}
|
||||||
|
|
||||||
|
interface WithBefore {
|
||||||
|
@BeforeTest fun before() {
|
||||||
|
call("before")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface WithAfter {
|
||||||
|
@AfterTest fun after() {
|
||||||
|
call("after")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B: A(), WithBefore
|
||||||
|
|
||||||
|
class C: A(), WithAfter
|
||||||
|
|
||||||
|
class D: A(), WithBefore, WithAfter
|
||||||
|
|
||||||
|
fun box() = checkLog {
|
||||||
|
suite("A") {
|
||||||
|
test("foo") {
|
||||||
|
returned("promise")
|
||||||
|
}
|
||||||
|
test("bar") {
|
||||||
|
returned("future")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
suite("B") {
|
||||||
|
test("foo") {
|
||||||
|
call("before")
|
||||||
|
returned("promise")
|
||||||
|
}
|
||||||
|
test("bar") {
|
||||||
|
call("before")
|
||||||
|
returned("future")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
suite("C") {
|
||||||
|
test("foo") {
|
||||||
|
call("after")
|
||||||
|
returned("promise")
|
||||||
|
}
|
||||||
|
test("bar") {
|
||||||
|
call("after")
|
||||||
|
returned("future")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
suite("D") {
|
||||||
|
test("foo") {
|
||||||
|
call("before")
|
||||||
|
call("after")
|
||||||
|
returned("promise")
|
||||||
|
}
|
||||||
|
test("bar") {
|
||||||
|
call("before")
|
||||||
|
call("after")
|
||||||
|
returned("future")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user