diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf6eb2b24..323723828 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/.github/workflows/wasm.yml b/.github/workflows/web.yml similarity index 87% rename from .github/workflows/wasm.yml rename to .github/workflows/web.yml index cacb32fa8..3d0785a1a 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/web.yml @@ -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: diff --git a/skiko/karma.config.d/js/config.js b/skiko/karma.config.d/js/config.js index e2165cc8f..712559a9e 100644 --- a/skiko/karma.config.d/js/config.js +++ b/skiko/karma.config.d/js/config.js @@ -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 || {}, { @@ -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); diff --git a/skiko/src/commonTest/kotlin/org/jetbrains/skiko/tests/TestUtils.kt b/skiko/src/commonTest/kotlin/org/jetbrains/skiko/tests/TestUtils.kt index 0cf1c67f0..b09b7d0cd 100644 --- a/skiko/src/commonTest/kotlin/org/jetbrains/skiko/tests/TestUtils.kt +++ b/skiko/src/commonTest/kotlin/org/jetbrains/skiko/tests/TestUtils.kt @@ -4,7 +4,9 @@ import org.jetbrains.skia.Data import org.jetbrains.skia.impl.InteropScope import org.jetbrains.skia.impl.NativePointer -expect fun runTest(block: suspend () -> Unit): T +expect class TestReturnType + +expect fun runTest(block: suspend () -> Unit): TestReturnType internal expect fun InteropScope.allocateBytesForPixels(size: Int): NativePointer diff --git a/skiko/src/jsTest/kotlin/org/jetbrains/skiko/resourcePath.kt b/skiko/src/jsTest/kotlin/org/jetbrains/skiko/resourcePath.kt index 99f18d2f0..c812a451c 100644 --- a/skiko/src/jsTest/kotlin/org/jetbrains/skiko/resourcePath.kt +++ b/skiko/src/jsTest/kotlin/org/jetbrains/skiko/resourcePath.kt @@ -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 diff --git a/skiko/src/jsTest/kotlin/org/jetbrains/skiko/tests/TestUtils.js.kt b/skiko/src/jsTest/kotlin/org/jetbrains/skiko/tests/TestUtils.js.kt index 088e21320..e2df0ea2c 100644 --- a/skiko/src/jsTest/kotlin/org/jetbrains/skiko/tests/TestUtils.js.kt +++ b/skiko/src/jsTest/kotlin/org/jetbrains/skiko/tests/TestUtils.js.kt @@ -15,19 +15,15 @@ private suspend fun Promise.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 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 \ No newline at end of file diff --git a/skiko/src/jvmTest/kotlin/TestUtils.jvm.kt b/skiko/src/jvmTest/kotlin/TestUtils.jvm.kt index c0e2b52c5..aff5718f6 100644 --- a/skiko/src/jvmTest/kotlin/TestUtils.jvm.kt +++ b/skiko/src/jvmTest/kotlin/TestUtils.jvm.kt @@ -8,11 +8,9 @@ import org.jetbrains.skia.impl.NativePointer import org.jetbrains.skia.makeFromFileName import java.nio.ByteBuffer -actual fun 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() } } diff --git a/skiko/src/nativeTest/kotlin/org/jetbrains/skiko/tests/TestUtils.native.kt b/skiko/src/nativeTest/kotlin/org/jetbrains/skiko/tests/TestUtils.native.kt index 099e067d6..db4b82667 100644 --- a/skiko/src/nativeTest/kotlin/org/jetbrains/skiko/tests/TestUtils.native.kt +++ b/skiko/src/nativeTest/kotlin/org/jetbrains/skiko/tests/TestUtils.native.kt @@ -6,11 +6,9 @@ import org.jetbrains.skia.impl.InteropScope import org.jetbrains.skia.impl.NativePointer import org.jetbrains.skia.makeFromFileName -actual fun 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() } } diff --git a/skiko/src/wasmJsTest/kotlin/org/jetbrains/skiko/tests/TestUtils.wasm.kt b/skiko/src/wasmJsTest/kotlin/org/jetbrains/skiko/tests/TestUtils.wasm.kt index 6754478a9..57a2e810d 100644 --- a/skiko/src/wasmJsTest/kotlin/org/jetbrains/skiko/tests/TestUtils.wasm.kt +++ b/skiko/src/wasmJsTest/kotlin/org/jetbrains/skiko/tests/TestUtils.wasm.kt @@ -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 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() }