Skip to content

Commit d2bf738

Browse files
committed
Fix actual typealias TestResult = Promise<Unit>
1 parent 12ec16c commit d2bf738

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

kotlinx-coroutines-core/js/test/TestBase.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ public actual val isStressTest: Boolean = false
1010
public actual val stressTestMultiplier: Int = 1
1111
public actual val stressTestMultiplierSqrt: Int = 1
1212

13-
@Suppress("ACTUAL_WITHOUT_EXPECT", "ACTUAL_TYPE_ALIAS_TO_CLASS_WITH_DECLARATION_SITE_VARIANCE")
14-
public actual typealias TestResult = Promise<Unit>
13+
@JsName("Promise")
14+
external class MyPromise {
15+
fun then(onFulfilled: ((Unit) -> Unit), onRejected: ((Throwable) -> Unit)): MyPromise
16+
fun then(onFulfilled: ((Unit) -> Unit)): MyPromise
17+
}
18+
19+
/** Always a `Promise<Unit>` */
20+
public actual typealias TestResult = MyPromise
1521

1622
public actual val isNative = false
1723

@@ -135,7 +141,7 @@ public actual open class TestBase actual constructor() {
135141
check(actionIndex == 0 || finished) { "Expecting that 'finish(...)' was invoked, but it was not" }
136142
}
137143
lastTestPromise = result
138-
return result
144+
return result as MyPromise
139145
}
140146
}
141147

kotlinx-coroutines-test/common/test/TestDispatchersTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class TestDispatchersTest: OrderedExecutionTestBase() {
2222

2323
/** Tests that asynchronous execution of tests does not happen concurrently with [AfterTest]. */
2424
@Test
25+
@NoJs // doesn't work because of KT-63359
2526
fun testMainMocking() = runTest {
2627
val mainAtStart = TestMainDispatcher.currentTestDispatcher
2728
assertNotNull(mainAtStart)

kotlinx-coroutines-test/js/src/TestBuilders.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
*/
44

55
package kotlinx.coroutines.test
6+
67
import kotlinx.coroutines.*
7-
import kotlin.js.*
8+
import kotlinx.coroutines.test.internal.*
89

9-
@Suppress("ACTUAL_WITHOUT_EXPECT", "ACTUAL_TYPE_ALIAS_TO_CLASS_WITH_DECLARATION_SITE_VARIANCE")
10-
public actual typealias TestResult = Promise<Unit>
10+
public actual typealias TestResult = JsPromiseInterfaceForTesting
1111

1212
internal actual fun createTestResult(testProcedure: suspend CoroutineScope.() -> Unit): TestResult =
1313
GlobalScope.promise {
1414
testProcedure()
15-
}
15+
} as JsPromiseInterfaceForTesting
1616

17-
internal actual fun dumpCoroutines() { }
17+
internal actual fun dumpCoroutines() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.coroutines.test.internal
6+
7+
/* This is a declaration of JS's `Promise<Unit>`. We need to keep it a separate class, because
8+
`actual typealias TestResult = Promise<Unit>` fails: you can't instantiate an `expect class` with a typealias to
9+
a parametric class. So, we make a non-parametric class just for this. */
10+
/**
11+
* @suppress
12+
*/
13+
@JsName("Promise")
14+
public external class JsPromiseInterfaceForTesting {
15+
/**
16+
* @suppress
17+
*/
18+
public fun then(onFulfilled: ((Unit) -> Unit), onRejected: ((Throwable) -> Unit)): JsPromiseInterfaceForTesting
19+
/**
20+
* @suppress
21+
*/
22+
public fun then(onFulfilled: ((Unit) -> Unit)): JsPromiseInterfaceForTesting
23+
}

0 commit comments

Comments
 (0)