https://kotlinlang.org logo
#kotest
Title
# kotest
r

rocketraman

11/09/2023, 3:42 PM
Using kotest, this test fails on JavaScript with Kotlin 1.9.20 with a
TypeError
, but note if
mapOf
is changed to
listOf
it works. Also note, if I use
kotlin.test
instead of kotest, the test passes as well. This is clearly a bug somewhere, but I'm trying to figure out whether its a kotlin/js bug, or whether its a kotest bug. Thoughts? More details in 🧵. Here is a repo to play with locally: https://github.com/rocketraman/test-kt-duration-in-map
Copy code
class DurationKoTest : FunSpec({
  test("Duration in map") {
    val tests = mapOf(
      15.seconds to 0L,
    )

    tests.forEach { (input, output) ->
      input.toLong(DurationUnit.DAYS) shouldBe output
    }
  }
})
Incidentally, it fails with the k2 compiler as well, in exactly the same way
And here is the error:
Copy code
TypeError: _get_rawValue__5zfu4e(...).shr_9fl3wl_k$ is not a function
	at <global>._get_value__a43j40(/home/raman/source/test-kt-duration-in-map/compileSync/js/test/testDevelopmentExecutable/kotlin/src/kotlin/time/Duration.kt:37)
	at <global>.Duration__toLong_impl_shr43i(/home/raman/source/test-kt-duration-in-map/compileSync/js/test/testDevelopmentExecutable/kotlin/src/kotlin/time/Duration.kt:789)
	at protoOf.doResume_5yljmg(/home/raman/source/test-kt-duration-in-map/src/commonTest/kotlin/DurationKotest.kt:13)
	at protoOf.invoke_s5vbtx(test-kt-duration-in-map-test.934710764.js:71230)
	at slambda.$test(test-kt-duration-in-map-test.934710764.js:71272)
	at protoOf.doResume_5yljmg(/runner/work/kotest/kotest/kotest-framework/kotest-framework-api/src/commonMain/kotlin/io/kotest/core/spec/style/scopes/RootScope.kt:36)
	at protoOf.invoke_s5vbtx(test-kt-duration-in-map-test.934710764.js:10912)
	at <global>.l(test-kt-duration-in-map-test.934710764.js:10959)
	at protoOf.doResume_5yljmg(/runner/work/kotest/kotest/kotest-framework/kotest-framework-engine/src/commonMain/kotlin/io/kotest/engine/test/TestCaseExecutor.kt:91)
	at protoOf.invoke_peurmw(test-kt-duration-in-map-test.934710764.js:28107)
c

Casey Brooks

11/09/2023, 4:19 PM
It also seems to work fine when run in the Playground https://pl.kotl.in/aSU4yVRrM Also, it seems like the test break when the
Map.Entry
is destructured, but works fine if you access the key/value properties normally
Copy code
// this works
tests.forEach {
    val input = it.key
    val output = it.value
    input.toLong(DurationUnit.DAYS) shouldBe output
}

// this fails with the same error
tests.forEach { 
    val (input, output) = it
    input.toLong(DurationUnit.DAYS) shouldBe output
}
👍 1
Is Kotest 5.8.0 used in the sample repo compiled with Kotlin 1.9.20? That might be the source of the issue, if it’s using a different version of the Kotlin stdlib
r

rocketraman

11/09/2023, 4:26 PM
I believe its 1.8.10
Using 1.8.10 in the repo above works -- the test passes. I guess its not a bug then -- as I understand it, Kotlin/JS does not yet offer compat between versions. Scary failure mode though.
c

Casey Brooks

11/09/2023, 4:31 PM
Yeah, I think JS is the only target which doesn’t really have any real ABI guarantees yet, and you basically need all libraries on the same minor version. Native uses its own klib format, and JVM has classfiles, which I guess are much easier to maintain binary compatibility for than compiled JS
5 Views