Promise-based async integration test for kotlin-test-js
This commit is contained in:
@@ -33,7 +33,7 @@ node {
|
||||
|
||||
def createFrameworkTest(def name) {
|
||||
return tasks.create("test$name", NpmTask) {
|
||||
dependsOn(compileKotlin2Js, populateNodeModules, npmInstall)
|
||||
dependsOn(compileTestKotlin2Js, populateNodeModules, npmInstall)
|
||||
def lowerName = name.toLowerCase()
|
||||
args = ['run', "test-$lowerName"]
|
||||
group = 'verification'
|
||||
|
||||
@@ -3,6 +3,9 @@ module.exports = {
|
||||
'SimpleTest testBar': 'pass',
|
||||
'SimpleTest testFooWrong': 'pending',
|
||||
'TestTest emptyTest': 'pending',
|
||||
'AsyncTest checkAsyncOrder': 'pass',
|
||||
'AsyncTest asyncPassing': 'pass',
|
||||
'AsyncTest asyncFailing': 'fail',
|
||||
'org OrgTest test': 'pass',
|
||||
'org.some SomeTest someIsBetterThanNothing': 'pass',
|
||||
'org.some.name NameTest test': 'pass',
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
var Tester = require('./test-result-checker');
|
||||
var tester = new Tester(require('./expected-outcomes'), 'qunit');
|
||||
|
||||
var full = require('./expected-outcomes');
|
||||
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) {
|
||||
var testName = (details.module.replace('> ', '') + ' ' + details.name).trim();
|
||||
|
||||
@@ -6,15 +6,15 @@ var Tester = require('./test-result-checker');
|
||||
// Tape doesn't report pending tests.
|
||||
// See https://github.com/substack/tape/pull/197 and https://github.com/substack/tape/issues/90
|
||||
var full = require('./expected-outcomes');
|
||||
var noPending = {};
|
||||
var noPendingAndAsyncPass = {};
|
||||
for (var name in full) {
|
||||
var result = full[name];
|
||||
if (result !== 'pending') {
|
||||
noPending[name] = result;
|
||||
noPendingAndAsyncPass[name] = name.startsWith('AsyncTest ') ? 'pass' : result;
|
||||
}
|
||||
}
|
||||
|
||||
var tester = new Tester(noPending, 'tape');
|
||||
var tester = new Tester(noPendingAndAsyncPass, 'tape');
|
||||
|
||||
process.on('exit', function () {
|
||||
tester.end();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import kotlin.js.Promise
|
||||
import kotlin.test.*
|
||||
|
||||
var value = 5
|
||||
@@ -30,4 +31,43 @@ class SimpleTest {
|
||||
class TestTest {
|
||||
@Test fun emptyTest() {
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncTest {
|
||||
|
||||
var log = ""
|
||||
|
||||
@BeforeTest
|
||||
fun before() {
|
||||
log = ""
|
||||
}
|
||||
|
||||
fun promise(v: Int) = Promise<Int> { resolve, reject ->
|
||||
log += "a"
|
||||
js("setTimeout")({ log += "c"; resolve(v) }, 100)
|
||||
log += "b"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun checkAsyncOrder(): Promise<Unit> {
|
||||
log += 1
|
||||
|
||||
val p1 = promise(10)
|
||||
|
||||
log += 2
|
||||
|
||||
val p2 = p1.then { result ->
|
||||
assertEquals(log, "1ab23c")
|
||||
}
|
||||
|
||||
log += 3
|
||||
|
||||
return p2
|
||||
}
|
||||
|
||||
@Test
|
||||
fun asyncPassing() = promise(10).then { assertEquals(10, it) }
|
||||
|
||||
@Test
|
||||
fun asyncFailing() = promise(20).then { assertEquals(10, it) }
|
||||
}
|
||||
Reference in New Issue
Block a user