Browser selection for wasm tests (#3994)

This commit is contained in:
Michał Wawrzyniec Urbańczyk 2022-12-21 05:35:42 +01:00 committed by GitHub
parent 9a173cb8d6
commit 622c7ce326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 144 additions and 26 deletions

93
Cargo.lock generated
View File

@ -1081,27 +1081,27 @@ dependencies = [
[[package]]
name = "clap"
version = "3.1.15"
version = "3.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85a35a599b11c089a7f49105658d089b8f2cf0882993c17daf6de15285c2c35d"
checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5"
dependencies = [
"atty",
"bitflags",
"clap_derive",
"clap_lex",
"indexmap",
"lazy_static",
"once_cell",
"strsim",
"termcolor",
"terminal_size",
"textwrap 0.15.0",
"terminal_size 0.2.3",
"textwrap 0.16.0",
]
[[package]]
name = "clap_derive"
version = "3.1.7"
version = "3.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3aab4734e083b809aaf5794e14e756d1c798d2c69c7f7de7a09a2f5214993c1"
checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65"
dependencies = [
"heck",
"proc-macro-error",
@ -1196,7 +1196,7 @@ dependencies = [
"encode_unicode",
"libc",
"once_cell",
"terminal_size",
"terminal_size 0.1.17",
"unicode-width",
"winapi 0.3.9",
]
@ -1827,7 +1827,7 @@ dependencies = [
"cached",
"cfg-if 1.0.0",
"chrono",
"clap 3.1.15",
"clap 3.2.23",
"console-subscriber",
"derivative",
"derive_more",
@ -1908,7 +1908,7 @@ dependencies = [
"anyhow",
"byte-unit",
"chrono",
"clap 3.1.15",
"clap 3.2.23",
"derivative",
"enso-build",
"enso-build-base",
@ -3063,6 +3063,27 @@ dependencies = [
"termcolor",
]
[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [
"errno-dragonfly",
"libc",
"winapi 0.3.9",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "event-listener"
version = "2.5.3"
@ -3856,7 +3877,7 @@ dependencies = [
"cached",
"cfg-if 1.0.0",
"chrono",
"clap 3.1.15",
"clap 3.2.23",
"convert_case 0.6.0",
"cron",
"data-encoding",
@ -4164,6 +4185,16 @@ dependencies = [
"toml",
]
[[package]]
name = "io-lifetimes"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c"
dependencies = [
"libc",
"windows-sys 0.42.0",
]
[[package]]
name = "iovec"
version = "0.1.4"
@ -4376,6 +4407,12 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
[[package]]
name = "linux-raw-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
[[package]]
name = "lock_api"
version = "0.3.4"
@ -4418,7 +4455,7 @@ dependencies = [
name = "logstat"
version = "0.1.0"
dependencies = [
"clap 3.1.15",
"clap 3.2.23",
"enso-prelude",
"lazy_static",
"regex",
@ -5885,6 +5922,20 @@ dependencies = [
"semver 1.0.14",
]
[[package]]
name = "rustix"
version = "0.36.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3807b5d10909833d3e9acd1eb5fb988f79376ff10fce42937de71a449c4c588"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys 0.42.0",
]
[[package]]
name = "rustls"
version = "0.19.1"
@ -6578,6 +6629,16 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "terminal_size"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb20089a8ba2b69debd491f8d2d023761cbf196e999218c591fa1e7e15a21907"
dependencies = [
"rustix",
"windows-sys 0.42.0",
]
[[package]]
name = "termtree"
version = "0.2.4"
@ -6595,11 +6656,11 @@ dependencies = [
[[package]]
name = "textwrap"
version = "0.15.0"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d"
dependencies = [
"terminal_size",
"terminal_size 0.2.3",
]
[[package]]
@ -7853,7 +7914,7 @@ name = "wstest"
version = "0.1.0"
dependencies = [
"base64 0.13.0",
"clap 3.1.15",
"clap 3.2.23",
"either",
"enso-prelude",
"futures 0.3.24",

View File

@ -1,5 +1,6 @@
//! Example scene showing a documentation panel of the component browser.
use ensogl::display::shape::*;
use ensogl::prelude::*;
use wasm_bindgen::prelude::*;
@ -8,12 +9,12 @@ use crate::mock_suggestion_database;
use crate::model::suggestion_database;
use crate::model::suggestion_database::Entry;
use crate::model::SuggestionDatabase;
use ensogl::application::Application;
use ensogl::data::color;
use ensogl::display;
use ensogl::display::navigation::navigator::Navigator;
use ensogl::display::shape::StyleWatchFrp;
use ensogl::display::shape::*;
use ensogl::frp;
use ensogl::shape;
use ensogl::system::web;

View File

@ -391,7 +391,7 @@ impl Wasm {
.await
}
pub async fn test(&self, repo_root: PathBuf, wasm: bool, native: bool) -> Result {
pub async fn test(&self, repo_root: PathBuf, wasm: &[test::Browser], native: bool) -> Result {
async fn maybe_run<Fut: Future<Output = Result>>(
name: &str,
enabled: bool,
@ -421,7 +421,7 @@ impl Wasm {
})
.await?;
maybe_run("wasm", wasm, || test::test_all(repo_root.clone())).await?;
maybe_run("wasm", !wasm.is_empty(), || test::test_all(repo_root.clone(), wasm)).await?;
Ok(())
}

View File

@ -1,12 +1,16 @@
use crate::project::*;
use anyhow::Context;
use clap::ArgEnum;
use ide_ci::programs::cargo;
use ide_ci::programs::wasm_pack;
use ide_ci::programs::WasmPack;
// =================
// === Constants ===
// =================
/// Flag that tells wasm-pack which browser should be used to run tests.
///
/// We use here Firefox rather than Chrome, because it is more stable. Chrome for some reason has
@ -22,6 +26,42 @@ pub const WASM_TEST_ATTRIBUTES: [&str; 2] = ["#[wasm_bindgen_test]", "#[wasm_bin
/// Subdirectories in the crate directory that contain sources for the crate.
pub const SOURCE_SUBDIRECTORIES: [&str; 4] = ["src", "benches", "examples", "tests"];
// ===============
// === Browser ===
// ===============
/// Select which browser should be used to run wasm tests.
///
/// In principle, wasm-pack is fine with passing multiple ones in a single call.
#[derive(ArgEnum, Clone, Copy, Debug, PartialEq, Eq)]
pub enum Browser {
/// Run tests in Chrome using `chromedriver`. <https://chromedriver.chromium.org/downloads>
Chrome,
/// Run tests in Edge using `msedgedriver`. <https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/>
Edge,
/// Run tests in Firefox using `geckodriver`.<https://github.com/mozilla/geckodriver/releases>
Firefox,
/// Run tests in Safari using `safaridriver`. It should come preinstalled on OSX.
Safari,
}
impl From<Browser> for wasm_pack::TestFlags {
fn from(browser: Browser) -> Self {
match browser {
Browser::Chrome => Self::Chrome,
// We treat Edge as Chrome, see: <https://github.com/rustwasm/wasm-pack/issues/1172>
Browser::Edge => Self::Chrome,
Browser::Firefox => Self::Firefox,
Browser::Safari => Self::Safari,
}
}
}
// =========================
// === Package discovery ===
// =========================
/// Lists members of given Cargo.toml workspace.
pub fn get_all_crates(repo_root: impl AsRef<Path>) -> Result<Vec<PathBuf>> {
let pattern = repo_root.as_ref().join("**/Cargo.toml");
@ -91,7 +131,13 @@ pub fn get_proc_macro(cargo_toml: toml::Value) -> Option<bool> {
cargo_toml.get("lib")?.get("proc-macro")?.as_bool()
}
pub async fn test_all(repo_root: PathBuf) -> Result {
// =====================
// === Running tests ===
// =====================
/// Run wasm tests on all crates in the workspace.
pub async fn test_all(repo_root: PathBuf, browsers: &[Browser]) -> Result {
let browser_flags = browsers.iter().copied().map_into::<wasm_pack::TestFlags>().collect_vec();
// FIXME args
//let wasm_pack_args = std::env::args().skip(1).collect::<Vec<_>>();
let all_members = get_all_crates(&repo_root)?;
@ -109,7 +155,7 @@ pub async fn test_all(repo_root: PathBuf) -> Result {
.current_dir(&repo_root)
.test()
.apply(&wasm_pack::TestFlags::Headless)
.apply(&BROWSER_FOR_WASM_TESTS)
.apply_iter(browser_flags.iter().copied())
.env("WASM_BINDGEN_TEST_TIMEOUT", "300")
// .args(&wasm_pack_args)
.arg(member.strip_prefix(&repo_root).with_context(|| {

View File

@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.57"
byte-unit = { version = "4.0.14", features = ["serde"] }
clap = { version = "3.1.5", features = ["derive", "env", "wrap_help"] }
clap = { version = "3.2.23", features = ["derive", "env", "wrap_help"] }
chrono = "0.4.19"
derivative = "2.2.0"
enso-build-base = { path = "../base" }

View File

@ -10,6 +10,7 @@ use crate::IsWatchableSource;
use clap::ArgEnum;
use clap::Args;
use clap::Subcommand;
use enso_build::project::wasm::test::Browser;
use enso_build::project::wasm::Wasm;
use std::sync::OnceLock;
@ -104,7 +105,7 @@ pub struct WatchInput {
pub enum Command {
/// Build the WASM package.
Build(BuildJob<Wasm>),
/// Lint the coodebase.
/// Lint the codebase.
Check,
/// Get the WASM artifacts from arbitrary source (e.g. release).
Get(Source<Wasm>),
@ -118,6 +119,11 @@ pub enum Command {
/// Skip the WASM Rust tests.
#[clap(long)]
no_wasm: bool,
/// Which browsers should be used to run WASM tests.
///
/// More than one browser can be specified.
#[clap(long, enso_env(), arg_enum, default_values_t = [Browser::Firefox])]
browser: Vec<Browser>,
},
}

View File

@ -312,8 +312,12 @@ impl Processor {
arg::wasm::Command::Watch(job) => self.watch_and_wait(job),
arg::wasm::Command::Build(job) => self.build(job).void_ok().boxed(),
arg::wasm::Command::Check => Wasm.check().boxed(),
arg::wasm::Command::Test { no_wasm, no_native } =>
Wasm.test(self.repo_root.to_path_buf(), !no_wasm, !no_native).boxed(),
arg::wasm::Command::Test { no_wasm, no_native, browser } => {
let wasm_browsers =
if no_wasm { default() } else { browser.into_iter().map_into().collect_vec() };
let root = self.repo_root.to_path_buf();
async move { Wasm.test(root, &wasm_browsers, !no_native).await }.boxed()
}
arg::wasm::Command::Get(source) => self.get(source).void_ok().boxed(),
}
}