diff --git a/Cargo.lock b/Cargo.lock index 4ef603c2..23f52ca6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,6 +36,17 @@ dependencies = [ "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "assert_cmd" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "escargot 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "predicates 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "predicates-tree 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "atty" version = "0.2.11" @@ -289,6 +300,11 @@ dependencies = [ "tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "difference" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "dirs" version = "1.0.4" @@ -323,6 +339,15 @@ dependencies = [ "backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "escargot" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "failure" version = "0.1.5" @@ -364,6 +389,14 @@ dependencies = [ "miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "float-cmp" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "foreign-types" version = "0.3.2" @@ -562,6 +595,16 @@ name = "nodrop" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "normalize-line-endings" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num-traits" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "openssl" version = "0.10.16" @@ -668,6 +711,32 @@ name = "podio" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "predicates" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "float-cmp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "normalize-line-endings 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "predicates-core" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "predicates-tree" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "proc-macro2" version = "0.4.24" @@ -951,6 +1020,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "serde" version = "1.0.84" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde_derive 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "serde_derive" @@ -1173,6 +1245,11 @@ dependencies = [ "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "treeline" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "ucd-util" version = "0.1.3" @@ -1249,6 +1326,7 @@ dependencies = [ name = "wasm-pack" version = "0.6.0" dependencies = [ + "assert_cmd 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "binary-install 0.0.1", "cargo_metadata 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1265,6 +1343,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "predicates 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", "serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1367,6 +1446,7 @@ dependencies = [ "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392" "checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" +"checksum assert_cmd 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b7ac5c260f75e4e4ba87b7342be6edcecbcb3eb6741a0507fda7ad115845cc65" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" "checksum autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e5f34df7a019573fb8bdc7e24a2bfebe51a2a1d6bfdbaeccedb3c41fc574727" "checksum backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b5b493b66e03090ebc4343eb02f94ff944e0cbc9ac6571491d170ba026741eb5" @@ -1392,14 +1472,17 @@ dependencies = [ "checksum curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "c7c9d851c825e0c033979d4516c9173bc19a78a96eb4d6ae51d4045440eafa16" "checksum curl-sys 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ca79238a79fb294be6173b4057c95b22a718c94c4e38475d5faa82b8383f3502" "checksum dialoguer 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ad1c29a0368928e78c551354dbff79f103a962ad820519724ef0d74f1c62fa9" +"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "88972de891f6118092b643d85a0b28e0678e0f948d7f879aa32f2d5aafe97d2a" "checksum encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd" "checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" "checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" +"checksum escargot 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "19db1f7e74438642a5018cdf263bb1325b2e792f02dd0a3ca6d6c0f0d7b1d5a5" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a2df5c1a8c4be27e7707789dc42ae65976e60b394afd293d1419ab915833e646" "checksum flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2291c165c8e703ee54ef3055ad6188e3d51108e2ded18e9f2476e774fc5ad3d4" +"checksum float-cmp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "134a8fa843d80a51a5b77d36d42bc2def9edcb0262c914861d08129fd1926600" "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" "checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" @@ -1425,6 +1508,8 @@ dependencies = [ "checksum miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ad30a47319c16cde58d0314f5d98202a80c9083b5f61178457403dfb14e509c" "checksum miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "28edaef377517fd9fe3e085c37d892ce7acd1fbeab9239c5a36eec352d8a8b7e" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" +"checksum normalize-line-endings 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2e0a1a39eab95caf4f5556da9289b9e68f0aafac901b2ce80daaf020d3b733a8" +"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" "checksum openssl 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ec7bd7ca4cce6dbdc77e7c1230682740d307d1218a87fb0349a571272be749f9" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" "checksum openssl-src 111.1.0+1.1.1a (registry+https://github.com/rust-lang/crates.io-index)" = "26bb632127731bf4ac49bf86a5dde12d2ca0918c2234fc39d79d4da2ccbc6da7" @@ -1437,6 +1522,9 @@ dependencies = [ "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" "checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd" +"checksum predicates 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa984b7cd021a0bf5315bcce4c4ae61d2a535db2a8d288fc7578638690a7b7c3" +"checksum predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "06075c3a3e92559ff8929e7a280684489ea27fe44805174c3ebd9328dcb37178" +"checksum predicates-tree 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e63c4859013b38a76eca2414c64911fba30def9e3202ac461a2d22831220124" "checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c" @@ -1496,6 +1584,7 @@ dependencies = [ "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" +"checksum treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" "checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" diff --git a/Cargo.toml b/Cargo.toml index 14bdf5b6..a0315885 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,8 @@ binary-install = { version = "0.0.1", path = "./binary-install" } walkdir = "2" [dev-dependencies] +assert_cmd = "0.10.2" +predicates = "1.0.0" tempfile = "3" [features] diff --git a/src/cache.rs b/src/cache.rs new file mode 100644 index 00000000..4e3c2d07 --- /dev/null +++ b/src/cache.rs @@ -0,0 +1,14 @@ +//! Getting and configuring wasm-pack's binary cache. + +use binary_install::Cache; +use std::env; +use std::path::Path; + +/// Get wasm-pack's binary cache. +pub fn get_wasm_pack_cache() -> Result { + if let Ok(path) = env::var("WASM_PACK_CACHE") { + Ok(Cache::at(Path::new(&path))) + } else { + Cache::new("wasm-pack") + } +} diff --git a/src/command/build.rs b/src/command/build.rs index c6bad240..ee59a759 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -3,6 +3,7 @@ use binary_install::{Cache, Download}; use bindgen; use build; +use cache; use command::utils::{create_pkg_dir, set_crate_path}; use emoji; use failure::Error; @@ -180,7 +181,7 @@ impl Build { mode: build_opts.mode, out_dir, bindgen: None, - cache: Cache::new("wasm_pack")?, + cache: cache::get_wasm_pack_cache()?, extra_options: build_opts.extra_options, }) } diff --git a/src/command/test.rs b/src/command/test.rs index e0837b1d..ff2f3486 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -4,6 +4,7 @@ use super::build::BuildMode; use binary_install::Cache; use bindgen; use build; +use cache; use command::utils::set_crate_path; use console::style; use emoji; @@ -132,7 +133,7 @@ impl Test { } Ok(Test { - cache: Cache::new("wasm_pack")?, + cache: cache::get_wasm_pack_cache()?, crate_path, crate_data, node, diff --git a/src/lib.rs b/src/lib.rs index 164988e1..97b136fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,6 +28,7 @@ extern crate walkdir; pub mod bindgen; pub mod build; +pub mod cache; pub mod child; pub mod command; pub mod emoji; diff --git a/src/progressbar.rs b/src/progressbar.rs index 24a89477..f0c0e6a5 100644 --- a/src/progressbar.rs +++ b/src/progressbar.rs @@ -43,6 +43,13 @@ impl ProgressOutput { let mut spinner = self.spinner.write(); *spinner = Self::progressbar(message); + + if !atty::is(atty::Stream::Stderr) { + // `indicatif` won't print any output if `stderr` is not a tty, so + // to ensure that our output is still emitted, we print it manually + // here. + eprintln!("{}", message) + } } fn add_message(&self, msg: &str) { diff --git a/src/test/mod.rs b/src/test/mod.rs index 0ec11e95..77eff435 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -4,7 +4,6 @@ pub mod webdriver; use child; use failure::{self, ResultExt}; -use log::info; use std::ffi::OsStr; use std::path::Path; use std::process::Command; @@ -17,20 +16,15 @@ where K: AsRef, V: AsRef, { - let output = { - let mut cmd = Command::new("cargo"); - cmd.envs(envs); - cmd.current_dir(path).arg("test"); - if release { - cmd.arg("--release"); - } - cmd.arg("--target").arg("wasm32-unknown-unknown"); - child::run(cmd, "cargo test").context("Running Wasm tests with wasm-bindgen-test failed")? - }; - - for line in output.lines() { - info!("test output: {}", line); - println!("{}", line); + let mut cmd = Command::new("cargo"); + cmd.envs(envs); + cmd.current_dir(path).arg("test"); + if release { + cmd.arg("--release"); } + cmd.arg("--target").arg("wasm32-unknown-unknown"); + child::run(cmd, "cargo test").context("Running Wasm tests with wasm-bindgen-test failed")?; + + // NB: `child::run` took care of ensuring that test output gets printed. Ok(()) } diff --git a/tests/all/main.rs b/tests/all/main.rs index 06806cd8..a01018b1 100644 --- a/tests/all/main.rs +++ b/tests/all/main.rs @@ -1,4 +1,6 @@ +extern crate assert_cmd; extern crate failure; +extern crate predicates; #[macro_use] extern crate lazy_static; #[macro_use] diff --git a/tests/all/test.rs b/tests/all/test.rs index 278959ab..b438fcdf 100644 --- a/tests/all/test.rs +++ b/tests/all/test.rs @@ -1,4 +1,6 @@ +use assert_cmd::prelude::*; use failure::Error; +use predicates::prelude::*; use std::env; use utils::fixture; use wasm_pack::command::{build, test, Command}; @@ -334,3 +336,43 @@ fn cdylib_not_required() { }); fixture.run(cmd).unwrap(); } + +#[test] +fn test_output_is_printed_once() { + let fixture = fixture::Fixture::new(); + fixture + .readme() + .cargo_toml("wbg-test-node") + .hello_world_src_lib() + .file( + "tests/node.rs", + r#" + extern crate wasm_bindgen; + extern crate wasm_bindgen_test; + use wasm_bindgen::prelude::*; + use wasm_bindgen_test::*; + + #[wasm_bindgen] + extern { + #[wasm_bindgen(js_namespace = console)] + fn log(s: &str); + } + + #[wasm_bindgen_test] + fn pass() { + log("YABBA DABBA DOO"); + assert_eq!(1, 2); + } + "#, + ); + + fixture + .wasm_pack() + .arg("test") + .arg("--node") + .assert() + .stderr(predicate::function(|err: &str| { + err.matches("YABBA DABBA DOO").count() == 1 + })) + .failure(); +} diff --git a/tests/all/utils/fixture.rs b/tests/all/utils/fixture.rs index def8e8c6..3eee609f 100644 --- a/tests/all/utils/fixture.rs +++ b/tests/all/utils/fixture.rs @@ -218,9 +218,14 @@ impl Fixture { wasm_pack::test::webdriver::install_chromedriver(&cache, true).unwrap() } + pub fn cache_dir(&self) -> PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("target") + .join("test_cache") + } + pub fn cache(&self) -> Cache { - let target_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("target"); - Cache::at(&target_dir.join("test_cache")) + Cache::at(&self.cache_dir()) } /// The `step_install_wasm_bindgen` and `step_run_wasm_bindgen` steps only @@ -257,6 +262,16 @@ impl Fixture { } } + /// Get a `wasm-pack` command configured to run in this fixure's temp + /// directory and using the test cache. + pub fn wasm_pack(&self) -> Command { + use assert_cmd::prelude::*; + let mut cmd = Command::main_binary().unwrap(); + cmd.current_dir(&self.path); + cmd.env("WASM_PACK_CACHE", self.cache_dir()); + cmd + } + pub fn lock(&self) -> MutexGuard<'static, ()> { use std::sync::Mutex; lazy_static! {