Skip to content

Commit

Permalink
Fix k/js tests (#842)
Browse files Browse the repository at this point in the history
* Fix k/js tests

Make resources reachable in tests

* Move k/js CI action configuration to web.yml

* Refactor our internal test API

---------

Co-authored-by: Oleksandr.Karpovich <[email protected]>
  • Loading branch information
eymar and Oleksandr.Karpovich authored Dec 11, 2023
1 parent c3dfcce commit f4c5a4e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 75 deletions.
50 changes: 0 additions & 50 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,56 +169,6 @@ jobs:
path: ./skiko/build/reports/tests
retention-days: 5

js:
runs-on: ubuntu-20.04
if: false # see wasm.yml
steps:
- uses: actions/checkout@v3
name: 'Check out code'

- uses: actions/setup-java@v3
name: 'Set up JDK 11'
with:
distribution: 'adopt'
java-version: '11'
cache: 'gradle'

- shell: bash
name: 'Set up JS build environment'
run: |
cd ./skiko
sudo apt-get update -y
sudo apt-get install binutils build-essential -y
sudo apt-get install software-properties-common -y
sudo apt-get install python git curl wget -y
if [ -d ./emsdk ]; then
cd ./emsdk
git pull
else
git clone https://github.com/emscripten-core/emsdk.git
cd ./emsdk
fi
./emsdk install 3.1.49
./emsdk activate 3.1.49
- shell: bash
name: 'Compile and run JS tests'
run: |
source "$(pwd)/skiko/emsdk/emsdk_env.sh"
./gradlew --stacktrace --info -Pskiko.wasm.enabled=true -Pskiko.test.onci=true :skiko:jsTest
- shell: bash
name: 'Publish WASM runtime to Maven Local'
run: |
source "$(pwd)/skiko/emsdk/emsdk_env.sh"
./gradlew --stacktrace --info -Pskiko.wasm.enabled=true :skiko:publishSkikoWasmRuntimePublicationToMavenLocal
- uses: actions/upload-artifact@v3
name: 'Save test results as artifact'
if: always()
with:
name: test-reports-js
path: ./skiko/build/reports/tests
retention-days: 5

windows:
runs-on: windows-2019
steps:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/wasm.yml → .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ jobs:
./emsdk activate 3.1.49
source ./emsdk_env.sh
cd ..
- name: 'run tests'
- name: 'run k/wasm tests'
shell: bash
run: |
cd ./skiko
source ./emsdk/emsdk_env.sh
./gradlew --stacktrace --info -Pskiko.wasm.enabled=true -Pskiko.js.enabled=true -Pskiko.test.onci=true wasmJsTest
./gradlew --stacktrace --info -Pskiko.wasm.enabled=true -Pskiko.js.enabled=true publishSkikoWasmRuntimePublicationToMavenLocal
- name: 'run k/js tests'
shell: bash
run: |
cd ./skiko
source ./emsdk/emsdk_env.sh
./gradlew --stacktrace --info -Pskiko.wasm.enabled=true -Pskiko.js.enabled=true -Pskiko.test.onci=true jsTest
- uses: actions/upload-artifact@v2
if: always()
with:
Expand Down
8 changes: 7 additions & 1 deletion skiko/karma.config.d/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ debug(`karma wasmPath: ${wasmPath}`);
debug(`karma generatedAssetsPath: ${generatedAssetsPath}`);

config.proxies = {
"/wasm/": wasmPath
"/wasm/": wasmPath,
"/resources": path.resolve(basePath, "kotlin"),
}

config.webpack.output = Object.assign(config.webpack.output || {}, {
Expand All @@ -42,4 +43,9 @@ config.files = [
path.resolve(wasmPath, "skiko.js"),
{pattern: path.resolve(wasmPath, "skiko.wasm"), included: false, served: true, watched: false},
{pattern: path.resolve(generatedAssetsPath, "**/*"), included: false, served: true, watched: false},
{pattern: path.resolve(basePath, "kotlin", "**/*.png"), included: false, served: true, watched: false},
{pattern: path.resolve(basePath, "kotlin", "**/*.gif"), included: false, served: true, watched: false},
{pattern: path.resolve(basePath, "kotlin", "**/*.ttf"), included: false, served: true, watched: false},
{pattern: path.resolve(basePath, "kotlin", "**/*.txt"), included: false, served: true, watched: false},
{pattern: path.resolve(basePath, "kotlin", "**/*.json"), included: false, served: true, watched: false},
].concat(config.files);
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import org.jetbrains.skia.Data
import org.jetbrains.skia.impl.InteropScope
import org.jetbrains.skia.impl.NativePointer

expect fun <T> runTest(block: suspend () -> Unit): T
expect class TestReturnType

expect fun runTest(block: suspend () -> Unit): TestReturnType

internal expect fun InteropScope.allocateBytesForPixels(size: Int): NativePointer

Expand Down
3 changes: 1 addition & 2 deletions skiko/src/jsTest/kotlin/org/jetbrains/skiko/resourcePath.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package org.jetbrains.skiko

@JsName("require")
actual external fun resourcePath(resourceId: String): String
actual fun resourcePath(resourceId: String): String = "resources/" + resourceId
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@ private suspend fun <T> Promise<T>.await(): T = suspendCoroutine { cont ->
then({ cont.resume(it) }, { cont.resumeWithException(it) })
}

actual typealias TestReturnType = Any
/**
* Awaits for `wasmSetup` and then runs the [block] in a coroutine.
*/
actual fun <T> runTest(block: suspend () -> Unit): dynamic = MainScope().promise {
error("It's a fake actual. Not expected to be called")
}

fun runTest(block: suspend () -> Unit): dynamic = MainScope().promise {
actual fun runTest(block: suspend () -> Unit): TestReturnType = MainScope().promise {
wasmSetup.await()
block()
}

actual typealias SkipJsTarget = kotlin.test.Ignore

actual annotation class SkipWasmTarget

actual annotation class SkipWasmTarget
6 changes: 2 additions & 4 deletions skiko/src/jvmTest/kotlin/TestUtils.jvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import org.jetbrains.skia.impl.NativePointer
import org.jetbrains.skia.makeFromFileName
import java.nio.ByteBuffer

actual fun <T> runTest(block: suspend () -> Unit): T {
error("It's a fake actual. Not expected to be called")
}
actual typealias TestReturnType = Unit

fun runTest(block: suspend () -> Unit): Unit {
actual fun runTest(block: suspend () -> Unit): TestReturnType {
return runBlocking { block() }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import org.jetbrains.skia.impl.InteropScope
import org.jetbrains.skia.impl.NativePointer
import org.jetbrains.skia.makeFromFileName

actual fun <T> runTest(block: suspend () -> Unit): T {
error("It's a fake actual. Not expected to be called")
}
actual typealias TestReturnType = Unit

fun runTest(block: suspend () -> Unit): Unit {
actual fun runTest(block: suspend () -> Unit): TestReturnType {
return runBlocking { block() }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ actual typealias SkipWasmTarget = kotlin.test.Ignore
@JsFun("() => ''")
private external fun jsRef(): JsAny


actual typealias TestReturnType = Any
/**
* Runs the [block] in a coroutine.
*/
actual fun <T> runTest(block: suspend () -> Unit): T {
error("It's a fake actual. Not expected to be called")
}

fun runTest(block: suspend () -> Unit): Any = MainScope().promise {
actual fun runTest(block: suspend () -> Unit): TestReturnType = MainScope().promise {
block()
jsRef()
}

0 comments on commit f4c5a4e

Please sign in to comment.