kotlin-test-js: pass test function result to test framework (e.g. Promise)

This commit is contained in:
Anton Bannykh
2017-12-27 16:23:10 +03:00
parent 3e0d83b7d1
commit 2df85ae4a9
4 changed files with 93 additions and 7 deletions
+6 -2
View File
@@ -15,8 +15,8 @@ val underscore = kotlin.test.setAdapter(object : FrameworkAdapter {
context.suite(name, ignored) { suiteFn() }
}
override fun test(name: String, ignored: Boolean, testFn: () -> Unit) {
context.test(name, ignored) { testFn() }
override fun test(name: String, ignored: Boolean, testFn: () -> dynamic) {
context.test(name, ignored) { returned(testFn()) }
}
})
@@ -58,6 +58,10 @@ class TestContext {
record("caught(\"$msg\")")
}
fun returned(msg: dynamic) = indent {
if (msg is String) record("returned(\"$msg\")")
}
private fun (TestContext.() -> Unit).runSafely() {
try {
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")
}
}
}