Skip to content

Commit

Permalink
Merge pull request #37 from fleeksoft/kotlinx-io
Browse files Browse the repository at this point in the history
add support for wasmjs with nodejs
  • Loading branch information
itboy87 authored Jul 25, 2024
2 parents 32c9218 + 41b0aa7 commit 347d57b
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
config: [
{ target: android, os: ubuntu-latest, tasks: testDebugUnitTest testReleaseUnitTest, continueOnError: false },
{ target: apple, os: macos-latest, tasks: iosX64Test iosSimulatorArm64Test macosX64Test macosArm64Test tvosX64Test tvosSimulatorArm64Test watchosX64Test watchosSimulatorArm64Test, continueOnError: false },
{ target: nodejs, os: ubuntu-latest, tasks: jsNodeTest, continueOnError: false },
{ target: js, os: ubuntu-latest, tasks: jsTest wasmJsTest, continueOnError: false },
{ target: desktop, os: ubuntu-latest, tasks: jvmTest, continueOnError: false },
{ target: windows, os: windows-latest, tasks: mingwX64Test, continueOnError: false },
]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ To report any issues, visit our [GitHub issues](https://github.com/fleeksoft/kso
| JS | Alpha | Does not support few charsets. |
| Native MacOS | Alpha | |
| Native Windows | Experimental | Does not support gzip file. |
| Wasm | Coming Soon | |
| WasmJs | Experimental | Does not support gzip file. |



Expand Down
4 changes: 4 additions & 0 deletions ksoup-network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ kotlin {
nodejs()
}

wasmJs {
nodejs()
}

linuxX64()
linuxArm64()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.fleeksoft.ksoup.network

import io.ktor.client.engine.*
import io.ktor.client.engine.js.*

internal actual fun provideHttpClientEngine(): HttpClientEngine {
return Js.create()
}
4 changes: 4 additions & 0 deletions ksoup/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ kotlin {
nodejs()
}

wasmJs {
nodejs()
}

linuxX64()
linuxArm64()

Expand Down
4 changes: 3 additions & 1 deletion ksoup/src/commonMain/kotlin/com/fleeksoft/ksoup/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum class PlatformType {
IOS,
LINUX,
JS,
WASM,
WASM_JS,
MAC,
WINDOWS,
}
Expand All @@ -43,3 +43,5 @@ public fun Platform.isJvmOrAndroid(): Boolean = this.current == PlatformType.JVM
public fun Platform.isJvm(): Boolean = this.current == PlatformType.JVM

public fun Platform.isJS(): Boolean = this.current == PlatformType.JS

public fun Platform.isWasmJs(): Boolean = this.current == PlatformType.WASM_JS
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlin.test.assertEquals
class GzipTest {
@Test
fun testReadGzipFile() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class DataUtilTest {
@Test
@Throws(Exception::class)
fun secondMetaElementWithContentTypeContainsCharsetParameter() {
if (Platform.isJS() || Platform.isApple() || Platform.isWindows()) {
if (Platform.isJS() || Platform.isApple() || Platform.isWindows() || Platform.isWasmJs()) {
// FIXME: euc-kr charset not supported
return
}
Expand Down Expand Up @@ -175,7 +175,7 @@ class DataUtilTest {

@Test
fun supportsBOMinFiles() {
if (Platform.isJS() || Platform.isWindows() || Platform.isApple()) {
if (Platform.isJS() || Platform.isWindows() || Platform.isApple() || Platform.isWasmJs()) {
// FIXME: utf-16 charset not supported
// FIXME: failing for iosX64˚
return
Expand Down Expand Up @@ -219,7 +219,7 @@ class DataUtilTest {

@Test
fun supportsZippedUTF8BOM() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand Down Expand Up @@ -260,7 +260,7 @@ class DataUtilTest {

@Test
fun lLoadsGzipFile() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand All @@ -273,7 +273,7 @@ class DataUtilTest {

@Test
fun loadsZGzipFile() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand All @@ -286,7 +286,7 @@ class DataUtilTest {

@Test
fun handlesFakeGzipFile() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand All @@ -298,7 +298,7 @@ class DataUtilTest {

@Test
fun handlesChunkedInputStream() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand All @@ -314,7 +314,7 @@ class DataUtilTest {

@Test
fun handlesUnlimitedRead() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import kotlin.test.assertTrue
class ParseTest {
@Test
fun testHtml5Charset() {
if (Platform.isJS() || Platform.isApple() || Platform.isWindows()) {
if (Platform.isJS() || Platform.isApple() || Platform.isWindows() || Platform.isWasmJs()) {
// FIXME: gb2312 charset not supported
return
}
Expand Down Expand Up @@ -86,7 +86,7 @@ class ParseTest {

@Test
fun testXwiki() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand All @@ -110,7 +110,7 @@ class ParseTest {

@Test
fun testXwikiExpanded() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand Down Expand Up @@ -139,7 +139,7 @@ class ParseTest {

@Test
fun testWikiExpandedFromString() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand All @@ -154,7 +154,7 @@ class ParseTest {

@Test
fun testWikiFromString() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand All @@ -169,7 +169,7 @@ class ParseTest {

@Test
fun testFileParseNoCharsetMethod() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import com.fleeksoft.ksoup.Ksoup
import com.fleeksoft.ksoup.Platform
import com.fleeksoft.ksoup.TestHelper
import com.fleeksoft.ksoup.isWindows
import com.fleeksoft.ksoup.*
import com.fleeksoft.ksoup.nodes.Document
import com.fleeksoft.ksoup.select.Elements
import kotlin.io.encoding.Base64
Expand All @@ -16,7 +13,7 @@ class GithubIssue19 {

@Test
fun testAttributeIncorrectMixCharsetIssue() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.fleeksoft.ksoup.issues

import com.fleeksoft.ksoup.Ksoup
import com.fleeksoft.ksoup.Platform
import com.fleeksoft.ksoup.TestHelper
import com.fleeksoft.ksoup.isWindows
import com.fleeksoft.ksoup.*
import kotlinx.coroutines.test.runTest
import kotlinx.io.files.Path
import kotlin.test.Test
Expand All @@ -12,7 +9,7 @@ import kotlin.test.assertEquals
class GithubIssuesTests {
@Test
fun testIssue20DuplicateElements() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class DocumentTest {

@Test
fun testOverflowClone() {
if (Platform.isJS()) {
if (Platform.isJS() || Platform.isWasmJs()) {
// FIXME: timeout error for js
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import com.fleeksoft.ksoup.BuildConfig
import com.fleeksoft.ksoup.Ksoup.parse
import com.fleeksoft.ksoup.Platform
import com.fleeksoft.ksoup.isJS
import com.fleeksoft.ksoup.isWasmJs
import com.fleeksoft.ksoup.ported.System
import kotlin.test.*
import kotlin.test.Test

class ElementIT {
@Test
fun testFastReparent() {
if (Platform.isJS() && BuildConfig.isGithubActions) {
if ((Platform.isJS() || Platform.isWasmJs()) && BuildConfig.isGithubActions) {
// failing on github action
return
}
Expand Down Expand Up @@ -44,7 +45,7 @@ class ElementIT {

@Test
fun testFastReparentExistingContent() {
if (Platform.isJS() && BuildConfig.isGithubActions) {
if ((Platform.isJS() || Platform.isWasmJs()) && BuildConfig.isGithubActions) {
// failing on github action
return
}
Expand Down Expand Up @@ -83,7 +84,7 @@ class ElementIT {
// These overflow tests take a couple seconds to run, so are in the slow tests
@Test
fun hasTextNoOverflow() {
if (Platform.isJS()) {
if (Platform.isJS() || Platform.isWasmJs()) {
// FIXME: timeout error for js
return
}
Expand All @@ -102,7 +103,7 @@ class ElementIT {

@Test
fun dataNoOverflow() {
if (Platform.isJS()) {
if (Platform.isJS() || Platform.isWasmJs()) {
// FIXME: timeout error for js
return
}
Expand All @@ -122,7 +123,7 @@ class ElementIT {

@Test
fun parentsNoOverflow() {
if (Platform.isJS()) {
if (Platform.isJS() || Platform.isWasmJs()) {
// FIXME: timeout error for js
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ class CharacterReaderTest {

@Test
fun linenumbersAgreeWithEditor() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ class HtmlParserTest {
}
assertEquals("One", doc.text())
val html = doc.outerHtml()
if (Platform.isJS() || Platform.isApple() || Platform.isWindows()) {
if (Platform.isJS() || Platform.isApple() || Platform.isWindows() || Platform.isWasmJs()) {
// ISO-2022-CN not supported so it will use UTF-8 by default
assertEquals(
"<html><head><meta charset=\"ISO-2022-CN\"></head><body>One</body></html>",
Expand All @@ -1592,7 +1592,7 @@ class HtmlParserTest {

@Test
fun characterReaderBuffer() {
if (Platform.isWindows()) {
if (Platform.isWindows() || Platform.isWasmJs()) {
// gzip not supported yet
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class BufferReaderTest {

@Test
fun testSpecialCharsBufferReader() {
if (Platform.isJS() || Platform.isApple()) {
if (Platform.isJS() || Platform.isApple() || Platform.isWasmJs()) {
// FIXME: euc-kr charset not supported
return
}
Expand Down
13 changes: 13 additions & 0 deletions ksoup/src/wasmJsMain/kotlin/com/fleeksoft/ksoup/Platform.wasmjs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.fleeksoft.ksoup

import kotlinx.io.RawSource
import kotlinx.io.files.Path

internal actual fun readGzipFile(file: Path): RawSource {
TODO("not implemented")
}

public actual object Platform {
public actual val current: PlatformType
get() = PlatformType.WASM_JS
}

0 comments on commit 347d57b

Please sign in to comment.