Unverified Commit f4c5a4ec authored by Oleksandr Karpovich's avatar Oleksandr Karpovich Committed by GitHub

Fix k/js tests (#842)

* 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: 's avatarOleksandr.Karpovich <oleksandr.karpovich@jetbrains.com>
parent c3dfcce6
...@@ -169,56 +169,6 @@ jobs: ...@@ -169,56 +169,6 @@ jobs:
path: ./skiko/build/reports/tests path: ./skiko/build/reports/tests
retention-days: 5 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: windows:
runs-on: windows-2019 runs-on: windows-2019
steps: steps:
......
...@@ -47,13 +47,19 @@ jobs: ...@@ -47,13 +47,19 @@ jobs:
./emsdk activate 3.1.49 ./emsdk activate 3.1.49
source ./emsdk_env.sh source ./emsdk_env.sh
cd .. cd ..
- name: 'run tests' - name: 'run k/wasm tests'
shell: bash shell: bash
run: | run: |
cd ./skiko cd ./skiko
source ./emsdk/emsdk_env.sh 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 -Pskiko.test.onci=true wasmJsTest
./gradlew --stacktrace --info -Pskiko.wasm.enabled=true -Pskiko.js.enabled=true publishSkikoWasmRuntimePublicationToMavenLocal ./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 - uses: actions/upload-artifact@v2
if: always() if: always()
with: with:
......
...@@ -16,7 +16,8 @@ debug(`karma wasmPath: ${wasmPath}`); ...@@ -16,7 +16,8 @@ debug(`karma wasmPath: ${wasmPath}`);
debug(`karma generatedAssetsPath: ${generatedAssetsPath}`); debug(`karma generatedAssetsPath: ${generatedAssetsPath}`);
config.proxies = { config.proxies = {
"/wasm/": wasmPath "/wasm/": wasmPath,
"/resources": path.resolve(basePath, "kotlin"),
} }
config.webpack.output = Object.assign(config.webpack.output || {}, { config.webpack.output = Object.assign(config.webpack.output || {}, {
...@@ -42,4 +43,9 @@ config.files = [ ...@@ -42,4 +43,9 @@ config.files = [
path.resolve(wasmPath, "skiko.js"), path.resolve(wasmPath, "skiko.js"),
{pattern: path.resolve(wasmPath, "skiko.wasm"), included: false, served: true, watched: false}, {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(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); ].concat(config.files);
...@@ -4,7 +4,9 @@ import org.jetbrains.skia.Data ...@@ -4,7 +4,9 @@ import org.jetbrains.skia.Data
import org.jetbrains.skia.impl.InteropScope import org.jetbrains.skia.impl.InteropScope
import org.jetbrains.skia.impl.NativePointer 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 internal expect fun InteropScope.allocateBytesForPixels(size: Int): NativePointer
......
package org.jetbrains.skiko package org.jetbrains.skiko
@JsName("require") actual fun resourcePath(resourceId: String): String = "resources/" + resourceId
actual external fun resourcePath(resourceId: String): String
...@@ -15,14 +15,11 @@ private suspend fun <T> Promise<T>.await(): T = suspendCoroutine { cont -> ...@@ -15,14 +15,11 @@ private suspend fun <T> Promise<T>.await(): T = suspendCoroutine { cont ->
then({ cont.resume(it) }, { cont.resumeWithException(it) }) then({ cont.resume(it) }, { cont.resumeWithException(it) })
} }
actual typealias TestReturnType = Any
/** /**
* Awaits for `wasmSetup` and then runs the [block] in a coroutine. * Awaits for `wasmSetup` and then runs the [block] in a coroutine.
*/ */
actual fun <T> runTest(block: suspend () -> Unit): dynamic = MainScope().promise { actual fun runTest(block: suspend () -> Unit): TestReturnType = MainScope().promise {
error("It's a fake actual. Not expected to be called")
}
fun runTest(block: suspend () -> Unit): dynamic = MainScope().promise {
wasmSetup.await() wasmSetup.await()
block() block()
} }
...@@ -30,4 +27,3 @@ fun runTest(block: suspend () -> Unit): dynamic = MainScope().promise { ...@@ -30,4 +27,3 @@ fun runTest(block: suspend () -> Unit): dynamic = MainScope().promise {
actual typealias SkipJsTarget = kotlin.test.Ignore actual typealias SkipJsTarget = kotlin.test.Ignore
actual annotation class SkipWasmTarget actual annotation class SkipWasmTarget
\ No newline at end of file
...@@ -8,11 +8,9 @@ import org.jetbrains.skia.impl.NativePointer ...@@ -8,11 +8,9 @@ import org.jetbrains.skia.impl.NativePointer
import org.jetbrains.skia.makeFromFileName import org.jetbrains.skia.makeFromFileName
import java.nio.ByteBuffer import java.nio.ByteBuffer
actual fun <T> runTest(block: suspend () -> Unit): T { actual typealias TestReturnType = Unit
error("It's a fake actual. Not expected to be called")
}
fun runTest(block: suspend () -> Unit): Unit { actual fun runTest(block: suspend () -> Unit): TestReturnType {
return runBlocking { block() } return runBlocking { block() }
} }
......
...@@ -6,11 +6,9 @@ import org.jetbrains.skia.impl.InteropScope ...@@ -6,11 +6,9 @@ import org.jetbrains.skia.impl.InteropScope
import org.jetbrains.skia.impl.NativePointer import org.jetbrains.skia.impl.NativePointer
import org.jetbrains.skia.makeFromFileName import org.jetbrains.skia.makeFromFileName
actual fun <T> runTest(block: suspend () -> Unit): T { actual typealias TestReturnType = Unit
error("It's a fake actual. Not expected to be called")
}
fun runTest(block: suspend () -> Unit): Unit { actual fun runTest(block: suspend () -> Unit): TestReturnType {
return runBlocking { block() } return runBlocking { block() }
} }
......
...@@ -10,14 +10,12 @@ actual typealias SkipWasmTarget = kotlin.test.Ignore ...@@ -10,14 +10,12 @@ actual typealias SkipWasmTarget = kotlin.test.Ignore
@JsFun("() => ''") @JsFun("() => ''")
private external fun jsRef(): JsAny private external fun jsRef(): JsAny
actual typealias TestReturnType = Any
/** /**
* Runs the [block] in a coroutine. * Runs the [block] in a coroutine.
*/ */
actual fun <T> runTest(block: suspend () -> Unit): T { actual fun runTest(block: suspend () -> Unit): TestReturnType = MainScope().promise {
error("It's a fake actual. Not expected to be called")
}
fun runTest(block: suspend () -> Unit): Any = MainScope().promise {
block() block()
jsRef() jsRef()
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment