Promise-based async integration test for kotlin-test-js
This commit is contained in:
@@ -33,7 +33,7 @@ node {
|
|||||||
|
|
||||||
def createFrameworkTest(def name) {
|
def createFrameworkTest(def name) {
|
||||||
return tasks.create("test$name", NpmTask) {
|
return tasks.create("test$name", NpmTask) {
|
||||||
dependsOn(compileKotlin2Js, populateNodeModules, npmInstall)
|
dependsOn(compileTestKotlin2Js, populateNodeModules, npmInstall)
|
||||||
def lowerName = name.toLowerCase()
|
def lowerName = name.toLowerCase()
|
||||||
args = ['run', "test-$lowerName"]
|
args = ['run', "test-$lowerName"]
|
||||||
group = 'verification'
|
group = 'verification'
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ module.exports = {
|
|||||||
'SimpleTest testBar': 'pass',
|
'SimpleTest testBar': 'pass',
|
||||||
'SimpleTest testFooWrong': 'pending',
|
'SimpleTest testFooWrong': 'pending',
|
||||||
'TestTest emptyTest': 'pending',
|
'TestTest emptyTest': 'pending',
|
||||||
|
'AsyncTest checkAsyncOrder': 'pass',
|
||||||
|
'AsyncTest asyncPassing': 'pass',
|
||||||
|
'AsyncTest asyncFailing': 'fail',
|
||||||
'org OrgTest test': 'pass',
|
'org OrgTest test': 'pass',
|
||||||
'org.some SomeTest someIsBetterThanNothing': 'pass',
|
'org.some SomeTest someIsBetterThanNothing': 'pass',
|
||||||
'org.some.name NameTest test': 'pass',
|
'org.some.name NameTest test': 'pass',
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
var Tester = require('./test-result-checker');
|
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) {
|
QUnit.testDone(function (details) {
|
||||||
var testName = (details.module.replace('> ', '') + ' ' + details.name).trim();
|
var testName = (details.module.replace('> ', '') + ' ' + details.name).trim();
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ var Tester = require('./test-result-checker');
|
|||||||
// Tape doesn't report pending tests.
|
// Tape doesn't report pending tests.
|
||||||
// See https://github.com/substack/tape/pull/197 and https://github.com/substack/tape/issues/90
|
// See https://github.com/substack/tape/pull/197 and https://github.com/substack/tape/issues/90
|
||||||
var full = require('./expected-outcomes');
|
var full = require('./expected-outcomes');
|
||||||
var noPending = {};
|
var noPendingAndAsyncPass = {};
|
||||||
for (var name in full) {
|
for (var name in full) {
|
||||||
var result = full[name];
|
var result = full[name];
|
||||||
if (result !== 'pending') {
|
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 () {
|
process.on('exit', function () {
|
||||||
tester.end();
|
tester.end();
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import kotlin.js.Promise
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
var value = 5
|
var value = 5
|
||||||
@@ -31,3 +32,42 @@ class TestTest {
|
|||||||
@Test fun emptyTest() {
|
@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