From aa9dcad4375962361ef62188e0a53de47425c2d2 Mon Sep 17 00:00:00 2001 From: Vincent Herlemont Date: Thu, 28 Dec 2023 13:46:23 +0100 Subject: [PATCH] fix: add target wasm32-unknown-unknown --- .github/workflows/build_test_wasm.yml | 2 ++ Cargo.toml | 14 ++++++++++---- justfile | 2 ++ tests/convert_all.rs | 2 ++ tests/{util.rs => create.rs} | 1 + tests/modules.rs | 1 + tests/native_model.rs | 1 + tests/scan.rs | 1 + tests/simple_multithreads.rs | 2 ++ tests/snapshot.rs | 2 ++ tests/transaction.rs | 2 ++ tests/wasm.rs | 12 ++++++++++++ tests/watch_tokio.rs | 1 + 13 files changed, 39 insertions(+), 4 deletions(-) rename tests/{util.rs => create.rs} (96%) create mode 100644 tests/wasm.rs diff --git a/.github/workflows/build_test_wasm.yml b/.github/workflows/build_test_wasm.yml index 28f38d77..3146dff1 100644 --- a/.github/workflows/build_test_wasm.yml +++ b/.github/workflows/build_test_wasm.yml @@ -24,6 +24,8 @@ jobs: with: toolchain: ${{ matrix.toolchain }} override: true + - name: Add target + run: rustup target add wasm32-unknown-unknown - uses: extractions/setup-just@v1 - uses: hustcer/setup-nu@v3.8 with: diff --git a/Cargo.toml b/Cargo.toml index 9c067569..d91f61b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,20 +29,26 @@ tokio = { version = "1", features = ["sync"], optional = true } # TODO: channels with futures # TODO: channels crossbeam -[dev-dependencies] +[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] assert_fs = "1.1" -serial_test = { version = "3.0", features = ["file_locks"] } shortcut_assert_fs = { version = "0.1.0" } +serial_test = { version = "3.0", features = ["file_locks"] } +criterion = { version = "0.5.1" } + +[target.'cfg(target_arch = "wasm32")'.dev-dependencies] +wasm-bindgen-test = "0.3.0" + +[dev-dependencies] skeptic = "0.13" tokio = { version = "1.37", features = ["test-util","macros"] } bincode = { version = "2.0.0-rc.3", features = ["serde"] } -criterion = { version = "0.5.1" } doc-comment = "0.3.3" -uuid = { version = "1", features = ["serde", "v4"] } +uuid = { version = "1", features = ["serde", "v4", "js"] } chrono = { version = "0.4", features = ["serde"] } rand = "0.8" once_cell = "1.19" + [features] default = [] diff --git a/justfile b/justfile index 14688f13..620273c3 100644 --- a/justfile +++ b/justfile @@ -34,6 +34,8 @@ test_all *args: just test_default {{args}}; just test_with_optional {{args}} +test_wasm: + cargo test --target wasm32-unknown-unknown # List all available devices test_mobile_all_devices: diff --git a/tests/convert_all.rs b/tests/convert_all.rs index 3ab8f2b1..e4c285b6 100644 --- a/tests/convert_all.rs +++ b/tests/convert_all.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_arch = "wasm32"))] + use native_db::*; use native_model::{native_model, Model}; use serde::{Deserialize, Serialize}; diff --git a/tests/util.rs b/tests/create.rs similarity index 96% rename from tests/util.rs rename to tests/create.rs index f75c76cd..edb10373 100644 --- a/tests/util.rs +++ b/tests/create.rs @@ -1,3 +1,4 @@ +#![cfg(not(target_arch = "wasm32"))] use native_db::*; use shortcut_assert_fs::TmpFs; diff --git a/tests/modules.rs b/tests/modules.rs index 907800e1..9769bd42 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -1,3 +1,4 @@ +#![cfg(not(target_arch = "wasm32"))] mod custom_type; mod macro_def; mod migrate; diff --git a/tests/native_model.rs b/tests/native_model.rs index 8f7fb942..2583f8c3 100644 --- a/tests/native_model.rs +++ b/tests/native_model.rs @@ -1,3 +1,4 @@ +#![cfg(not(target_arch = "wasm32"))] use bincode; use bincode::{config, Decode, Encode}; use native_db::*; diff --git a/tests/scan.rs b/tests/scan.rs index 0a02f36f..8cc3d8f6 100644 --- a/tests/scan.rs +++ b/tests/scan.rs @@ -1,3 +1,4 @@ +#![cfg(not(target_arch = "wasm32"))] // TODO: refactor and move to query/ folder use native_db::*; diff --git a/tests/simple_multithreads.rs b/tests/simple_multithreads.rs index b1be3ccc..842aea45 100644 --- a/tests/simple_multithreads.rs +++ b/tests/simple_multithreads.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_arch = "wasm32"))] + use native_db::*; use native_model::{native_model, Model}; use serde::{Deserialize, Serialize}; diff --git a/tests/snapshot.rs b/tests/snapshot.rs index 226422f0..e3b1c1b1 100644 --- a/tests/snapshot.rs +++ b/tests/snapshot.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_arch = "wasm32"))] + use native_db::*; use native_model::{native_model, Model}; use serde::{Deserialize, Serialize}; diff --git a/tests/transaction.rs b/tests/transaction.rs index 40ad6637..7abab124 100644 --- a/tests/transaction.rs +++ b/tests/transaction.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_arch = "wasm32"))] + use native_db::*; use native_model::{native_model, Model}; use serde::{Deserialize, Serialize}; diff --git a/tests/wasm.rs b/tests/wasm.rs new file mode 100644 index 00000000..c5f225c9 --- /dev/null +++ b/tests/wasm.rs @@ -0,0 +1,12 @@ +#![cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; + +#[wasm_bindgen_test] +fn pass() { + assert_eq!(1, 1); +} + +#[wasm_bindgen_test] +fn fail() { + assert_eq!(1, 2); +} \ No newline at end of file diff --git a/tests/watch_tokio.rs b/tests/watch_tokio.rs index 52eb24ff..6671a4b1 100644 --- a/tests/watch_tokio.rs +++ b/tests/watch_tokio.rs @@ -1,3 +1,4 @@ +#![cfg(not(target_arch = "wasm32"))] #![cfg(feature = "tokio")] use native_db::watch::Event;