From 9372e32edb1fb342d78a7237069e5364a33609de Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 19 Nov 2023 21:15:10 +0100 Subject: [PATCH 01/51] Give tungstenite types distinct names --- src/gateway/backend_tungstenite.rs | 11 ++++++----- src/gateway/gateway.rs | 6 +++--- src/gateway/handle.rs | 2 +- src/gateway/heartbeat.rs | 4 ++-- src/gateway/mod.rs | 6 +++--- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/gateway/backend_tungstenite.rs b/src/gateway/backend_tungstenite.rs index 53b6982a..f99424d5 100644 --- a/src/gateway/backend_tungstenite.rs +++ b/src/gateway/backend_tungstenite.rs @@ -11,16 +11,17 @@ use super::GatewayMessage; use crate::errors::GatewayError; #[derive(Debug, Clone)] -pub struct WebSocketBackend; +pub struct TungsteniteBackend; // These could be made into inherent associated types when that's stabilized -pub type WsSink = SplitSink>, tungstenite::Message>; -pub type WsStream = SplitStream>>; +pub type TungsteniteSink = + SplitSink>, tungstenite::Message>; +pub type TungsteniteStream = SplitStream>>; -impl WebSocketBackend { +impl TungsteniteBackend { pub async fn connect( websocket_url: &str, - ) -> Result<(WsSink, WsStream), crate::errors::GatewayError> { + ) -> Result<(TungsteniteSink, TungsteniteStream), crate::errors::GatewayError> { let mut roots = rustls::RootCertStore::empty(); for cert in rustls_native_certs::load_native_certs().expect("could not load platform certs") { diff --git a/src/gateway/gateway.rs b/src/gateway/gateway.rs index 9e3410c3..e2923c90 100644 --- a/src/gateway/gateway.rs +++ b/src/gateway/gateway.rs @@ -6,7 +6,7 @@ use tokio::task; use self::event::Events; use super::*; -use super::{WsSink, WsStream}; +use super::{Sink, Stream}; use crate::types::{ self, AutoModerationRule, AutoModerationRuleUpdate, Channel, ChannelCreate, ChannelDelete, ChannelUpdate, Guild, GuildRoleCreate, GuildRoleUpdate, JsonField, RoleObject, SourceUrlField, @@ -17,8 +17,8 @@ use crate::types::{ pub struct Gateway { events: Arc>, heartbeat_handler: HeartbeatHandler, - websocket_send: Arc>, - websocket_receive: WsStream, + websocket_send: Arc>, + websocket_receive: Stream, kill_send: tokio::sync::broadcast::Sender<()>, store: Arc>>>>, url: String, diff --git a/src/gateway/handle.rs b/src/gateway/handle.rs index 9a3c509f..620faba8 100644 --- a/src/gateway/handle.rs +++ b/src/gateway/handle.rs @@ -14,7 +14,7 @@ use crate::types::{self, Composite}; pub struct GatewayHandle { pub url: String, pub events: Arc>, - pub websocket_send: Arc>, + pub websocket_send: Arc>, /// Tells gateway tasks to close pub(super) kill_send: tokio::sync::broadcast::Sender<()>, pub(crate) store: Arc>>>>, diff --git a/src/gateway/heartbeat.rs b/src/gateway/heartbeat.rs index a5875a4c..b8e4bec7 100644 --- a/src/gateway/heartbeat.rs +++ b/src/gateway/heartbeat.rs @@ -27,7 +27,7 @@ pub(super) struct HeartbeatHandler { impl HeartbeatHandler { pub fn new( heartbeat_interval: Duration, - websocket_tx: Arc>, + websocket_tx: Arc>, kill_rc: tokio::sync::broadcast::Receiver<()>, ) -> Self { let (send, receive) = tokio::sync::mpsc::channel(32); @@ -49,7 +49,7 @@ impl HeartbeatHandler { /// Can be killed by the kill broadcast; /// If the websocket is closed, will die out next time it tries to send a heartbeat; pub async fn heartbeat_task( - websocket_tx: Arc>, + websocket_tx: Arc>, heartbeat_interval: Duration, mut receive: Receiver, mut kill_receive: tokio::sync::broadcast::Receiver<()>, diff --git a/src/gateway/mod.rs b/src/gateway/mod.rs index 8314999e..03ac5024 100644 --- a/src/gateway/mod.rs +++ b/src/gateway/mod.rs @@ -23,11 +23,11 @@ use std::sync::{Arc, RwLock}; use tokio::sync::Mutex; #[cfg(not(target_arch = "wasm32"))] -pub type WsSink = backend_tungstenite::WsSink; +pub type Sink = backend_tungstenite::TungsteniteSink; #[cfg(not(target_arch = "wasm32"))] -pub type WsStream = backend_tungstenite::WsStream; +pub type Stream = backend_tungstenite::TungsteniteStream; #[cfg(not(target_arch = "wasm32"))] -pub type WebSocketBackend = backend_tungstenite::WebSocketBackend; +pub type WebSocketBackend = backend_tungstenite::TungsteniteBackend; // Gateway opcodes /// Opcode received when the server dispatches a [crate::types::WebSocketEvent] From 73e40cabd2d24d3e948b42b9ba1356e390ad8bd1 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 19 Nov 2023 21:21:34 +0100 Subject: [PATCH 02/51] reorganize files --- src/gateway/backends/mod.rs | 9 +++++++++ .../tungstenite.rs} | 2 +- src/gateway/mod.rs | 11 ++--------- 3 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 src/gateway/backends/mod.rs rename src/gateway/{backend_tungstenite.rs => backends/tungstenite.rs} (98%) diff --git a/src/gateway/backends/mod.rs b/src/gateway/backends/mod.rs new file mode 100644 index 00000000..53123fe0 --- /dev/null +++ b/src/gateway/backends/mod.rs @@ -0,0 +1,9 @@ +#[cfg(not(target_arch = "wasm32"))] +pub mod tungstenite; + +#[cfg(not(target_arch = "wasm32"))] +pub type Sink = tungstenite::TungsteniteSink; +#[cfg(not(target_arch = "wasm32"))] +pub type Stream = tungstenite::TungsteniteStream; +#[cfg(not(target_arch = "wasm32"))] +pub type WebSocketBackend = tungstenite::TungsteniteBackend; diff --git a/src/gateway/backend_tungstenite.rs b/src/gateway/backends/tungstenite.rs similarity index 98% rename from src/gateway/backend_tungstenite.rs rename to src/gateway/backends/tungstenite.rs index f99424d5..51843293 100644 --- a/src/gateway/backend_tungstenite.rs +++ b/src/gateway/backends/tungstenite.rs @@ -7,8 +7,8 @@ use tokio_tungstenite::{ connect_async_tls_with_config, tungstenite, Connector, MaybeTlsStream, WebSocketStream, }; -use super::GatewayMessage; use crate::errors::GatewayError; +use crate::gateway::GatewayMessage; #[derive(Debug, Clone)] pub struct TungsteniteBackend; diff --git a/src/gateway/mod.rs b/src/gateway/mod.rs index 03ac5024..076ed541 100644 --- a/src/gateway/mod.rs +++ b/src/gateway/mod.rs @@ -1,13 +1,13 @@ use async_trait::async_trait; -#[cfg(not(target_arch = "wasm32"))] -pub mod backend_tungstenite; +pub mod backends; pub mod events; pub mod gateway; pub mod handle; pub mod heartbeat; pub mod message; +pub use backends::*; pub use gateway::*; pub use handle::*; use heartbeat::*; @@ -22,13 +22,6 @@ use std::sync::{Arc, RwLock}; use tokio::sync::Mutex; -#[cfg(not(target_arch = "wasm32"))] -pub type Sink = backend_tungstenite::TungsteniteSink; -#[cfg(not(target_arch = "wasm32"))] -pub type Stream = backend_tungstenite::TungsteniteStream; -#[cfg(not(target_arch = "wasm32"))] -pub type WebSocketBackend = backend_tungstenite::TungsteniteBackend; - // Gateway opcodes /// Opcode received when the server dispatches a [crate::types::WebSocketEvent] const GATEWAY_DISPATCH: u8 = 0; From ec381309bed7186d7389b4fe68ab9ccbe8f6452a Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 19 Nov 2023 22:04:18 +0100 Subject: [PATCH 03/51] Better feature locking, add wasm.rs --- src/gateway/backends/mod.rs | 21 ++++++++++++---- src/gateway/backends/wasm.rs | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 src/gateway/backends/wasm.rs diff --git a/src/gateway/backends/mod.rs b/src/gateway/backends/mod.rs index 53123fe0..fe6e325b 100644 --- a/src/gateway/backends/mod.rs +++ b/src/gateway/backends/mod.rs @@ -1,9 +1,22 @@ -#[cfg(not(target_arch = "wasm32"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] pub mod tungstenite; +#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] +pub use tungstenite::*; +#[cfg(all(target_arch = "wasm32", feature = "client"))] +pub mod wasm; +#[cfg(all(target_arch = "wasm32", feature = "client"))] +pub use wasm::*; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] pub type Sink = tungstenite::TungsteniteSink; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] pub type Stream = tungstenite::TungsteniteStream; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] pub type WebSocketBackend = tungstenite::TungsteniteBackend; + +#[cfg(all(target_arch = "wasm32", feature = "client"))] +pub type Sink = wasm::WasmSink; +#[cfg(all(target_arch = "wasm32", feature = "client"))] +pub type Stream = wasm::WasmStream; +#[cfg(all(target_arch = "wasm32", feature = "client"))] +pub type WebSocketBackend = wasm::WasmBackend; diff --git a/src/gateway/backends/wasm.rs b/src/gateway/backends/wasm.rs new file mode 100644 index 00000000..546a05d5 --- /dev/null +++ b/src/gateway/backends/wasm.rs @@ -0,0 +1,46 @@ +use futures_util::{ + stream::{SplitSink, SplitStream}, + StreamExt, +}; + +use ws_stream_wasm::*; + +use crate::errors::GatewayError; +use crate::gateway::GatewayMessage; + +#[derive(Debug, Clone)] +pub struct WasmBackend; + +// These could be made into inherent associated types when that's stabilized +pub type WasmSink = SplitSink>, tungstenite::Message>; +pub type WasmStream = SplitStream>>; + +impl WasmBackend { + pub async fn connect( + websocket_url: &str, + ) -> Result<(WasmSink, WasmStream), crate::errors::GatewayError> { + let (websocket_stream, _) = match WsMeta::connect(); + { + Ok(websocket_stream) => websocket_stream, + Err(e) => { + return Err(GatewayError::CannotConnect { + error: e.to_string(), + }) + } + }; + + Ok(websocket_stream.split()) + } +} + +impl From for WsMessage { + fn from(message: GatewayMessage) -> Self { + Self::Text(message.0) + } +} + +impl From for GatewayMessage { + fn from(value: WsMessage) -> Self { + Self(value.to_string()) + } +} From 984fdacd4ee5052c80447e5762a380e0103d69b1 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 19 Nov 2023 22:23:24 +0100 Subject: [PATCH 04/51] Implement wasm Backend --- src/gateway/backends/mod.rs | 1 + src/gateway/backends/wasm.rs | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/gateway/backends/mod.rs b/src/gateway/backends/mod.rs index fe6e325b..edb5dc97 100644 --- a/src/gateway/backends/mod.rs +++ b/src/gateway/backends/mod.rs @@ -2,6 +2,7 @@ pub mod tungstenite; #[cfg(all(not(target_arch = "wasm32"), feature = "client"))] pub use tungstenite::*; + #[cfg(all(target_arch = "wasm32", feature = "client"))] pub mod wasm; #[cfg(all(target_arch = "wasm32", feature = "client"))] diff --git a/src/gateway/backends/wasm.rs b/src/gateway/backends/wasm.rs index 546a05d5..e9927ac4 100644 --- a/src/gateway/backends/wasm.rs +++ b/src/gateway/backends/wasm.rs @@ -12,22 +12,19 @@ use crate::gateway::GatewayMessage; pub struct WasmBackend; // These could be made into inherent associated types when that's stabilized -pub type WasmSink = SplitSink>, tungstenite::Message>; -pub type WasmStream = SplitStream>>; +pub type WasmSink = SplitSink; +pub type WasmStream = SplitStream; impl WasmBackend { pub async fn connect( websocket_url: &str, ) -> Result<(WasmSink, WasmStream), crate::errors::GatewayError> { - let (websocket_stream, _) = match WsMeta::connect(); - { - Ok(websocket_stream) => websocket_stream, - Err(e) => { - return Err(GatewayError::CannotConnect { - error: e.to_string(), - }) - } - }; + let (_, websocket_stream) = match WsMeta::connect(websocket_url, None).await { + Ok(stream) => Ok(stream), + Err(e) => Err(GatewayError::CannotConnect { + error: e.to_string(), + }), + }?; Ok(websocket_stream.split()) } @@ -41,6 +38,13 @@ impl From for WsMessage { impl From for GatewayMessage { fn from(value: WsMessage) -> Self { - Self(value.to_string()) + match value { + WsMessage::Text(text) => Self(text), + WsMessage::Binary(bin) => { + let mut text = String::new(); + let _ = bin.iter().map(|v| text.push_str(&v.to_string())); + Self(text) + } + } } } From dc0c2ee43079c6a0f6732b1bee096552708765ee Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 19 Nov 2023 22:49:41 +0100 Subject: [PATCH 05/51] add wasm-bindgen-test --- Cargo.lock | 42 ++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 6 +++--- tests/wasm.rs | 0 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tests/wasm.rs diff --git a/Cargo.lock b/Cargo.lock index f7379c13..ad4ce35e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -223,6 +223,7 @@ dependencies = [ "tokio", "tokio-tungstenite", "url", + "wasm-bindgen-test", "ws_stream_wasm", ] @@ -252,6 +253,16 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + [[package]] name = "const-oid" version = "0.9.5" @@ -1674,6 +1685,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scopeguard" version = "1.2.0" @@ -2627,6 +2644,31 @@ version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" +[[package]] +name = "wasm-bindgen-test" +version = "0.3.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6433b7c56db97397842c46b67e11873eda263170afeb3a2dc74a7cb370fee0d" +dependencies = [ + "console_error_panic_hook", + "js-sys", + "scoped-tls", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-test-macro", +] + +[[package]] +name = "wasm-bindgen-test-macro" +version = "0.3.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "493fcbab756bb764fa37e6bee8cec2dd709eb4273d06d0c282a5e74275ded735" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + [[package]] name = "web-sys" version = "0.3.65" diff --git a/Cargo.toml b/Cargo.toml index 72028c67..31de1b1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,9 +54,10 @@ sqlx = { version = "0.7.1", features = [ ], optional = true } safina-timer = "0.1.11" rand = "0.8.5" -# TODO: Remove the below 2 imports for production! +# TODO: Remove the below 3 imports for production! ws_stream_wasm = "0.7.4" pharos = "0.5.3" +wasm-bindgen-test = "0.3.38" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] rustls = "0.21.8" @@ -70,9 +71,8 @@ hostname = "0.3.1" [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2.11", features = ["js"] } -tokio-tungstenite = { version = "0.20.1", default-features = false } ws_stream_wasm = "0.7.4" -pharos = "0.5.3" +wasm-bindgen-test = "0.3.38" [dev-dependencies] diff --git a/tests/wasm.rs b/tests/wasm.rs new file mode 100644 index 00000000..e69de29b From 1bcf54c5ea836120dcbfaf825fc917eaf9b91e2c Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 19 Nov 2023 23:04:25 +0100 Subject: [PATCH 06/51] Build & Test for wasm --- .github/workflows/build_and_test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 31962c2b..60ef223e 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -44,4 +44,6 @@ jobs: cargo build --verbose --all-features cargo test --verbose --all-features fi + curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + GECKODRIVER=/usr/local/share/gecko_driver CHROMEDRIVER=/usr/local/share/chromedriver-linux64 cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" From d0bc0bb2d215f9c2081f91a62050baec5bb9ed52 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 19 Nov 2023 23:15:12 +0100 Subject: [PATCH 07/51] Add macos safari wasm test --- .github/workflows/build_and_test.yml | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 60ef223e..e798ec67 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -10,7 +10,7 @@ env: CARGO_TERM_COLOR: always jobs: - rust: + linux: runs-on: ubuntu-latest @@ -33,6 +33,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: cache-all-crates: "true" + prefix-key: "linux" - name: Build, Test and Publish Coverage run: | if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then @@ -46,4 +47,27 @@ jobs: fi curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh GECKODRIVER=/usr/local/share/gecko_driver CHROMEDRIVER=/usr/local/share/chromedriver-linux64 cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" - + macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Clone spacebar server + run: | + git clone https://github.com/bitfl0wer/server.git + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'npm' + cache-dependency-path: server/package-lock.json + - name: Prepare and start Spacebar server + run: | + npm install + npm run setup + npm run start & + working-directory: ./server + - uses: Swatinem/rust-cache@v2 + with: + cache-all-crates: "true" + prefix-key: "macos" + - name: Build, Test wasm with Safari + run: SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" \ No newline at end of file From ced6496d4909a58d9e8d1d93eaf71503fa183f59 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 19 Nov 2023 23:18:58 +0100 Subject: [PATCH 08/51] Add wasm32 target --- .github/workflows/build_and_test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index e798ec67..aedb98d4 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -36,6 +36,7 @@ jobs: prefix-key: "linux" - name: Build, Test and Publish Coverage run: | + rustup target add wasm32-unknown-unknown if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm cargo-tarpaulin --force @@ -70,4 +71,6 @@ jobs: cache-all-crates: "true" prefix-key: "macos" - name: Build, Test wasm with Safari - run: SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" \ No newline at end of file + run: | + rustup target add wasm32-unknown-unknown + SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" \ No newline at end of file From 2690819aa072c0131b8e4bb51e0a086bf8e99bda Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 00:06:35 +0100 Subject: [PATCH 09/51] Add wasm.rs test --- tests/wasm.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/wasm.rs b/tests/wasm.rs index e69de29b..22509653 100644 --- a/tests/wasm.rs +++ b/tests/wasm.rs @@ -0,0 +1 @@ +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); From ce9c1d59bbda4d258d738d44bfe0727dccae338e Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 00:07:09 +0100 Subject: [PATCH 10/51] Move wasm-pack installation before test execution --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index aedb98d4..df8f52bd 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -37,6 +37,7 @@ jobs: - name: Build, Test and Publish Coverage run: | rustup target add wasm32-unknown-unknown + curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm cargo-tarpaulin --force @@ -46,7 +47,6 @@ jobs: cargo build --verbose --all-features cargo test --verbose --all-features fi - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh GECKODRIVER=/usr/local/share/gecko_driver CHROMEDRIVER=/usr/local/share/chromedriver-linux64 cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" macos: runs-on: macos-latest From 81091ebceedee4f3b626150b4c615a503bde91ad Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 00:07:16 +0100 Subject: [PATCH 11/51] Fix build on wasm32 --- src/gateway/gateway.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/gateway/gateway.rs b/src/gateway/gateway.rs index e2923c90..d10dbfbf 100644 --- a/src/gateway/gateway.rs +++ b/src/gateway/gateway.rs @@ -37,7 +37,10 @@ impl Gateway { // Wait for the first hello and then spawn both tasks so we avoid nested tasks // This automatically spawns the heartbeat task, but from the main thread + #[cfg(not(target_arch = "wasm32"))] let msg: GatewayMessage = websocket_receive.next().await.unwrap().unwrap().into(); + #[cfg(target_arch = "wasm32")] + let msg: GatewayMessage = websocket_receive.next().await.unwrap().into(); let gateway_payload: types::GatewayReceivePayload = serde_json::from_str(&msg.0).unwrap(); if gateway_payload.op_code != GATEWAY_HELLO { @@ -91,11 +94,18 @@ impl Gateway { loop { let msg = self.websocket_receive.next().await; + // PRETTYFYME: Remove inline conditional compiling // This if chain can be much better but if let is unstable on stable rust + #[cfg(not(target_arch = "wasm32"))] if let Some(Ok(message)) = msg { self.handle_message(message.into()).await; continue; } + #[cfg(target_arch = "wasm32")] + if let Some(message) = msg { + self.handle_message(message.into()).await; + continue; + } // We couldn't receive the next message or it was an error, something is wrong with the websocket, close warn!("GW: Websocket is broken, stopping gateway"); From 0782f257e8daab754f5b1f821b9b918f5b019012 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 00:13:32 +0100 Subject: [PATCH 12/51] Fix examples depending on tokio::time --- examples/gateway_observers.rs | 5 +++-- examples/gateway_simple.rs | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/gateway_observers.rs b/examples/gateway_observers.rs index d4e690cc..a13c9359 100644 --- a/examples/gateway_observers.rs +++ b/examples/gateway_observers.rs @@ -6,7 +6,7 @@ use chorus::{ types::{GatewayIdentifyPayload, GatewayReady}, }; use std::{sync::Arc, time::Duration}; -use tokio::{self, time::sleep}; +use tokio::{self}; // This example creates a simple gateway connection and a basic observer struct @@ -54,9 +54,10 @@ async fn main() { let mut identify = GatewayIdentifyPayload::common(); identify.token = token; gateway.send_identify(identify).await; + safina_timer::start_timer_thread(); // Do something on the main thread so we don't quit loop { - sleep(Duration::MAX).await; + safina_timer::sleep_for(Duration::MAX).await } } diff --git a/examples/gateway_simple.rs b/examples/gateway_simple.rs index a9c019b1..acb4eb33 100644 --- a/examples/gateway_simple.rs +++ b/examples/gateway_simple.rs @@ -2,7 +2,6 @@ use std::time::Duration; use chorus::gateway::Gateway; use chorus::{self, types::GatewayIdentifyPayload}; -use tokio::time::sleep; /// This example creates a simple gateway connection and a session with an Identify event #[tokio::main(flavor = "current_thread")] @@ -27,10 +26,10 @@ async fn main() { identify.token = token; // Send off the event - gateway.send_identify(identify).await; + safina_timer::start_timer_thread(); // Do something on the main thread so we don't quit loop { - sleep(Duration::MAX).await; + safina_timer::sleep_for(Duration::MAX).await } } From 25434279ddfe50d70c3095b00916074281c3892d Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 00:25:18 +0100 Subject: [PATCH 13/51] fix clippy warn --- examples/gateway_simple.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gateway_simple.rs b/examples/gateway_simple.rs index acb4eb33..29962832 100644 --- a/examples/gateway_simple.rs +++ b/examples/gateway_simple.rs @@ -10,7 +10,7 @@ async fn main() { let websocket_url_spacebar = "wss://gateway.old.server.spacebar.chat/".to_string(); // Initiate the gateway connection, starting a listener in one thread and a heartbeat handler in another - let gateway = Gateway::spawn(websocket_url_spacebar).await.unwrap(); + let _ = Gateway::spawn(websocket_url_spacebar).await.unwrap(); // At this point, we are connected to the server and are sending heartbeats, however we still haven't authenticated From a8110316a8891c0dad1d9ab3c20c90a34af7502d Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 00:27:27 +0100 Subject: [PATCH 14/51] Add example wasm bindgen test --- tests/wasm.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/wasm.rs b/tests/wasm.rs index 22509653..d5d26c15 100644 --- a/tests/wasm.rs +++ b/tests/wasm.rs @@ -1 +1,7 @@ +use wasm_bindgen_test::wasm_bindgen_test; + wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); +#[wasm_bindgen_test] +fn pass() { + let _ = String::new(); +} From c456d65c2fc5c3bf4b774b70747ac12edc2dcdfd Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 11:41:32 +0100 Subject: [PATCH 15/51] Add wasm-bindgen to Cargo.toml --- Cargo.lock | 2 +- Cargo.toml | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad4ce35e..7c74e2a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -205,7 +205,6 @@ dependencies = [ "lazy_static", "log", "native-tls", - "pharos", "poem", "rand", "regex", @@ -223,6 +222,7 @@ dependencies = [ "tokio", "tokio-tungstenite", "url", + "wasm-bindgen", "wasm-bindgen-test", "ws_stream_wasm", ] diff --git a/Cargo.toml b/Cargo.toml index 31de1b1f..24a71148 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,10 +54,6 @@ sqlx = { version = "0.7.1", features = [ ], optional = true } safina-timer = "0.1.11" rand = "0.8.5" -# TODO: Remove the below 3 imports for production! -ws_stream_wasm = "0.7.4" -pharos = "0.5.3" -wasm-bindgen-test = "0.3.38" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] rustls = "0.21.8" @@ -72,8 +68,9 @@ hostname = "0.3.1" [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2.11", features = ["js"] } ws_stream_wasm = "0.7.4" -wasm-bindgen-test = "0.3.38" [dev-dependencies] lazy_static = "1.4.0" +wasm-bindgen-test = "0.3.38" +wasm-bindgen = "0.2.88" From 62e9123adc0034cf5e5e4f6f2203101bf39f82ec Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 11:41:46 +0100 Subject: [PATCH 16/51] Add wasm test configuration --- .cargo/config.toml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..4ec2f3b8 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[target.wasm32-unknown-unknown] +runner = 'wasm-bindgen-test-runner' From c9d4ecda18a5e00f020e862f87bd03acb6ea7008 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 11:42:07 +0100 Subject: [PATCH 17/51] Install wasm-bindgen-cli on linux --- .github/workflows/build_and_test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index df8f52bd..c57dc24d 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -40,6 +40,7 @@ jobs: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash + cargo binstall --no-confirm wasm-bindgen-cli --vers "0.2.88" --force cargo binstall --no-confirm cargo-tarpaulin --force cargo tarpaulin --all-features --avoid-cfg-tarpaulin --tests --verbose --skip-clean --coveralls ${{ secrets.COVERALLS_REPO_TOKEN }} --timeout 120 else From 7f94b8e3f3f5d765145189fe7bc587bb294a550a Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 11:43:08 +0100 Subject: [PATCH 18/51] Add wasm-bindgen-cli to macos --- .github/workflows/build_and_test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index c57dc24d..157861c5 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -74,4 +74,6 @@ jobs: - name: Build, Test wasm with Safari run: | rustup target add wasm32-unknown-unknown + curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash + cargo binstall --no-confirm wasm-bindgen-cli --vers "0.2.88" --force SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" \ No newline at end of file From a52dd1edc8146bb12ee1c6500559723e72237f58 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 11:46:10 +0100 Subject: [PATCH 19/51] Correct "vers" to "version" --- .github/workflows/build_and_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 157861c5..127b088a 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -40,7 +40,7 @@ jobs: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash - cargo binstall --no-confirm wasm-bindgen-cli --vers "0.2.88" --force + cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force cargo binstall --no-confirm cargo-tarpaulin --force cargo tarpaulin --all-features --avoid-cfg-tarpaulin --tests --verbose --skip-clean --coveralls ${{ secrets.COVERALLS_REPO_TOKEN }} --timeout 120 else @@ -75,5 +75,5 @@ jobs: run: | rustup target add wasm32-unknown-unknown curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash - cargo binstall --no-confirm wasm-bindgen-cli --vers "0.2.88" --force + cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" \ No newline at end of file From 401249b3d1dba197cd98c353d44314279731ce8e Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 11:57:31 +0100 Subject: [PATCH 20/51] Attempt to locate correct geckodriver --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 127b088a..e7ef766f 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -48,7 +48,7 @@ jobs: cargo build --verbose --all-features cargo test --verbose --all-features fi - GECKODRIVER=/usr/local/share/gecko_driver CHROMEDRIVER=/usr/local/share/chromedriver-linux64 cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + GECKODRIVER=$(which geckodriver) CHROMEDRIVER=$(which chromedriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" macos: runs-on: macos-latest steps: From a2834b2251d425fc2b134a07873d63432b716d58 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 11:59:37 +0100 Subject: [PATCH 21/51] Run wasm tests first --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index e7ef766f..3021c972 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -38,6 +38,7 @@ jobs: run: | rustup target add wasm32-unknown-unknown curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + GECKODRIVER=$(which geckodriver) CHROMEDRIVER=$(which chromedriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force @@ -48,7 +49,6 @@ jobs: cargo build --verbose --all-features cargo test --verbose --all-features fi - GECKODRIVER=$(which geckodriver) CHROMEDRIVER=$(which chromedriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" macos: runs-on: macos-latest steps: From 083f4386f312725007221ab14480aacea6ff1db0 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 12:04:56 +0100 Subject: [PATCH 22/51] maybe this will fix ci :clueless: --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 3021c972..0679775a 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -38,7 +38,7 @@ jobs: run: | rustup target add wasm32-unknown-unknown curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - GECKODRIVER=$(which geckodriver) CHROMEDRIVER=$(which chromedriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + GECKODRIVER=/usr/local/share/gecko_driver CHROMEDRIVER=/usr/local/share/chromedriver-linux64 sudo cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force From 7862c5f222f61bd5ede390eb274b97bdd8d6f4f0 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 12:08:40 +0100 Subject: [PATCH 23/51] Move wasm-bindgen-cli install --- .github/workflows/build_and_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 0679775a..1079a136 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -38,10 +38,10 @@ jobs: run: | rustup target add wasm32-unknown-unknown curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - GECKODRIVER=/usr/local/share/gecko_driver CHROMEDRIVER=/usr/local/share/chromedriver-linux64 sudo cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force + GECKODRIVER=/usr/local/share/gecko_driver CHROMEDRIVER=/usr/local/share/chromedriver-linux64 cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash - cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force cargo binstall --no-confirm cargo-tarpaulin --force cargo tarpaulin --all-features --avoid-cfg-tarpaulin --tests --verbose --skip-clean --coveralls ${{ secrets.COVERALLS_REPO_TOKEN }} --timeout 120 else From 7e4f60b161188f3d7bc74bbd2e4041416663a1a7 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 12:11:30 +0100 Subject: [PATCH 24/51] Add cargo-binstall installation script for wasm-bindgen-cli --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 1079a136..2feb908a 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -38,10 +38,10 @@ jobs: run: | rustup target add wasm32-unknown-unknown curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force GECKODRIVER=/usr/local/share/gecko_driver CHROMEDRIVER=/usr/local/share/chromedriver-linux64 cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then - curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm cargo-tarpaulin --force cargo tarpaulin --all-features --avoid-cfg-tarpaulin --tests --verbose --skip-clean --coveralls ${{ secrets.COVERALLS_REPO_TOKEN }} --timeout 120 else From 608629a8748e28570587f81a3ee4c4b8851abc05 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 12:29:20 +0100 Subject: [PATCH 25/51] Try using only one browser --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 2feb908a..eac51199 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -40,7 +40,7 @@ jobs: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force - GECKODRIVER=/usr/local/share/gecko_driver CHROMEDRIVER=/usr/local/share/chromedriver-linux64 cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + GECKODRIVER=/usr/local/share/gecko_driver cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then cargo binstall --no-confirm cargo-tarpaulin --force cargo tarpaulin --all-features --avoid-cfg-tarpaulin --tests --verbose --skip-clean --coveralls ${{ secrets.COVERALLS_REPO_TOKEN }} --timeout 120 From c492f85235fcb93680d816fcdec4b33161bacdf4 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 12:32:48 +0100 Subject: [PATCH 26/51] remove geckodriver --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index eac51199..b7a643b2 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -40,7 +40,7 @@ jobs: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force - GECKODRIVER=/usr/local/share/gecko_driver cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + CHROMEDRIVER=/usr/local/share/chromedriver-linux64 cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then cargo binstall --no-confirm cargo-tarpaulin --force cargo tarpaulin --all-features --avoid-cfg-tarpaulin --tests --verbose --skip-clean --coveralls ${{ secrets.COVERALLS_REPO_TOKEN }} --timeout 120 From 79d97a1a7a74846f88346d03b7677c220d08bfd1 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 12:38:39 +0100 Subject: [PATCH 27/51] Move all wasm related tests to macos --- .github/workflows/build_and_test.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index b7a643b2..0010a13d 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -36,12 +36,8 @@ jobs: prefix-key: "linux" - name: Build, Test and Publish Coverage run: | - rustup target add wasm32-unknown-unknown - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash - cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force - CHROMEDRIVER=/usr/local/share/chromedriver-linux64 cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then + curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm cargo-tarpaulin --force cargo tarpaulin --all-features --avoid-cfg-tarpaulin --tests --verbose --skip-clean --coveralls ${{ secrets.COVERALLS_REPO_TOKEN }} --timeout 120 else @@ -76,4 +72,6 @@ jobs: rustup target add wasm32-unknown-unknown curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force - SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" \ No newline at end of file + SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + GECKODRIVER=$(which geckodriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + CHROMEDRIVER=$(which chromedriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" \ No newline at end of file From 31136ada292653f4566cadaa08f81d2b57da6cef Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 12:51:55 +0100 Subject: [PATCH 28/51] Rename macOS test step for clarity --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 0010a13d..c0e314fc 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -67,7 +67,7 @@ jobs: with: cache-all-crates: "true" prefix-key: "macos" - - name: Build, Test wasm with Safari + - name: Run WASM tests with Safari, Firefox, Chrome run: | rustup target add wasm32-unknown-unknown curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash From 584fd21076160490395aeb051e0902a61e471f45 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 13:16:49 +0100 Subject: [PATCH 29/51] Try out combined coverage report --- .github/workflows/build_and_test.yml | 34 ++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index c0e314fc..d5231658 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -39,12 +39,18 @@ jobs: if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm cargo-tarpaulin --force - cargo tarpaulin --all-features --avoid-cfg-tarpaulin --tests --verbose --skip-clean --coveralls ${{ secrets.COVERALLS_REPO_TOKEN }} --timeout 120 + cargo tarpaulin --all-features --avoid-cfg-tarpaulin --tests --verbose --skip-clean --timeout 120 --output-dir ./cargo/output-linux.lcov --out Lcov else echo "Code Coverage step is skipped on forks!" cargo build --verbose --all-features cargo test --verbose --all-features fi + - name: Upload coverage for Linux + if: ${{ secrets.COVERALLS_REPO_TOKEN }} + uses: actions/upload-artifact@v2 + with: + name: coverage-linux + path: ./cargo/output-linux.lcov macos: runs-on: macos-latest steps: @@ -72,6 +78,26 @@ jobs: rustup target add wasm32-unknown-unknown curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force - SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" - GECKODRIVER=$(which geckodriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" - CHROMEDRIVER=$(which chromedriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" \ No newline at end of file + if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then + cargo binstall --no-confirm cargo-tarpaulin --force + SAFARIDRIVER=$(which safaridriver) CHROMEDRIVER=$(which chromedriver) GECKODRIVER=$(which geckodriver) cargo tarpaulin --target wasm32-unknown-unknown --no-default-features --features="client, rt" --avoid-cfg-tarpaulin --tests --verbose --skip-clean --timeout 120 --output-dir ./cargo/output-macos.lcov --out Lcov + else + echo "Code Coverage step is skipped on forks!" + SAFARIDRIVER=$(which safaridriver) CHROMEDRIVER=$(which chromedriver) GECKODRIVER=$(which geckodriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + fi + - name: Upload coverage for macOS + if: ${{ secrets.COVERALLS_REPO_TOKEN }} + uses: actions/upload-artifact@v2 + with: + name: coverage-macos + path: ./cargo/output-macos.lcov + + upload-coverage: + needs: [linux, macos] + if: ${{ secrets.COVERALLS_REPO_TOKEN }} + runs-on: ubuntu-latest + steps: + - name: Download all workflow run artifacts + uses: actions/download-artifact@v2 + - name: Upload coverage to Coveralls.io + uses: coverallsapp/github-action@v2 \ No newline at end of file From cae64ae5a479e63ced019d045c3c48523f1ceaa2 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 13:22:23 +0100 Subject: [PATCH 30/51] try different strategy to skip coverage on forks --- .github/workflows/build_and_test.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index d5231658..05b0acbe 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -15,6 +15,9 @@ jobs: runs-on: ubuntu-latest steps: + - name: Set coverage flag + id: cov-flag + run: echo ::set-output name=flag::${{ github.event.pull_request.head.repo.fork == false }} - uses: actions/checkout@v4 - name: Clone spacebar server run: | @@ -46,7 +49,7 @@ jobs: cargo test --verbose --all-features fi - name: Upload coverage for Linux - if: ${{ secrets.COVERALLS_REPO_TOKEN }} + if: steps.cov-flag.outputs.flag == 'true' uses: actions/upload-artifact@v2 with: name: coverage-linux @@ -54,6 +57,9 @@ jobs: macos: runs-on: macos-latest steps: + - name: Set coverage flag + id: cov-flag + run: echo ::set-output name=flag::${{ github.event.pull_request.head.repo.fork == false }} - uses: actions/checkout@v4 - name: Clone spacebar server run: | @@ -86,7 +92,7 @@ jobs: SAFARIDRIVER=$(which safaridriver) CHROMEDRIVER=$(which chromedriver) GECKODRIVER=$(which geckodriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" fi - name: Upload coverage for macOS - if: ${{ secrets.COVERALLS_REPO_TOKEN }} + if: steps.cov-flag.outputs.flag == 'true' uses: actions/upload-artifact@v2 with: name: coverage-macos @@ -94,7 +100,7 @@ jobs: upload-coverage: needs: [linux, macos] - if: ${{ secrets.COVERALLS_REPO_TOKEN }} + if: needs.linux.outputs.flag == 'true' && needs.macos.outputs.flag == 'true' runs-on: ubuntu-latest steps: - name: Download all workflow run artifacts From 06574c2708e4c9b422dd46ad64a136f404bafe79 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 13:33:40 +0100 Subject: [PATCH 31/51] Revert "try different strategy to skip coverage on forks" This reverts commit cae64ae5a479e63ced019d045c3c48523f1ceaa2. --- .github/workflows/build_and_test.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 05b0acbe..d5231658 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -15,9 +15,6 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set coverage flag - id: cov-flag - run: echo ::set-output name=flag::${{ github.event.pull_request.head.repo.fork == false }} - uses: actions/checkout@v4 - name: Clone spacebar server run: | @@ -49,7 +46,7 @@ jobs: cargo test --verbose --all-features fi - name: Upload coverage for Linux - if: steps.cov-flag.outputs.flag == 'true' + if: ${{ secrets.COVERALLS_REPO_TOKEN }} uses: actions/upload-artifact@v2 with: name: coverage-linux @@ -57,9 +54,6 @@ jobs: macos: runs-on: macos-latest steps: - - name: Set coverage flag - id: cov-flag - run: echo ::set-output name=flag::${{ github.event.pull_request.head.repo.fork == false }} - uses: actions/checkout@v4 - name: Clone spacebar server run: | @@ -92,7 +86,7 @@ jobs: SAFARIDRIVER=$(which safaridriver) CHROMEDRIVER=$(which chromedriver) GECKODRIVER=$(which geckodriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" fi - name: Upload coverage for macOS - if: steps.cov-flag.outputs.flag == 'true' + if: ${{ secrets.COVERALLS_REPO_TOKEN }} uses: actions/upload-artifact@v2 with: name: coverage-macos @@ -100,7 +94,7 @@ jobs: upload-coverage: needs: [linux, macos] - if: needs.linux.outputs.flag == 'true' && needs.macos.outputs.flag == 'true' + if: ${{ secrets.COVERALLS_REPO_TOKEN }} runs-on: ubuntu-latest steps: - name: Download all workflow run artifacts From 5e20d77bf07e5eb3b8ee96468aa7038c9f197b84 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 13:33:45 +0100 Subject: [PATCH 32/51] Revert "Try out combined coverage report" This reverts commit 584fd21076160490395aeb051e0902a61e471f45. --- .github/workflows/build_and_test.yml | 34 ++++------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index d5231658..c0e314fc 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -39,18 +39,12 @@ jobs: if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm cargo-tarpaulin --force - cargo tarpaulin --all-features --avoid-cfg-tarpaulin --tests --verbose --skip-clean --timeout 120 --output-dir ./cargo/output-linux.lcov --out Lcov + cargo tarpaulin --all-features --avoid-cfg-tarpaulin --tests --verbose --skip-clean --coveralls ${{ secrets.COVERALLS_REPO_TOKEN }} --timeout 120 else echo "Code Coverage step is skipped on forks!" cargo build --verbose --all-features cargo test --verbose --all-features fi - - name: Upload coverage for Linux - if: ${{ secrets.COVERALLS_REPO_TOKEN }} - uses: actions/upload-artifact@v2 - with: - name: coverage-linux - path: ./cargo/output-linux.lcov macos: runs-on: macos-latest steps: @@ -78,26 +72,6 @@ jobs: rustup target add wasm32-unknown-unknown curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force - if [ -n "${{ secrets.COVERALLS_REPO_TOKEN }}" ]; then - cargo binstall --no-confirm cargo-tarpaulin --force - SAFARIDRIVER=$(which safaridriver) CHROMEDRIVER=$(which chromedriver) GECKODRIVER=$(which geckodriver) cargo tarpaulin --target wasm32-unknown-unknown --no-default-features --features="client, rt" --avoid-cfg-tarpaulin --tests --verbose --skip-clean --timeout 120 --output-dir ./cargo/output-macos.lcov --out Lcov - else - echo "Code Coverage step is skipped on forks!" - SAFARIDRIVER=$(which safaridriver) CHROMEDRIVER=$(which chromedriver) GECKODRIVER=$(which geckodriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" - fi - - name: Upload coverage for macOS - if: ${{ secrets.COVERALLS_REPO_TOKEN }} - uses: actions/upload-artifact@v2 - with: - name: coverage-macos - path: ./cargo/output-macos.lcov - - upload-coverage: - needs: [linux, macos] - if: ${{ secrets.COVERALLS_REPO_TOKEN }} - runs-on: ubuntu-latest - steps: - - name: Download all workflow run artifacts - uses: actions/download-artifact@v2 - - name: Upload coverage to Coveralls.io - uses: coverallsapp/github-action@v2 \ No newline at end of file + SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + GECKODRIVER=$(which geckodriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + CHROMEDRIVER=$(which chromedriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" \ No newline at end of file From 4288455aec738ba9875e717fef9f21d5cb66d347 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 14:03:06 +0100 Subject: [PATCH 33/51] Add tests for WASM --- tests/auth.rs | 12 ++++++++++++ tests/channels.rs | 36 ++++++++++++++++++++++++++++++++++++ tests/gateway.rs | 29 +++++++++++++++++++++++++++++ tests/guilds.rs | 35 +++++++++++++++++++++++++++++++++++ tests/instance.rs | 11 +++++++++++ tests/invites.rs | 12 ++++++++++++ tests/members.rs | 11 +++++++++++ tests/messages.rs | 29 +++++++++++++++++++++++++++++ tests/relationships.rs | 29 +++++++++++++++++++++++++++++ tests/roles.rs | 17 +++++++++++++++++ 10 files changed, 221 insertions(+) diff --git a/tests/auth.rs b/tests/auth.rs index f89e5e42..4c795623 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -1,7 +1,13 @@ use chorus::types::RegisterSchema; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); mod common; +#[cfg(not(target_arch = "wasm32"))] #[tokio::test] async fn test_registration() { let bundle = common::setup().await; @@ -14,3 +20,9 @@ async fn test_registration() { bundle.instance.clone().register_account(reg).await.unwrap(); common::teardown(bundle).await; } + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_registration_wasm() { + test_registration().await +} diff --git a/tests/channels.rs b/tests/channels.rs index 16476521..d1b85b22 100644 --- a/tests/channels.rs +++ b/tests/channels.rs @@ -4,6 +4,42 @@ use chorus::types::{ }; mod common; +// PRETTYFYME: Move common wasm setup to common.rs + +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_get_channel_wasm() { + get_channel().await +} +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_delete_channel_wasm() { + delete_channel().await +} +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_modify_channel_wasm() { + modify_channel().await +} +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_get_channel_messages_wasm() { + get_channel_messages().await +} +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_create_dm_wasm() { + create_dm().await +} +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_remove_add_person_from_to_dm_wasm() { + remove_add_person_from_to_dm().await +} #[tokio::test] async fn get_channel() { diff --git a/tests/gateway.rs b/tests/gateway.rs index 0b1e12fa..a05a7983 100644 --- a/tests/gateway.rs +++ b/tests/gateway.rs @@ -4,6 +4,35 @@ use std::sync::{Arc, RwLock}; use chorus::gateway::*; use chorus::types::{self, ChannelModifySchema, RoleCreateModifySchema, RoleObject}; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_gateway_establish_wasm() { + test_gateway_establish().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_gateway_authenticate_wasm() { + test_gateway_authenticate().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_self_updating_structs_wasm() { + test_self_updating_structs().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_recursive_self_updating_structs_wasm() { + test_recursive_self_updating_structs().await +} #[tokio::test] /// Tests establishing a connection (hello and heartbeats) on the local gateway; diff --git a/tests/guilds.rs b/tests/guilds.rs index d7e2699d..2bafbabe 100644 --- a/tests/guilds.rs +++ b/tests/guilds.rs @@ -3,6 +3,41 @@ use chorus::types::{ }; mod common; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn guild_creation_deletion_wasm() { + guild_creation_deletion().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn get_channels_wasm() { + get_channels().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn guild_create_ban_wasm() { + guild_create_ban().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn modify_guild_wasm() { + modify_guild().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn guild_remove_member_wasm() { + guild_remove_member().await +} #[tokio::test] async fn guild_creation_deletion() { diff --git a/tests/instance.rs b/tests/instance.rs index d3cd5f02..2466e60f 100644 --- a/tests/instance.rs +++ b/tests/instance.rs @@ -1,4 +1,15 @@ mod common; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn guild_creation_deletion_wasm() { + guild_creation_deletion().await +} #[tokio::test] async fn generate_general_configuration_schema() { diff --git a/tests/invites.rs b/tests/invites.rs index ab264d4c..a535b84c 100644 --- a/tests/invites.rs +++ b/tests/invites.rs @@ -1,5 +1,17 @@ mod common; use chorus::types::CreateChannelInviteSchema; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn create_accept_invite_wasm() { + create_accept_invite().await +} + #[tokio::test] async fn create_accept_invite() { let mut bundle = common::setup().await; diff --git a/tests/members.rs b/tests/members.rs index fbab7728..a2043efb 100644 --- a/tests/members.rs +++ b/tests/members.rs @@ -1,7 +1,18 @@ use chorus::{errors::ChorusResult, types::GuildMember}; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); mod common; +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn add_remove_role_wasm() { + add_remove_role().await.unwrap() +} + #[tokio::test] async fn add_remove_role() -> ChorusResult<()> { let mut bundle = common::setup().await; diff --git a/tests/messages.rs b/tests/messages.rs index 5ad9a899..fc46831c 100644 --- a/tests/messages.rs +++ b/tests/messages.rs @@ -2,9 +2,38 @@ use std::fs::File; use std::io::{BufReader, Read}; use chorus::types::{self, Guild, Message, MessageSearchQuery}; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); mod common; +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn send_message_wasm() { + send_message().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn send_message_attachment_wasm() { + send_message_attachment().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn search_messages_wasm() { + search_messages().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_stickies_wasm() { + test_stickies().await +} + #[tokio::test] async fn send_message() { let mut bundle = common::setup().await; diff --git a/tests/relationships.rs b/tests/relationships.rs index 09ddab04..7f26e0f5 100644 --- a/tests/relationships.rs +++ b/tests/relationships.rs @@ -1,7 +1,36 @@ use chorus::types::{self, Relationship, RelationshipType}; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); mod common; +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_get_relationships_wasm() { + test_get_relationships().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_get_mutual_relationships_wasm() { + test_get_mutual_relationships().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_modify_relationship_friends_wasm() { + test_modify_relationship_friends().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_modify_relationship_block_wasm() { + test_modify_relationship_block().await +} + #[tokio::test] async fn test_get_mutual_relationships() { let mut bundle = common::setup().await; diff --git a/tests/roles.rs b/tests/roles.rs index 8691138e..0dd3b7f7 100644 --- a/tests/roles.rs +++ b/tests/roles.rs @@ -1,7 +1,24 @@ use chorus::types::{self, RoleCreateModifySchema, RoleObject}; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); mod common; +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn create_and_get_roles_wasm() { + create_and_get_roles().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn get_and_delete_role_wasm() { + get_and_delete_role().await +} + #[tokio::test] async fn create_and_get_roles() { let mut bundle = common::setup().await; From 8eee0c816c9df18ac8ee8a9632cbafc8dfd5243c Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 14:11:56 +0100 Subject: [PATCH 34/51] remove all .await from wasm tests --- tests/auth.rs | 2 +- tests/channels.rs | 12 ++++++------ tests/gateway.rs | 8 ++++---- tests/guilds.rs | 10 +++++----- tests/instance.rs | 2 +- tests/invites.rs | 2 +- tests/members.rs | 2 +- tests/messages.rs | 8 ++++---- tests/relationships.rs | 8 ++++---- tests/roles.rs | 4 ++-- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/auth.rs b/tests/auth.rs index 4c795623..b6731d73 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -24,5 +24,5 @@ async fn test_registration() { #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_registration_wasm() { - test_registration().await + test_registration() } diff --git a/tests/channels.rs b/tests/channels.rs index d1b85b22..270f64f9 100644 --- a/tests/channels.rs +++ b/tests/channels.rs @@ -13,32 +13,32 @@ wasm_bindgen_test_configure!(run_in_browser); #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_get_channel_wasm() { - get_channel().await + get_channel() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_delete_channel_wasm() { - delete_channel().await + delete_channel() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_modify_channel_wasm() { - modify_channel().await + modify_channel() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_get_channel_messages_wasm() { - get_channel_messages().await + get_channel_messages() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_create_dm_wasm() { - create_dm().await + create_dm() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_remove_add_person_from_to_dm_wasm() { - remove_add_person_from_to_dm().await + remove_add_person_from_to_dm() } #[tokio::test] diff --git a/tests/gateway.rs b/tests/gateway.rs index a05a7983..54de74f3 100644 --- a/tests/gateway.rs +++ b/tests/gateway.rs @@ -13,25 +13,25 @@ wasm_bindgen_test_configure!(run_in_browser); #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_gateway_establish_wasm() { - test_gateway_establish().await + test_gateway_establish() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_gateway_authenticate_wasm() { - test_gateway_authenticate().await + test_gateway_authenticate() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_self_updating_structs_wasm() { - test_self_updating_structs().await + test_self_updating_structs() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_recursive_self_updating_structs_wasm() { - test_recursive_self_updating_structs().await + test_recursive_self_updating_structs() } #[tokio::test] diff --git a/tests/guilds.rs b/tests/guilds.rs index 2bafbabe..fd684ddb 100644 --- a/tests/guilds.rs +++ b/tests/guilds.rs @@ -12,31 +12,31 @@ wasm_bindgen_test_configure!(run_in_browser); #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn guild_creation_deletion_wasm() { - guild_creation_deletion().await + guild_creation_deletion() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn get_channels_wasm() { - get_channels().await + get_channels() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn guild_create_ban_wasm() { - guild_create_ban().await + guild_create_ban() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn modify_guild_wasm() { - modify_guild().await + modify_guild() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn guild_remove_member_wasm() { - guild_remove_member().await + guild_remove_member() } #[tokio::test] diff --git a/tests/instance.rs b/tests/instance.rs index 2466e60f..1ffe914f 100644 --- a/tests/instance.rs +++ b/tests/instance.rs @@ -8,7 +8,7 @@ wasm_bindgen_test_configure!(run_in_browser); #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn guild_creation_deletion_wasm() { - guild_creation_deletion().await + guild_creation_deletion() } #[tokio::test] diff --git a/tests/invites.rs b/tests/invites.rs index a535b84c..031afeb4 100644 --- a/tests/invites.rs +++ b/tests/invites.rs @@ -9,7 +9,7 @@ wasm_bindgen_test_configure!(run_in_browser); #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn create_accept_invite_wasm() { - create_accept_invite().await + create_accept_invite() } #[tokio::test] diff --git a/tests/members.rs b/tests/members.rs index a2043efb..0dd3616c 100644 --- a/tests/members.rs +++ b/tests/members.rs @@ -10,7 +10,7 @@ mod common; #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn add_remove_role_wasm() { - add_remove_role().await.unwrap() + add_remove_role().unwrap() } #[tokio::test] diff --git a/tests/messages.rs b/tests/messages.rs index fc46831c..a39e9a00 100644 --- a/tests/messages.rs +++ b/tests/messages.rs @@ -13,25 +13,25 @@ mod common; #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn send_message_wasm() { - send_message().await + send_message() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn send_message_attachment_wasm() { - send_message_attachment().await + send_message_attachment() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn search_messages_wasm() { - search_messages().await + search_messages() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_stickies_wasm() { - test_stickies().await + test_stickies() } #[tokio::test] diff --git a/tests/relationships.rs b/tests/relationships.rs index 7f26e0f5..112b47e4 100644 --- a/tests/relationships.rs +++ b/tests/relationships.rs @@ -10,25 +10,25 @@ mod common; #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_get_relationships_wasm() { - test_get_relationships().await + test_get_relationships() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_get_mutual_relationships_wasm() { - test_get_mutual_relationships().await + test_get_mutual_relationships() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_modify_relationship_friends_wasm() { - test_modify_relationship_friends().await + test_modify_relationship_friends() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_modify_relationship_block_wasm() { - test_modify_relationship_block().await + test_modify_relationship_block() } #[tokio::test] diff --git a/tests/roles.rs b/tests/roles.rs index 0dd3b7f7..5e85fbc0 100644 --- a/tests/roles.rs +++ b/tests/roles.rs @@ -10,13 +10,13 @@ mod common; #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn create_and_get_roles_wasm() { - create_and_get_roles().await + create_and_get_roles() } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn get_and_delete_role_wasm() { - get_and_delete_role().await + get_and_delete_role() } #[tokio::test] From ebb414cc8c795f42eebde3938108f5f5d7acdac0 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 14:15:23 +0100 Subject: [PATCH 35/51] Remove unnecessary code --- tests/auth.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/auth.rs b/tests/auth.rs index b6731d73..c0ba90ff 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -7,7 +7,6 @@ wasm_bindgen_test_configure!(run_in_browser); mod common; -#[cfg(not(target_arch = "wasm32"))] #[tokio::test] async fn test_registration() { let bundle = common::setup().await; From 42d512e4a187568571eecb1d280afe4a82fc8aee Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 14:22:00 +0100 Subject: [PATCH 36/51] Rename test function to generate_general_configuration_schema_wasm --- tests/instance.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/instance.rs b/tests/instance.rs index 1ffe914f..d8658bdb 100644 --- a/tests/instance.rs +++ b/tests/instance.rs @@ -7,8 +7,8 @@ wasm_bindgen_test_configure!(run_in_browser); #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] -async fn guild_creation_deletion_wasm() { - guild_creation_deletion() +async fn generate_general_configuration_schema_wasm() { + generate_general_configuration_schema() } #[tokio::test] From 0acf3fb5f74f59a813bad06ff0f337f66aed29c1 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 14:36:00 +0100 Subject: [PATCH 37/51] Fix formatting in test functions --- tests/auth.rs | 2 +- tests/channels.rs | 12 ++++++------ tests/gateway.rs | 8 ++++---- tests/guilds.rs | 10 +++++----- tests/instance.rs | 2 +- tests/invites.rs | 2 +- tests/members.rs | 2 +- tests/messages.rs | 8 ++++---- tests/relationships.rs | 8 ++++---- tests/roles.rs | 4 ++-- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/auth.rs b/tests/auth.rs index c0ba90ff..921effa1 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -23,5 +23,5 @@ async fn test_registration() { #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_registration_wasm() { - test_registration() + test_registration(); } diff --git a/tests/channels.rs b/tests/channels.rs index 270f64f9..e67f3ddb 100644 --- a/tests/channels.rs +++ b/tests/channels.rs @@ -13,32 +13,32 @@ wasm_bindgen_test_configure!(run_in_browser); #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_get_channel_wasm() { - get_channel() + get_channel(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_delete_channel_wasm() { - delete_channel() + delete_channel(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_modify_channel_wasm() { - modify_channel() + modify_channel(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_get_channel_messages_wasm() { - get_channel_messages() + get_channel_messages(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_create_dm_wasm() { - create_dm() + create_dm(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_remove_add_person_from_to_dm_wasm() { - remove_add_person_from_to_dm() + remove_add_person_from_to_dm(); } #[tokio::test] diff --git a/tests/gateway.rs b/tests/gateway.rs index 54de74f3..d0741f99 100644 --- a/tests/gateway.rs +++ b/tests/gateway.rs @@ -13,25 +13,25 @@ wasm_bindgen_test_configure!(run_in_browser); #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_gateway_establish_wasm() { - test_gateway_establish() + test_gateway_establish(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_gateway_authenticate_wasm() { - test_gateway_authenticate() + test_gateway_authenticate(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_self_updating_structs_wasm() { - test_self_updating_structs() + test_self_updating_structs(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_recursive_self_updating_structs_wasm() { - test_recursive_self_updating_structs() + test_recursive_self_updating_structs(); } #[tokio::test] diff --git a/tests/guilds.rs b/tests/guilds.rs index fd684ddb..8537bb37 100644 --- a/tests/guilds.rs +++ b/tests/guilds.rs @@ -12,31 +12,31 @@ wasm_bindgen_test_configure!(run_in_browser); #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn guild_creation_deletion_wasm() { - guild_creation_deletion() + guild_creation_deletion(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn get_channels_wasm() { - get_channels() + get_channels(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn guild_create_ban_wasm() { - guild_create_ban() + guild_create_ban(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn modify_guild_wasm() { - modify_guild() + modify_guild(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn guild_remove_member_wasm() { - guild_remove_member() + guild_remove_member(); } #[tokio::test] diff --git a/tests/instance.rs b/tests/instance.rs index d8658bdb..77ad366e 100644 --- a/tests/instance.rs +++ b/tests/instance.rs @@ -8,7 +8,7 @@ wasm_bindgen_test_configure!(run_in_browser); #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn generate_general_configuration_schema_wasm() { - generate_general_configuration_schema() + generate_general_configuration_schema(); } #[tokio::test] diff --git a/tests/invites.rs b/tests/invites.rs index 031afeb4..99d75b88 100644 --- a/tests/invites.rs +++ b/tests/invites.rs @@ -9,7 +9,7 @@ wasm_bindgen_test_configure!(run_in_browser); #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn create_accept_invite_wasm() { - create_accept_invite() + create_accept_invite(); } #[tokio::test] diff --git a/tests/members.rs b/tests/members.rs index 0dd3616c..e7a34ed4 100644 --- a/tests/members.rs +++ b/tests/members.rs @@ -10,7 +10,7 @@ mod common; #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn add_remove_role_wasm() { - add_remove_role().unwrap() + add_remove_role().unwrap(); } #[tokio::test] diff --git a/tests/messages.rs b/tests/messages.rs index a39e9a00..43557937 100644 --- a/tests/messages.rs +++ b/tests/messages.rs @@ -13,25 +13,25 @@ mod common; #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn send_message_wasm() { - send_message() + send_message(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn send_message_attachment_wasm() { - send_message_attachment() + send_message_attachment(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn search_messages_wasm() { - search_messages() + search_messages(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_stickies_wasm() { - test_stickies() + test_stickies(); } #[tokio::test] diff --git a/tests/relationships.rs b/tests/relationships.rs index 112b47e4..e05e2fe0 100644 --- a/tests/relationships.rs +++ b/tests/relationships.rs @@ -10,25 +10,25 @@ mod common; #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_get_relationships_wasm() { - test_get_relationships() + test_get_relationships(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_get_mutual_relationships_wasm() { - test_get_mutual_relationships() + test_get_mutual_relationships(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_modify_relationship_friends_wasm() { - test_modify_relationship_friends() + test_modify_relationship_friends(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn test_modify_relationship_block_wasm() { - test_modify_relationship_block() + test_modify_relationship_block(); } #[tokio::test] diff --git a/tests/roles.rs b/tests/roles.rs index 5e85fbc0..628e4fce 100644 --- a/tests/roles.rs +++ b/tests/roles.rs @@ -10,13 +10,13 @@ mod common; #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn create_and_get_roles_wasm() { - create_and_get_roles() + create_and_get_roles(); } #[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn get_and_delete_role_wasm() { - get_and_delete_role() + get_and_delete_role(); } #[tokio::test] From 325c3d324bfe0af8d975c8e036f7f92f5f89214f Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 14:47:13 +0100 Subject: [PATCH 38/51] Spawn local gateway task on wasm32 --- src/gateway/gateway.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/gateway/gateway.rs b/src/gateway/gateway.rs index d10dbfbf..55552b8e 100644 --- a/src/gateway/gateway.rs +++ b/src/gateway/gateway.rs @@ -74,9 +74,14 @@ impl Gateway { }; // Now we can continuously check for messages in a different task, since we aren't going to receive another hello + #[cfg(not(target_arch = "wasm32"))] task::spawn(async move { gateway.gateway_listen_task().await; }); + #[cfg(target_arch = "wasm32")] + task::spawn_local(async move { + gateway.gateway_listen_task().await; + }); Ok(GatewayHandle { url: websocket_url.clone(), From f0a4fe62eb489975046d6f0d41cf34b4638c9bbc Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 14:57:45 +0100 Subject: [PATCH 39/51] Refactor heartbeat task to support WebAssembly --- src/gateway/heartbeat.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/gateway/heartbeat.rs b/src/gateway/heartbeat.rs index b8e4bec7..25f42232 100644 --- a/src/gateway/heartbeat.rs +++ b/src/gateway/heartbeat.rs @@ -33,9 +33,14 @@ impl HeartbeatHandler { let (send, receive) = tokio::sync::mpsc::channel(32); let kill_receive = kill_rc.resubscribe(); + #[cfg(not(target_arch = "wasm32"))] let handle: JoinHandle<()> = task::spawn(async move { Self::heartbeat_task(websocket_tx, heartbeat_interval, receive, kill_receive).await; }); + #[cfg(target_arch = "wasm32")] + let handle: JoinHandle<()> = task::spawn_local(move || { + Self::heartbeat_task(websocket_tx, heartbeat_interval, receive, kill_receive); + }); Self { heartbeat_interval, From 0ff02447fc3603dd2b0045b809ab4f989192e543 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 15:14:28 +0100 Subject: [PATCH 40/51] Revert "Refactor heartbeat task to support WebAssembly" This reverts commit f0a4fe62eb489975046d6f0d41cf34b4638c9bbc. --- src/gateway/heartbeat.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/gateway/heartbeat.rs b/src/gateway/heartbeat.rs index 25f42232..b8e4bec7 100644 --- a/src/gateway/heartbeat.rs +++ b/src/gateway/heartbeat.rs @@ -33,14 +33,9 @@ impl HeartbeatHandler { let (send, receive) = tokio::sync::mpsc::channel(32); let kill_receive = kill_rc.resubscribe(); - #[cfg(not(target_arch = "wasm32"))] let handle: JoinHandle<()> = task::spawn(async move { Self::heartbeat_task(websocket_tx, heartbeat_interval, receive, kill_receive).await; }); - #[cfg(target_arch = "wasm32")] - let handle: JoinHandle<()> = task::spawn_local(move || { - Self::heartbeat_task(websocket_tx, heartbeat_interval, receive, kill_receive); - }); Self { heartbeat_interval, From 1ad93e2c01be43d0525ff738439e16cd15611e47 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 15:14:34 +0100 Subject: [PATCH 41/51] Revert "Spawn local gateway task on wasm32" This reverts commit 325c3d324bfe0af8d975c8e036f7f92f5f89214f. --- src/gateway/gateway.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/gateway/gateway.rs b/src/gateway/gateway.rs index 55552b8e..d10dbfbf 100644 --- a/src/gateway/gateway.rs +++ b/src/gateway/gateway.rs @@ -74,14 +74,9 @@ impl Gateway { }; // Now we can continuously check for messages in a different task, since we aren't going to receive another hello - #[cfg(not(target_arch = "wasm32"))] task::spawn(async move { gateway.gateway_listen_task().await; }); - #[cfg(target_arch = "wasm32")] - task::spawn_local(async move { - gateway.gateway_listen_task().await; - }); Ok(GatewayHandle { url: websocket_url.clone(), From 9ddf8dde1dc8c2905743ec4e0eed0f272abb160d Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Tue, 21 Nov 2023 17:10:19 +0100 Subject: [PATCH 42/51] Add FIXME comments for wasm compatibility --- src/gateway/gateway.rs | 1 + src/gateway/heartbeat.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/gateway/gateway.rs b/src/gateway/gateway.rs index d10dbfbf..7a3a81d8 100644 --- a/src/gateway/gateway.rs +++ b/src/gateway/gateway.rs @@ -74,6 +74,7 @@ impl Gateway { }; // Now we can continuously check for messages in a different task, since we aren't going to receive another hello + // FIXME: Doesn't work in WASM task::spawn(async move { gateway.gateway_listen_task().await; }); diff --git a/src/gateway/heartbeat.rs b/src/gateway/heartbeat.rs index b8e4bec7..ea8f9652 100644 --- a/src/gateway/heartbeat.rs +++ b/src/gateway/heartbeat.rs @@ -33,6 +33,7 @@ impl HeartbeatHandler { let (send, receive) = tokio::sync::mpsc::channel(32); let kill_receive = kill_rc.resubscribe(); + // FIXME: Doesn't work in WASM let handle: JoinHandle<()> = task::spawn(async move { Self::heartbeat_task(websocket_tx, heartbeat_interval, receive, kill_receive).await; }); From e6417d8ddd3aa994f7e6b993955367081260d49d Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 22 Nov 2023 14:20:45 +0100 Subject: [PATCH 43/51] Add build instructions, especially for wasm --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index e654610a..999db506 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,25 @@ We recommend checking out the examples directory, as well as the documentation f Rust **1.67.1**. This number might change at any point while Chorus is not yet at version 1.0.0. +## Development Setup + +Make sure that you have at least Rust 1.67.1 installed. You can check your Rust version by running `cargo --version` +in your terminal. To compile for `wasm32-unknown-unknown`, you need to install the `wasm32-unknown-unknown` target. +You can do this by running `rustup target add wasm32-unknown-unknown`. + +### Testing + +In general, the tests will require you to run a local instance of the Spacebar server. You can find instructions on how +to do that [here](https://docs.spacebar.chat/setup/server/). You can find a pre-configured version of the server +[here](https://github.com/bitfl0wer/server). It is recommended to use the pre-configured version, as certain things +like "proxy connection checking" are already disabled on this version, which otherwise might break tests. + +### wasm + +To test for wasm, you will need to `cargo install wasm-pack`. You can then run +`wasm-pack test -- --headless -- --target wasm32-unknown-unknown --features="rt, client" --no-default-features` +to run the tests for wasm. + ## Versioning This crate uses Semantic Versioning 2.0.0 as its versioning scheme. You can read the specification [here](https://semver.org/spec/v2.0.0.html). From f63881dbd4f56f29deceed6620fc2304de908491 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 22 Nov 2023 14:23:33 +0100 Subject: [PATCH 44/51] Remove 'handle', add wasm friendly task spawning --- src/gateway/heartbeat.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/gateway/heartbeat.rs b/src/gateway/heartbeat.rs index ea8f9652..11765178 100644 --- a/src/gateway/heartbeat.rs +++ b/src/gateway/heartbeat.rs @@ -4,7 +4,8 @@ use std::time::{self, Duration, Instant}; use tokio::sync::mpsc::{Receiver, Sender}; use safina_timer::sleep_until; -use tokio::task::{self, JoinHandle}; +#[cfg(not(target_arch = "wasm32"))] +use tokio::task; use super::*; use crate::types; @@ -20,8 +21,6 @@ pub(super) struct HeartbeatHandler { pub heartbeat_interval: Duration, /// The send channel for the heartbeat thread pub send: Sender, - /// The handle of the thread - handle: JoinHandle<()>, } impl HeartbeatHandler { @@ -33,15 +32,18 @@ impl HeartbeatHandler { let (send, receive) = tokio::sync::mpsc::channel(32); let kill_receive = kill_rc.resubscribe(); - // FIXME: Doesn't work in WASM - let handle: JoinHandle<()> = task::spawn(async move { + #[cfg(not(target_arch = "wasm32"))] + task::spawn(async move { + Self::heartbeat_task(websocket_tx, heartbeat_interval, receive, kill_receive).await; + }); + #[cfg(target_arch = "wasm32")] + wasm_bindgen_futures::spawn_local(async move { Self::heartbeat_task(websocket_tx, heartbeat_interval, receive, kill_receive).await; }); Self { heartbeat_interval, send, - handle, } } From 233a89c6c540c25d0957b9bfc5f7faf4ca483d9a Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 22 Nov 2023 14:23:36 +0100 Subject: [PATCH 45/51] add wasm friendly task spawning --- src/gateway/gateway.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gateway/gateway.rs b/src/gateway/gateway.rs index 7a3a81d8..684b9d21 100644 --- a/src/gateway/gateway.rs +++ b/src/gateway/gateway.rs @@ -2,6 +2,7 @@ use std::time::Duration; use futures_util::{SinkExt, StreamExt}; use log::*; +#[cfg(not(target_arch = "wasm32"))] use tokio::task; use self::event::Events; @@ -74,10 +75,14 @@ impl Gateway { }; // Now we can continuously check for messages in a different task, since we aren't going to receive another hello - // FIXME: Doesn't work in WASM + #[cfg(not(target_arch = "wasm32"))] task::spawn(async move { gateway.gateway_listen_task().await; }); + #[cfg(target_arch = "wasm32")] + wasm_bindgen_futures::spawn_local(async move { + gateway.gateway_listen_task().await; + }); Ok(GatewayHandle { url: websocket_url.clone(), From 1c7e3182019533654aceb6a2f53ba54dce882b6e Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 22 Nov 2023 14:24:01 +0100 Subject: [PATCH 46/51] Add wasm-bindgen-futures --- Cargo.lock | 1 + Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 7c74e2a6..fea0bf41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -223,6 +223,7 @@ dependencies = [ "tokio-tungstenite", "url", "wasm-bindgen", + "wasm-bindgen-futures", "wasm-bindgen-test", "ws_stream_wasm", ] diff --git a/Cargo.toml b/Cargo.toml index 24a71148..8ade54c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,7 +68,7 @@ hostname = "0.3.1" [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2.11", features = ["js"] } ws_stream_wasm = "0.7.4" - +wasm-bindgen-futures = "0.4.38" [dev-dependencies] lazy_static = "1.4.0" From 383f1cafea34a0fb83e21e9b1d1bb200a0e5adc4 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 22 Nov 2023 14:24:10 +0100 Subject: [PATCH 47/51] Remove broken test code --- tests/auth.rs | 6 ------ tests/channels.rs | 30 ------------------------------ tests/gateway.rs | 24 ------------------------ tests/guilds.rs | 30 ------------------------------ tests/instance.rs | 6 ------ tests/invites.rs | 6 ------ tests/members.rs | 6 ------ tests/messages.rs | 24 ------------------------ tests/relationships.rs | 24 ------------------------ tests/roles.rs | 12 ------------ 10 files changed, 168 deletions(-) diff --git a/tests/auth.rs b/tests/auth.rs index 921effa1..f73a01f1 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -19,9 +19,3 @@ async fn test_registration() { bundle.instance.clone().register_account(reg).await.unwrap(); common::teardown(bundle).await; } - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_registration_wasm() { - test_registration(); -} diff --git a/tests/channels.rs b/tests/channels.rs index e67f3ddb..d489d94a 100644 --- a/tests/channels.rs +++ b/tests/channels.rs @@ -10,36 +10,6 @@ mod common; use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] wasm_bindgen_test_configure!(run_in_browser); -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_get_channel_wasm() { - get_channel(); -} -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_delete_channel_wasm() { - delete_channel(); -} -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_modify_channel_wasm() { - modify_channel(); -} -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_get_channel_messages_wasm() { - get_channel_messages(); -} -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_create_dm_wasm() { - create_dm(); -} -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_remove_add_person_from_to_dm_wasm() { - remove_add_person_from_to_dm(); -} #[tokio::test] async fn get_channel() { diff --git a/tests/gateway.rs b/tests/gateway.rs index d0741f99..2cbbe90a 100644 --- a/tests/gateway.rs +++ b/tests/gateway.rs @@ -10,30 +10,6 @@ use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] wasm_bindgen_test_configure!(run_in_browser); -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_gateway_establish_wasm() { - test_gateway_establish(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_gateway_authenticate_wasm() { - test_gateway_authenticate(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_self_updating_structs_wasm() { - test_self_updating_structs(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_recursive_self_updating_structs_wasm() { - test_recursive_self_updating_structs(); -} - #[tokio::test] /// Tests establishing a connection (hello and heartbeats) on the local gateway; async fn test_gateway_establish() { diff --git a/tests/guilds.rs b/tests/guilds.rs index 8537bb37..78d10c9a 100644 --- a/tests/guilds.rs +++ b/tests/guilds.rs @@ -9,36 +9,6 @@ use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] wasm_bindgen_test_configure!(run_in_browser); -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn guild_creation_deletion_wasm() { - guild_creation_deletion(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn get_channels_wasm() { - get_channels(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn guild_create_ban_wasm() { - guild_create_ban(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn modify_guild_wasm() { - modify_guild(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn guild_remove_member_wasm() { - guild_remove_member(); -} - #[tokio::test] async fn guild_creation_deletion() { let mut bundle = common::setup().await; diff --git a/tests/instance.rs b/tests/instance.rs index 77ad366e..d7a2caa9 100644 --- a/tests/instance.rs +++ b/tests/instance.rs @@ -5,12 +5,6 @@ use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] wasm_bindgen_test_configure!(run_in_browser); -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn generate_general_configuration_schema_wasm() { - generate_general_configuration_schema(); -} - #[tokio::test] async fn generate_general_configuration_schema() { let bundle = common::setup().await; diff --git a/tests/invites.rs b/tests/invites.rs index 99d75b88..472b87a1 100644 --- a/tests/invites.rs +++ b/tests/invites.rs @@ -6,12 +6,6 @@ use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] wasm_bindgen_test_configure!(run_in_browser); -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn create_accept_invite_wasm() { - create_accept_invite(); -} - #[tokio::test] async fn create_accept_invite() { let mut bundle = common::setup().await; diff --git a/tests/members.rs b/tests/members.rs index e7a34ed4..c95e6fca 100644 --- a/tests/members.rs +++ b/tests/members.rs @@ -7,12 +7,6 @@ wasm_bindgen_test_configure!(run_in_browser); mod common; -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn add_remove_role_wasm() { - add_remove_role().unwrap(); -} - #[tokio::test] async fn add_remove_role() -> ChorusResult<()> { let mut bundle = common::setup().await; diff --git a/tests/messages.rs b/tests/messages.rs index 43557937..a06a615e 100644 --- a/tests/messages.rs +++ b/tests/messages.rs @@ -10,30 +10,6 @@ wasm_bindgen_test_configure!(run_in_browser); mod common; -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn send_message_wasm() { - send_message(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn send_message_attachment_wasm() { - send_message_attachment(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn search_messages_wasm() { - search_messages(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_stickies_wasm() { - test_stickies(); -} - #[tokio::test] async fn send_message() { let mut bundle = common::setup().await; diff --git a/tests/relationships.rs b/tests/relationships.rs index e05e2fe0..d013223b 100644 --- a/tests/relationships.rs +++ b/tests/relationships.rs @@ -7,30 +7,6 @@ wasm_bindgen_test_configure!(run_in_browser); mod common; -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_get_relationships_wasm() { - test_get_relationships(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_get_mutual_relationships_wasm() { - test_get_mutual_relationships(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_modify_relationship_friends_wasm() { - test_modify_relationship_friends(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn test_modify_relationship_block_wasm() { - test_modify_relationship_block(); -} - #[tokio::test] async fn test_get_mutual_relationships() { let mut bundle = common::setup().await; diff --git a/tests/roles.rs b/tests/roles.rs index 628e4fce..547db476 100644 --- a/tests/roles.rs +++ b/tests/roles.rs @@ -7,18 +7,6 @@ wasm_bindgen_test_configure!(run_in_browser); mod common; -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn create_and_get_roles_wasm() { - create_and_get_roles(); -} - -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen_test] -async fn get_and_delete_role_wasm() { - get_and_delete_role(); -} - #[tokio::test] async fn create_and_get_roles() { let mut bundle = common::setup().await; From 8bf28012e4df904518acbc2ad6a1f28f59db50b0 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 22 Nov 2023 14:39:32 +0100 Subject: [PATCH 48/51] Replace #[tokio::test] w/ wasm-ok macro calls --- tests/auth.rs | 3 ++- tests/channels.rs | 15 ++++++++++----- tests/gateway.rs | 12 ++++++++---- tests/guilds.rs | 15 ++++++++++----- tests/instance.rs | 3 ++- tests/invites.rs | 3 ++- tests/members.rs | 3 ++- tests/messages.rs | 12 ++++++++---- tests/relationships.rs | 12 ++++++++---- tests/roles.rs | 6 ++++-- 10 files changed, 56 insertions(+), 28 deletions(-) diff --git a/tests/auth.rs b/tests/auth.rs index f73a01f1..086c8bad 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -7,7 +7,8 @@ wasm_bindgen_test_configure!(run_in_browser); mod common; -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn test_registration() { let bundle = common::setup().await; let reg = RegisterSchema { diff --git a/tests/channels.rs b/tests/channels.rs index d489d94a..864165a5 100644 --- a/tests/channels.rs +++ b/tests/channels.rs @@ -11,7 +11,8 @@ use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] wasm_bindgen_test_configure!(run_in_browser); -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn get_channel() { let mut bundle = common::setup().await; let bundle_channel = bundle.channel.read().unwrap().clone(); @@ -24,7 +25,8 @@ async fn get_channel() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn delete_channel() { let mut bundle = common::setup().await; let channel_guard = bundle.channel.write().unwrap().clone(); @@ -33,7 +35,8 @@ async fn delete_channel() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn modify_channel() { const CHANNEL_NAME: &str = "beepboop"; let mut bundle = common::setup().await; @@ -91,7 +94,8 @@ async fn modify_channel() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn get_channel_messages() { let mut bundle = common::setup().await; let channel_id: Snowflake = bundle.channel.read().unwrap().id; @@ -147,7 +151,8 @@ async fn get_channel_messages() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn create_dm() { let mut bundle = common::setup().await; let other_user = bundle.create_user("integrationtestuser2").await; diff --git a/tests/gateway.rs b/tests/gateway.rs index 2cbbe90a..b564cde9 100644 --- a/tests/gateway.rs +++ b/tests/gateway.rs @@ -10,7 +10,8 @@ use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] wasm_bindgen_test_configure!(run_in_browser); -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] /// Tests establishing a connection (hello and heartbeats) on the local gateway; async fn test_gateway_establish() { let bundle = common::setup().await; @@ -19,7 +20,8 @@ async fn test_gateway_establish() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] /// Tests establishing a connection and authenticating async fn test_gateway_authenticate() { let bundle = common::setup().await; @@ -33,7 +35,8 @@ async fn test_gateway_authenticate() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn test_self_updating_structs() { let mut bundle = common::setup().await; let received_channel = bundle @@ -66,7 +69,8 @@ async fn test_self_updating_structs() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn test_recursive_self_updating_structs() { // Setup let mut bundle = common::setup().await; diff --git a/tests/guilds.rs b/tests/guilds.rs index 78d10c9a..360113dd 100644 --- a/tests/guilds.rs +++ b/tests/guilds.rs @@ -9,7 +9,8 @@ use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] wasm_bindgen_test_configure!(run_in_browser); -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn guild_creation_deletion() { let mut bundle = common::setup().await; @@ -31,7 +32,8 @@ async fn guild_creation_deletion() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn get_channels() { let mut bundle = common::setup().await; let guild = bundle.guild.read().unwrap().clone(); @@ -39,7 +41,8 @@ async fn get_channels() { common::teardown(bundle).await; } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn guild_create_ban() { // TODO: When routes exist to check if user x is on guild y, add this as an assertion to check // if Spacebar actually bans the user. @@ -76,7 +79,8 @@ async fn guild_create_ban() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn modify_guild() { let mut bundle = common::setup().await; let schema = GuildModifySchema { @@ -91,7 +95,8 @@ async fn modify_guild() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn guild_remove_member() { let mut bundle = common::setup().await; let channel = bundle.channel.read().unwrap().clone(); diff --git a/tests/instance.rs b/tests/instance.rs index d7a2caa9..56f4d6d4 100644 --- a/tests/instance.rs +++ b/tests/instance.rs @@ -5,7 +5,8 @@ use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] wasm_bindgen_test_configure!(run_in_browser); -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn generate_general_configuration_schema() { let bundle = common::setup().await; bundle diff --git a/tests/invites.rs b/tests/invites.rs index 472b87a1..d830ee8c 100644 --- a/tests/invites.rs +++ b/tests/invites.rs @@ -6,7 +6,8 @@ use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] wasm_bindgen_test_configure!(run_in_browser); -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn create_accept_invite() { let mut bundle = common::setup().await; let channel = bundle.channel.read().unwrap().clone(); diff --git a/tests/members.rs b/tests/members.rs index c95e6fca..c9072efd 100644 --- a/tests/members.rs +++ b/tests/members.rs @@ -7,7 +7,8 @@ wasm_bindgen_test_configure!(run_in_browser); mod common; -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn add_remove_role() -> ChorusResult<()> { let mut bundle = common::setup().await; let guild = bundle.guild.read().unwrap().id; diff --git a/tests/messages.rs b/tests/messages.rs index a06a615e..8228aa70 100644 --- a/tests/messages.rs +++ b/tests/messages.rs @@ -10,7 +10,8 @@ wasm_bindgen_test_configure!(run_in_browser); mod common; -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn send_message() { let mut bundle = common::setup().await; let message = types::MessageSendSchema { @@ -22,7 +23,8 @@ async fn send_message() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn send_message_attachment() { let f = File::open("./README.md").unwrap(); let mut reader = BufReader::new(f); @@ -59,7 +61,8 @@ async fn send_message_attachment() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn search_messages() { let f = File::open("./README.md").unwrap(); let mut reader = BufReader::new(f); @@ -105,7 +108,8 @@ async fn search_messages() { assert_eq!(query_result.get(0).unwrap().id, message.id); } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn test_stickies() { let mut bundle = common::setup().await; let message = types::MessageSendSchema { diff --git a/tests/relationships.rs b/tests/relationships.rs index d013223b..156f6ebc 100644 --- a/tests/relationships.rs +++ b/tests/relationships.rs @@ -7,7 +7,8 @@ wasm_bindgen_test_configure!(run_in_browser); mod common; -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn test_get_mutual_relationships() { let mut bundle = common::setup().await; let mut other_user = bundle.create_user("integrationtestuser2").await; @@ -28,7 +29,8 @@ async fn test_get_mutual_relationships() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn test_get_relationships() { let mut bundle = common::setup().await; let mut other_user = bundle.create_user("integrationtestuser2").await; @@ -51,7 +53,8 @@ async fn test_get_relationships() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn test_modify_relationship_friends() { let mut bundle = common::setup().await; let mut other_user = bundle.create_user("integrationtestuser2").await; @@ -102,7 +105,8 @@ async fn test_modify_relationship_friends() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn test_modify_relationship_block() { let mut bundle = common::setup().await; let mut other_user = bundle.create_user("integrationtestuser2").await; diff --git a/tests/roles.rs b/tests/roles.rs index 547db476..ca58582c 100644 --- a/tests/roles.rs +++ b/tests/roles.rs @@ -7,7 +7,8 @@ wasm_bindgen_test_configure!(run_in_browser); mod common; -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn create_and_get_roles() { let mut bundle = common::setup().await; let permissions = types::PermissionFlags::CONNECT | types::PermissionFlags::MANAGE_EVENTS; @@ -36,7 +37,8 @@ async fn create_and_get_roles() { common::teardown(bundle).await } -#[tokio::test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn get_and_delete_role() { let mut bundle = common::setup().await; let guild_id = bundle.guild.read().unwrap().id; From 60419473e2cc3fe21a553598565cad1d9480519f Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 22 Nov 2023 14:52:49 +0100 Subject: [PATCH 49/51] Add fixme note about tests requiring std::fs --- tests/messages.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/messages.rs b/tests/messages.rs index 8228aa70..fc59a42d 100644 --- a/tests/messages.rs +++ b/tests/messages.rs @@ -26,6 +26,9 @@ async fn send_message() { #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn send_message_attachment() { + /// FIXME: Fix this test for wasm32. wasm32-unknown-unknown does not have a filesystem and therefore cannot read files. + #[cfg(target_arch = "wasm32")] + return; let f = File::open("./README.md").unwrap(); let mut reader = BufReader::new(f); let mut buffer = Vec::new(); @@ -64,6 +67,9 @@ async fn send_message_attachment() { #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn search_messages() { + /// FIXME: Fix this test for wasm32. wasm32-unknown-unknown does not have a filesystem and therefore cannot read files. + #[cfg(target_arch = "wasm32")] + return; let f = File::open("./README.md").unwrap(); let mut reader = BufReader::new(f); let mut buffer = Vec::new(); From 889db105daa6ea05909e1d4ee09622e62aa0b268 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 22 Nov 2023 15:01:51 +0100 Subject: [PATCH 50/51] Update supported platforms in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 999db506..e4350862 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ dbg!(&user.object.read().unwrap().username); ## Supported Platforms All major desktop operating systems (Windows, macOS (aarch64/x86_64), Linux (aarch64/x86_64)) are supported. -We are currently working on adding full support for `wasm32-unknown-unknown`. This will allow you to use Chorus in +`wasm32-unknown-unknown` is a supported compilation target on versions `>0.11.0`. This allows you to use Chorus in your browser, or in any other environment that supports WebAssembly. We recommend checking out the examples directory, as well as the documentation for more information. From 14bbeb328a0e4875c1233b1f0fa597e93b77b1ac Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 22 Nov 2023 15:13:26 +0100 Subject: [PATCH 51/51] Split up wasm-tests into 3 seperate tests --- .github/workflows/build_and_test.yml | 56 +++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index c0e314fc..cefd2600 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -45,7 +45,7 @@ jobs: cargo build --verbose --all-features cargo test --verbose --all-features fi - macos: + wasm-safari: runs-on: macos-latest steps: - uses: actions/checkout@v4 @@ -73,5 +73,59 @@ jobs: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + wasm-gecko: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Clone spacebar server + run: | + git clone https://github.com/bitfl0wer/server.git + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'npm' + cache-dependency-path: server/package-lock.json + - name: Prepare and start Spacebar server + run: | + npm install + npm run setup + npm run start & + working-directory: ./server + - uses: Swatinem/rust-cache@v2 + with: + cache-all-crates: "true" + prefix-key: "macos" + - name: Run WASM tests with Safari, Firefox, Chrome + run: | + rustup target add wasm32-unknown-unknown + curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash + cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force GECKODRIVER=$(which geckodriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + wasm-chrome: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Clone spacebar server + run: | + git clone https://github.com/bitfl0wer/server.git + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'npm' + cache-dependency-path: server/package-lock.json + - name: Prepare and start Spacebar server + run: | + npm install + npm run setup + npm run start & + working-directory: ./server + - uses: Swatinem/rust-cache@v2 + with: + cache-all-crates: "true" + prefix-key: "macos" + - name: Run WASM tests with Safari, Firefox, Chrome + run: | + rustup target add wasm32-unknown-unknown + curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash + cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force CHROMEDRIVER=$(which chromedriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" \ No newline at end of file