Skip to content

Commit 0a7a7f1

Browse files
committed
Fix actual typealias TestResult = Promise<Unit>
1 parent 6ceda56 commit 0a7a7f1

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

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

+9-3
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

@@ -131,7 +137,7 @@ public actual open class TestBase actual constructor() {
131137
check(actionIndex == 0 || finished) { "Expecting that 'finish(...)' was invoked, but it was not" }
132138
}
133139
lastTestPromise = result
134-
return result
140+
return result as MyPromise
135141
}
136142
}
137143

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

+5-5
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() {}
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)