Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WASM tests #444

Merged
merged 44 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9372e32
Give tungstenite types distinct names
bitfl0wer Nov 19, 2023
73e40ca
reorganize files
bitfl0wer Nov 19, 2023
ec38130
Better feature locking, add wasm.rs
bitfl0wer Nov 19, 2023
984fdac
Implement wasm Backend
bitfl0wer Nov 19, 2023
dc0c2ee
add wasm-bindgen-test
bitfl0wer Nov 19, 2023
1bcf54c
Build & Test for wasm
bitfl0wer Nov 19, 2023
d0bc0bb
Add macos safari wasm test
bitfl0wer Nov 19, 2023
ced6496
Add wasm32 target
bitfl0wer Nov 19, 2023
2690819
Add wasm.rs test
bitfl0wer Nov 19, 2023
ce9c1d5
Move wasm-pack installation before test execution
bitfl0wer Nov 19, 2023
81091eb
Fix build on wasm32
bitfl0wer Nov 19, 2023
0782f25
Fix examples depending on tokio::time
bitfl0wer Nov 19, 2023
2543427
fix clippy warn
bitfl0wer Nov 19, 2023
3e2152d
Merge branch 'dev' into feature/wasm32-unknown
bitfl0wer Nov 19, 2023
a811031
Add example wasm bindgen test
bitfl0wer Nov 19, 2023
c456d65
Add wasm-bindgen to Cargo.toml
bitfl0wer Nov 20, 2023
62e9123
Add wasm test configuration
bitfl0wer Nov 20, 2023
c9d4ecd
Install wasm-bindgen-cli on linux
bitfl0wer Nov 20, 2023
7f94b8e
Add wasm-bindgen-cli to macos
bitfl0wer Nov 20, 2023
a52dd1e
Correct "vers" to "version"
bitfl0wer Nov 20, 2023
401249b
Attempt to locate correct geckodriver
bitfl0wer Nov 20, 2023
a2834b2
Run wasm tests first
bitfl0wer Nov 20, 2023
083f438
maybe this will fix ci :clueless:
bitfl0wer Nov 20, 2023
7862c5f
Move wasm-bindgen-cli install
bitfl0wer Nov 20, 2023
7e4f60b
Add cargo-binstall installation script for
bitfl0wer Nov 20, 2023
608629a
Try using only one browser
bitfl0wer Nov 20, 2023
c492f85
remove geckodriver
bitfl0wer Nov 20, 2023
79d97a1
Move all wasm related tests to macos
bitfl0wer Nov 20, 2023
31136ad
Rename macOS test step for clarity
bitfl0wer Nov 20, 2023
584fd21
Try out combined coverage report
bitfl0wer Nov 20, 2023
cae64ae
try different strategy to skip coverage on forks
bitfl0wer Nov 20, 2023
06574c2
Revert "try different strategy to skip coverage on forks"
bitfl0wer Nov 20, 2023
5e20d77
Revert "Try out combined coverage report"
bitfl0wer Nov 20, 2023
4288455
Add tests for WASM
bitfl0wer Nov 20, 2023
c985882
Merge branch 'dev' into feature/wasm32-unknown
bitfl0wer Nov 20, 2023
8eee0c8
remove all .await from wasm tests
bitfl0wer Nov 20, 2023
ebb414c
Remove unnecessary code
bitfl0wer Nov 20, 2023
42d512e
Rename test function to
bitfl0wer Nov 20, 2023
0acf3fb
Fix formatting in test functions
bitfl0wer Nov 20, 2023
325c3d3
Spawn local gateway task on wasm32
bitfl0wer Nov 20, 2023
f0a4fe6
Refactor heartbeat task to support WebAssembly
bitfl0wer Nov 20, 2023
0ff0244
Revert "Refactor heartbeat task to support WebAssembly"
bitfl0wer Nov 20, 2023
1ad93e2
Revert "Spawn local gateway task on wasm32"
bitfl0wer Nov 20, 2023
9ddf8dd
Add FIXME comments for wasm compatibility
bitfl0wer Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/gateway/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
1 change: 1 addition & 0 deletions src/gateway/heartbeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
11 changes: 11 additions & 0 deletions tests/auth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
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;

Expand All @@ -14,3 +19,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();
}
36 changes: 36 additions & 0 deletions tests/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
#[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() {
Expand Down
29 changes: 29 additions & 0 deletions tests/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

#[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;
Expand Down
35 changes: 35 additions & 0 deletions tests/guilds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

#[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() {
Expand Down
11 changes: 11 additions & 0 deletions tests/instance.rs
Original file line number Diff line number Diff line change
@@ -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 generate_general_configuration_schema_wasm() {
generate_general_configuration_schema();
}

#[tokio::test]
async fn generate_general_configuration_schema() {
Expand Down
12 changes: 12 additions & 0 deletions tests/invites.rs
Original file line number Diff line number Diff line change
@@ -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();
}

#[tokio::test]
async fn create_accept_invite() {
let mut bundle = common::setup().await;
Expand Down
11 changes: 11 additions & 0 deletions tests/members.rs
Original file line number Diff line number Diff line change
@@ -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().unwrap();
}

#[tokio::test]
async fn add_remove_role() -> ChorusResult<()> {
let mut bundle = common::setup().await;
Expand Down
29 changes: 29 additions & 0 deletions tests/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

#[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;
Expand Down
29 changes: 29 additions & 0 deletions tests/relationships.rs
Original file line number Diff line number Diff line change
@@ -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();
}

#[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;
Expand Down
17 changes: 17 additions & 0 deletions tests/roles.rs
Original file line number Diff line number Diff line change
@@ -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();
}

#[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;
Expand Down
Loading