-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from dokar3/dokar/improve-execute-pending-job
Improve the calling of executePendingJob
- Loading branch information
Showing
3 changed files
with
103 additions
and
24 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
quickjs/src/commonTest/kotlin/com/dokar/quickjs/test/JsPromiseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.dokar.quickjs.test | ||
|
||
import com.dokar.quickjs.binding.function | ||
import com.dokar.quickjs.quickJs | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class JsPromiseTest { | ||
@Test | ||
fun asyncFunction() = runTest { | ||
quickJs { | ||
val result = evaluate<Int>( | ||
""" | ||
async function add(a, b) { | ||
return a + b; | ||
} | ||
await add(1, 2) | ||
""".trimIndent() | ||
) | ||
assertEquals(3, result) | ||
} | ||
} | ||
|
||
@Test | ||
fun promise() = runTest { | ||
quickJs { | ||
val result = evaluate<Int>( | ||
""" | ||
await new Promise((resolve) => resolve(1)) | ||
.then((result) => result + 1) | ||
""".trimIndent() | ||
) | ||
assertEquals(2, result) | ||
} | ||
} | ||
|
||
@Test | ||
fun promiseDotAll() = runTest { | ||
quickJs { | ||
val result = evaluate<List<*>>( | ||
""" | ||
async function add(a, b) { | ||
return a + b; | ||
} | ||
await Promise.all([add(1, 2), add(3, 4)]) | ||
""".trimIndent() | ||
) | ||
assertEquals(listOf(3L, 7L), result) | ||
} | ||
} | ||
|
||
@Test | ||
fun promiseWithoutAwait() = runTest { | ||
quickJs { | ||
val logs = mutableListOf<String>() | ||
|
||
function<String, Unit>("log") { logs += it } | ||
|
||
evaluate<Any?>( | ||
""" | ||
log("Start"); | ||
new Promise((resolve) => resolve()) | ||
.then(() => log("Then")); | ||
log("End"); | ||
""".trimIndent() | ||
) | ||
|
||
assertEquals(listOf("Start", "End", "Then"), logs) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters