Skip to content

Commit 510e1d4

Browse files
authored
use esm for js export (#154)
1 parent ecc1c2d commit 510e1d4

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ kotlin {
4747
js(IR) {
4848
browser { testTask { useMocha { timeout = "10min" } } }
4949
nodejs { testTask { useMocha { timeout = "10min" } } }
50-
50+
useEsModules()
5151
binaries.library()
5252
generateTypeScriptDefinitions()
5353
}

src/jsTest/kotlin/co/pokeapi/pokekotlin/test/LiveJsTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package co.pokeapi.pokekotlin.test
22

33
import co.pokeapi.pokekotlin.PokeApi
4-
import io.ktor.client.plugins.*
5-
import io.ktor.http.*
4+
import io.ktor.client.plugins.ClientRequestException
5+
import io.ktor.http.HttpStatusCode
66
import kotlin.js.Promise
77
import kotlin.test.Test
88
import kotlin.test.assertEquals
@@ -12,12 +12,12 @@ import kotlinx.coroutines.test.runTest
1212

1313
@Suppress("UnusedVariable", "unused")
1414
class LiveJsTest {
15-
private val client: PokeApi =
16-
js("require('./pokekotlin.js').co.pokeapi.pokekotlin.PokeApi.Default")
15+
private val client: Promise<PokeApi> =
16+
js("import('./pokekotlin.mjs').then(function (it) { return it.PokeApi.Default; })")
1717

1818
@Test
1919
fun resource() = runTest {
20-
val client = client
20+
val client = client.await()
2121
assertEquals(
2222
"sitrus",
2323
js("client.getBerryAsync(10).then(function (it) { return it.name; })")
@@ -28,7 +28,7 @@ class LiveJsTest {
2828

2929
@Test
3030
fun list() = runTest {
31-
val client = client
31+
val client = client.await()
3232

3333
val berry1 =
3434
js("client.getBerryListAsync(0, 10).then(function (it) { return it.results[5]; })")
@@ -45,7 +45,7 @@ class LiveJsTest {
4545

4646
@Test
4747
fun notFound() = runTest {
48-
val client = client
48+
val client = client.await()
4949

5050
val exception =
5151
assertFailsWith<ClientRequestException> {

0 commit comments

Comments
 (0)