diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e48865..94193aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## development +- support wasm target ## version 0.0.5 - update Kotlin to 1.9.22 diff --git a/adhan/build.gradle.kts b/adhan/build.gradle.kts index 42c3da7..c778dab 100644 --- a/adhan/build.gradle.kts +++ b/adhan/build.gradle.kts @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest @@ -27,6 +28,17 @@ kotlin { } } + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + nodejs { + testTask { + useMocha { + timeout = "30s" + } + } + } + } + linuxX64() linuxArm64() mingwX64() @@ -53,10 +65,11 @@ kotlin { val commonTest by getting { dependencies { + implementation(kotlin("test")) implementation(kotlin("test-common")) implementation(kotlin("test-annotations-common")) api("com.squareup.okio:okio:3.8.0") - implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2") } } @@ -75,6 +88,12 @@ kotlin { implementation(npm("@js-joda/timezone", "2.3.0")) } } + + val wasmJsTest by getting { + dependencies { + implementation(npm("@js-joda/timezone", "2.3.0")) + } + } } // set an environment variable and read it in the test @@ -187,6 +206,12 @@ publishing { } } +// for wasm to be able to run tests +with(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin.apply(rootProject)) { + nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2" + nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary" +} + // auto replace yarn.lock rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin::class.java) { rootProject.the().yarnLockMismatchReport = diff --git a/adhan/src/commonTest/kotlin/com/batoulapps/adhan2/TestUtil.kt b/adhan/src/commonTest/kotlin/com/batoulapps/adhan2/TestUtil.kt index 85a8622..1d968c1 100644 --- a/adhan/src/commonTest/kotlin/com/batoulapps/adhan2/TestUtil.kt +++ b/adhan/src/commonTest/kotlin/com/batoulapps/adhan2/TestUtil.kt @@ -3,6 +3,6 @@ package com.batoulapps.adhan2 import okio.FileSystem expect class TestUtil() { - fun fileSystem(): FileSystem + fun fileSystem(): FileSystem? fun environmentVariable(name: String): String? } \ No newline at end of file diff --git a/adhan/src/commonTest/kotlin/com/batoulapps/adhan2/TimingTest.kt b/adhan/src/commonTest/kotlin/com/batoulapps/adhan2/TimingTest.kt index 93fbb8d..a3cb2fe 100644 --- a/adhan/src/commonTest/kotlin/com/batoulapps/adhan2/TimingTest.kt +++ b/adhan/src/commonTest/kotlin/com/batoulapps/adhan2/TimingTest.kt @@ -29,7 +29,6 @@ import kotlinx.datetime.LocalDateTime import kotlinx.datetime.TimeZone import kotlinx.datetime.toInstant import kotlinx.datetime.toLocalDateTime -import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import okio.Path.Companion.toPath @@ -41,7 +40,10 @@ class TimingTest { val testUtil = TestUtil() val root = (testUtil.environmentVariable("ADHAN_ROOT") ?: "").toPath() - val fs = testUtil.fileSystem() + + // disable time verification tests for platforms without filesystem support + // currently, this is just wasm + val fs = testUtil.fileSystem() ?: return val jsonPath = root.resolve("Shared/Times/") assertTrue(fs.exists(jsonPath), "Json Path Does not Exist: $jsonPath") diff --git a/adhan/src/jsTest/kotlin/com/batoulapps/adhan2/TestUtil.kt b/adhan/src/jsTest/kotlin/com/batoulapps/adhan2/TestUtil.js.kt similarity index 86% rename from adhan/src/jsTest/kotlin/com/batoulapps/adhan2/TestUtil.kt rename to adhan/src/jsTest/kotlin/com/batoulapps/adhan2/TestUtil.js.kt index 901adb1..97b39fb 100644 --- a/adhan/src/jsTest/kotlin/com/batoulapps/adhan2/TestUtil.kt +++ b/adhan/src/jsTest/kotlin/com/batoulapps/adhan2/TestUtil.js.kt @@ -10,6 +10,6 @@ external object JsJodaTimeZoneModule private val jsJodaTz = JsJodaTimeZoneModule actual class TestUtil actual constructor() { - actual fun fileSystem(): FileSystem = NodeJsFileSystem + actual fun fileSystem(): FileSystem? = NodeJsFileSystem actual fun environmentVariable(name: String): String? = js("globalThis.process.env[name]") as String? } \ No newline at end of file diff --git a/adhan/src/jvmTest/kotlin/com/batoulapps/adhan2/TestUtil.kt b/adhan/src/jvmTest/kotlin/com/batoulapps/adhan2/TestUtil.jvm.kt similarity index 75% rename from adhan/src/jvmTest/kotlin/com/batoulapps/adhan2/TestUtil.kt rename to adhan/src/jvmTest/kotlin/com/batoulapps/adhan2/TestUtil.jvm.kt index 698d30e..a747ab6 100644 --- a/adhan/src/jvmTest/kotlin/com/batoulapps/adhan2/TestUtil.kt +++ b/adhan/src/jvmTest/kotlin/com/batoulapps/adhan2/TestUtil.jvm.kt @@ -3,6 +3,6 @@ package com.batoulapps.adhan2 import okio.FileSystem actual class TestUtil actual constructor() { - actual fun fileSystem(): FileSystem = FileSystem.SYSTEM + actual fun fileSystem(): FileSystem? = FileSystem.SYSTEM actual fun environmentVariable(name: String): String? = System.getenv(name) } \ No newline at end of file diff --git a/adhan/src/nativeTest/kotlin/com/batoulapps/adhan2/TestUtil.kt b/adhan/src/nativeTest/kotlin/com/batoulapps/adhan2/TestUtil.native.kt similarity index 84% rename from adhan/src/nativeTest/kotlin/com/batoulapps/adhan2/TestUtil.kt rename to adhan/src/nativeTest/kotlin/com/batoulapps/adhan2/TestUtil.native.kt index 69be32d..d176960 100644 --- a/adhan/src/nativeTest/kotlin/com/batoulapps/adhan2/TestUtil.kt +++ b/adhan/src/nativeTest/kotlin/com/batoulapps/adhan2/TestUtil.native.kt @@ -7,6 +7,6 @@ import platform.posix.getenv @OptIn(ExperimentalForeignApi::class) actual class TestUtil actual constructor() { - actual fun fileSystem(): FileSystem = FileSystem.SYSTEM + actual fun fileSystem(): FileSystem? = FileSystem.SYSTEM actual fun environmentVariable(name: String): String? = getenv(name)?.toKString() } \ No newline at end of file diff --git a/adhan/src/wasmJsTest/kotlin/com/batoulapps/adhan2/TestUtil.wasmJs.kt b/adhan/src/wasmJsTest/kotlin/com/batoulapps/adhan2/TestUtil.wasmJs.kt new file mode 100644 index 0000000..6a16fa4 --- /dev/null +++ b/adhan/src/wasmJsTest/kotlin/com/batoulapps/adhan2/TestUtil.wasmJs.kt @@ -0,0 +1,13 @@ +package com.batoulapps.adhan2 + +import okio.FileSystem + +@JsModule("@js-joda/timezone") +external object JsJodaTimeZoneModule + +private val jsJodaTz = JsJodaTimeZoneModule + +actual class TestUtil actual constructor() { + actual fun fileSystem(): FileSystem? = null + actual fun environmentVariable(name: String): String? = null +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 31b0508..3526fd5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,3 +13,10 @@ allprojects { mavenCentral() } } + +// Disable NPM to NodeJS nightly compatibility check. +// Drop this when NodeJs version that supports latest Wasm become stable +// Required so wasm tests can run +tasks.withType().configureEach { + args.add("--ignore-engines") +} \ No newline at end of file