KT-22807: allow asynchronous testing in Kotlin/JS with QUnit
This commit is contained in:
@@ -1,12 +1,6 @@
|
|||||||
var Tester = require('./test-result-checker');
|
var Tester = require('./test-result-checker');
|
||||||
|
var expectedOutcomes = require('./expected-outcomes');
|
||||||
var full = require('./expected-outcomes');
|
var tester = new Tester(expectedOutcomes, 'qunit');
|
||||||
var allAsyncPass = {};
|
|
||||||
for (var name in full) {
|
|
||||||
allAsyncPass[name] = name.startsWith('AsyncTest ') ? 'pass' : full[name];
|
|
||||||
}
|
|
||||||
|
|
||||||
var tester = new Tester(allAsyncPass, 'qunit');
|
|
||||||
|
|
||||||
QUnit.testDone(function (details) {
|
QUnit.testDone(function (details) {
|
||||||
var testName = (details.module.replace('> ', '') + ' ' + details.name).trim();
|
var testName = (details.module.replace('> ', '') + ' ' + details.name).trim();
|
||||||
|
|||||||
@@ -38,5 +38,5 @@ public external interface FrameworkAdapter {
|
|||||||
* @param ignored whether the test is ignored
|
* @param ignored whether the test is ignored
|
||||||
* @param testFn contains test body invocation
|
* @param testFn contains test body invocation
|
||||||
*/
|
*/
|
||||||
fun test(name: String, ignored: Boolean, testFn: () -> Unit)
|
fun test(name: String, ignored: Boolean, testFn: () -> Any)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ internal open class BareAdapter : FrameworkAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun test(name: String, ignored: Boolean, testFn: () -> Unit) {
|
override fun test(name: String, ignored: Boolean, testFn: () -> Any) {
|
||||||
if (!ignored) {
|
if (!ignored) {
|
||||||
testFn()
|
testFn()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ package kotlin.test.adapters
|
|||||||
*/
|
*/
|
||||||
internal external object QUnit {
|
internal external object QUnit {
|
||||||
fun module(name: String, suiteFn: () -> Unit): Unit
|
fun module(name: String, suiteFn: () -> Unit): Unit
|
||||||
fun test(name: String, testFn: (dynamic) -> Unit): Unit
|
fun test(name: String, testFn: (dynamic) -> Any): Unit
|
||||||
fun skip(name: String, testFn: (dynamic) -> Unit): Unit
|
fun skip(name: String, testFn: (dynamic) -> Any): Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -20,8 +20,8 @@ internal external object QUnit {
|
|||||||
|
|
||||||
internal external fun describe(name: String, fn: () -> Unit)
|
internal external fun describe(name: String, fn: () -> Unit)
|
||||||
internal external fun xdescribe(name: String, fn: () -> Unit)
|
internal external fun xdescribe(name: String, fn: () -> Unit)
|
||||||
internal external fun it(name: String, fn: () -> Unit)
|
internal external fun it(name: String, fn: () -> Any)
|
||||||
internal external fun xit(name: String, fn: () -> Unit)
|
internal external fun xit(name: String, fn: () -> Any)
|
||||||
|
|
||||||
internal fun isQUnit() = jsTypeOf(QUnit) !== "undefined"
|
internal fun isQUnit() = jsTypeOf(QUnit) !== "undefined"
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ internal class JasmineLikeAdapter : FrameworkAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun test(name: String, ignored: Boolean, testFn: () -> Unit) {
|
override fun test(name: String, ignored: Boolean, testFn: () -> Any) {
|
||||||
if (ignored) {
|
if (ignored) {
|
||||||
xit(name, testFn)
|
xit(name, testFn)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ internal class QUnitAdapter : FrameworkAdapter {
|
|||||||
ignoredSuite = prevIgnore
|
ignoredSuite = prevIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun test(name: String, ignored: Boolean, testFn: () -> Unit) {
|
override fun test(name: String, ignored: Boolean, testFn: () -> Any) {
|
||||||
if (ignored or ignoredSuite) {
|
if (ignored or ignoredSuite) {
|
||||||
QUnit.skip(name, wrapTest(testFn))
|
QUnit.skip(name, wrapTest(testFn))
|
||||||
} else {
|
} else {
|
||||||
@@ -30,15 +30,16 @@ internal class QUnitAdapter : FrameworkAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun wrapTest(testFn: () -> Unit): (dynamic) -> Unit = { assert ->
|
private fun wrapTest(testFn: () -> Any): (dynamic) -> Any = { assert ->
|
||||||
var assertionsHappened = false
|
var assertionsHappened = false
|
||||||
assertHook = { testResult ->
|
assertHook = { testResult ->
|
||||||
assertionsHappened = true
|
assertionsHappened = true
|
||||||
assert.ok(testResult.result, testResult.lazyMessage())
|
assert.ok(testResult.result, testResult.lazyMessage())
|
||||||
}
|
}
|
||||||
testFn()
|
val possiblePromise = testFn()
|
||||||
if (!assertionsHappened) {
|
if (!assertionsHappened) {
|
||||||
assertTrue(true, "A test with no assertions is considered successful")
|
assertTrue(true, "A test with no assertions is considered successful")
|
||||||
}
|
}
|
||||||
|
possiblePromise
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user