Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix k/js tests #842

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}