mike.holler
11/08/2022, 4:53 PMError: Timeout of 15000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
Here is my runTest { ... }
function:
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.promise
val testScope = MainScope()
val testCoroutineContext = testScope.coroutineContext
actual fun runTest(
block: suspend (scope: CoroutineScope) -> Unit
): dynamic = testScope.promise(
start = CoroutineStart.UNDISPATCHED,
context = testCoroutineContext,
) {
block(this)
}
And a simple test to verify:
class SimpleTest {
@Test fun testShortDelay() = runTest { delay(10_000) } // passes
@Test fun testLongDelay() = runTest { delay(15_001) } // fails (I want it to pass)
}
Does anybody know what I should change in runTest
to get testLongDelay
and testShortDelay
to both pass? I've tried a number of things and nothing seems to work.nschulzke
11/08/2022, 5:12 PMtestShortDelay
actually take 10 seconds to execute? If so, that's your problem, because `delay`s are supposed to be skipped within runTest
.mike.holler
11/08/2022, 5:14 PMnschulzke
11/08/2022, 5:16 PMrunTest
because JS doesn't have one built in?mike.holler
11/08/2022, 5:16 PMmike.holler
11/08/2022, 5:17 PMnschulzke
11/08/2022, 5:19 PMcommon
, the jvm version is deprecated and just calls the common version.mike.holler
11/08/2022, 5:19 PMnschulzke
11/08/2022, 5:19 PM* On JS, this function creates a `Promise` that executes the test body with the delay-skipping behavior.
mike.holler
11/08/2022, 5:19 PMmike.holler
11/08/2022, 5:20 PMnschulzke
11/08/2022, 5:20 PMmike.holler
11/08/2022, 5:20 PMmike.holler
11/08/2022, 5:21 PMmike.holler
11/08/2022, 5:21 PMnschulzke
11/08/2022, 5:21 PMnschulzke
11/08/2022, 5:21 PMmike.holler
11/08/2022, 5:23 PMmike.holler
11/08/2022, 5:32 PMmike.holler
11/08/2022, 6:22 PM/**
* See [kotlinxRunTest] for more details.
*/
@OptIn(ExperimentalCoroutinesApi::class)
fun runTest(
dispatchTimeoutMs: Long = DEFAULT_TIMEOUT_MS,
block: suspend (scope: CoroutineScope) -> Unit
): TestResult {
return kotlinxRunTest(dispatchTimeoutMs = dispatchTimeoutMs) {
withContext(Dispatchers.Default) {
block(this@withContext)
}
}
}
mike.holler
11/08/2022, 6:23 PMtestLongDelay
still fails for the same reason 😞mike.holler
11/08/2022, 6:23 PMmike.holler
11/08/2022, 6:24 PMmike.holler
11/08/2022, 6:34 PM@Test
fun testLongDelay() = kotlinx.coroutines.test.runTest (dispatchTimeoutMs = 16000) {
withContext(Dispatchers.Default) {
withTimeout(16000) {
delay(15001)
}
}
}
mike.holler
11/08/2022, 6:34 PMError: Timeout of 15000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
Error: Timeout of 15000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
at <global>.listOnTimeout(node:internal/timers:557)
at <global>.processTimers(node:internal/timers:500)
andylamax
11/09/2022, 7:22 AMandylamax
11/09/2022, 7:25 AMkarma.config.d
folder that is in the same leve as your build.gradle(.kts)
and inside create a js file (I call mine timeout.js
) and set your timeout like so
config.set({
"client": {
"mocha": {
"timeout": 15000
},
},
"browserDisconnectTimeout": 15000
});
andylamax
11/09/2022, 7:26 AM