I’m using the “js” plugin with the “nodejs” configuration, just to build a utility app. Things are mostly working, but one issue I’ve encountered is that I can’t write async tests — normally with Mocha/Jest etc a test can be written as an async function, or take a
done
parameter, but the JS produced by the Kotlin/JS compiler from inspecting the test sources seems to preclude that:
Copy code
test('resolve_gradle', false, function () {
var tmp$;
tmp$ = new VersionResolversTest();
tmp$.beforeTest();
try {
return tmp$.resolve_gradle();
}finally {
tmp$.afterTest();
}
});
(
beforeTest
and
afterTest
here were methods annotated with
@BeforeTest
and
@AfterTest
)
Is this output configurable in any way?
r
Rob Murdock
03/19/2020, 2:43 PM
I’m seeing no one’s gotten back to you - the way the kotlin test package is set up, you can return promises from your test cases technically (I’ve been exploiting this in my own code), but last time i played with it, it didn’t work in before + after functions.
Rob Murdock
03/19/2020, 2:44 PM
happy to chat about it if you still need help
a
araqnid
03/19/2020, 4:51 PM
That makes sense, actually, the return value from the test is passed up, so returning a promise should work. I think my eyes slipped over that last time I looked…
araqnid
03/19/2020, 4:55 PM
Ah, yes, if I make the test return a promise and delay for over 2 seconds, it gets caught by the timeout, so clearly it’s working. Just before/after aren’t, which is a shame.
araqnid
03/19/2020, 4:56 PM
Thanks for the reply 🙂 I’m just writing tests like this:
Copy code
@Test
fun some_async_test() = GlobalScope.promise {
println("this is an async test")
delay(1500L)
println("it's finishing after a delay")
}