From c0fc7c9f7ea53777d304b2fb78c42d678955aa74 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 27 Apr 2022 16:50:27 +0200 Subject: [PATCH] chore: Adding ci-subcommand to xtask for testing --- xtask/src/ci.rs | 94 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 3 deletions(-) diff --git a/xtask/src/ci.rs b/xtask/src/ci.rs index 82a188746..c43d9d962 100644 --- a/xtask/src/ci.rs +++ b/xtask/src/ci.rs @@ -36,6 +36,11 @@ enum CiCommand { #[clap(subcommand)] cmd: Option, }, + /// Run wasm-pack tests + WasmPack { + #[clap(subcommand)] + cmd: Option, + }, /// Run tests for the different crypto crate features TestCrypto, } @@ -61,7 +66,10 @@ enum WasmFeatureSet { MatrixSdkBase, MatrixSdkCommon, MatrixSdkCrypto, + MatrixSdkIndexeddbStoresNoCrypto, MatrixSdkIndexeddbStores, + IndexeddbNoCrypto, + IndexeddbWithCrypto, MatrixSdkCommandBot, } @@ -79,6 +87,7 @@ impl CiArgs { CiCommand::TestFeatures { cmd } => run_feature_tests(cmd), CiCommand::TestAppservice => run_appservice_tests(), CiCommand::Wasm { cmd } => run_wasm_checks(cmd), + CiCommand::WasmPack { cmd } => run_wasm_pack_tests(cmd), CiCommand::TestCrypto => run_crypto_tests(), }, None => { @@ -192,17 +201,27 @@ fn run_wasm_checks(cmd: Option) -> Result<()> { (WasmFeatureSet::MatrixQrcode, "-p matrix-qrcode"), ( WasmFeatureSet::MatrixSdkNoDefault, - "-p matrix-sdk \ - --no-default-features \ - --features qrcode,encryption,indexeddb-state-store,indexeddb-crypto-store,rustls-tls", + "-p matrix-sdk --no-default-features --features rustls-tls", ), (WasmFeatureSet::MatrixSdkBase, "-p matrix-sdk-base"), (WasmFeatureSet::MatrixSdkCommon, "-p matrix-sdk-common"), (WasmFeatureSet::MatrixSdkCrypto, "-p matrix-sdk-crypto"), + ( + WasmFeatureSet::MatrixSdkIndexeddbStoresNoCrypto, + "-p matrix-sdk --no-default-features --features indexeddb-state-store,rustls-tls", + ), ( WasmFeatureSet::MatrixSdkIndexeddbStores, "-p matrix-sdk --no-default-features --features indexeddb-state-store,indexeddb-crypto-store,encryption,rustls-tls", ), + ( + WasmFeatureSet::IndexeddbNoCrypto, + "-p matrix-sdk-indexeddb --no-default-features --features state-store", + ), + ( + WasmFeatureSet::IndexeddbWithCrypto, + "-p matrix-sdk-indexeddb --no-default-features --features state-store,crypto-store", + ), ]); let run = |arg_set: &str| { @@ -241,6 +260,75 @@ fn run_wasm_checks(cmd: Option) -> Result<()> { Ok(()) } + +fn run_wasm_pack_tests(cmd: Option) -> Result<()> { + let args = BTreeMap::from([ + (WasmFeatureSet::MatrixQrcode, ("matrix-qrcode", "")), + ( + WasmFeatureSet::MatrixSdkNoDefault, ("matrix-sdk", "--no-default-features --features rustls-tls --lib") + ), + (WasmFeatureSet::MatrixSdkBase, ("matrix-sdk-base", "")), + (WasmFeatureSet::MatrixSdkCommon, ("matrix-sdk-common", "")), + (WasmFeatureSet::MatrixSdkCrypto, ("matrix-sdk-crypto", "")), + ( + WasmFeatureSet::MatrixSdkIndexeddbStoresNoCrypto, ( + "matrix-sdk", "--no-default-features --features indexeddb-state-store,rustls-tls", + ) + ), + ( + WasmFeatureSet::MatrixSdkIndexeddbStores, ( + "matrix-sdk", "--no-default-features --features indexeddb-state-store,indexeddb-crypto-store,encryption,rustls-tls --lib", + ) + ), + ( + WasmFeatureSet::IndexeddbNoCrypto, ( + "matrix-sdk-indexeddb", "--no-default-features --features state-store", + ) + ), + ( + WasmFeatureSet::IndexeddbWithCrypto, ( + "matrix-sdk-indexeddb", "--no-default-features --features state-store,crypto-store", + ) + ), + ]); + + let run = |(folder, arg_set) : (&str, &str)| { + let _p = pushd(format!("crates/{}", folder)); + cmd!("pwd").run()?; // print dir so we know what might have failed + cmd!("wasm-pack test --node -- ") + .args(arg_set.split_whitespace()) + .run()?; + cmd!("wasm-pack test --firefox --headless --") + .args(arg_set.split_whitespace()) + .run() + }; + + let test_command_bot = || { + let _p = pushd("crates/matrix-sdk/examples/wasm_command_bot"); + cmd!("wasm-pack test --node").run()?; + cmd!("wasm-pack test --firefox --headless").run() + }; + + match cmd { + Some(cmd) => match cmd { + WasmFeatureSet::MatrixSdkCommandBot => { + test_command_bot()?; + } + _ => { + run(args[&cmd])?; + } + }, + None => { + for &arg_set in args.values() { + run(arg_set)?; + } + + test_command_bot()?; + } + } + + Ok(()) +} fn workspace_root() -> Result { #[derive(Deserialize)] struct Metadata {