From 879e3aa7a68a793d6c871967380137b42c1fddfc Mon Sep 17 00:00:00 2001 From: Chinedu Francis Nwafili Date: Sun, 27 Jan 2019 11:44:01 -0500 Subject: [PATCH] Add back building tests --- src/build.rs | 17 ++++++++++++++++- src/command/test.rs | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/build.rs b/src/build.rs index e0fb1ca..e706b6a 100644 --- a/src/build.rs +++ b/src/build.rs @@ -25,7 +25,7 @@ pub fn check_rustc_version(step: &Step) -> Result { } else { Ok(mv.to_string()) } - }, + } None => bail!("We can't figure out what your Rust version is- which means you might not have Rust installed. Please install Rust version 1.30.0 or higher."), } } @@ -93,3 +93,18 @@ pub fn cargo_build_wasm( child::run(cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?; Ok(()) } + +/// Run `cargo build --tests` targetting `wasm32-unknown-unknown`. +/// +/// This generates the `Cargo.lock` file that we use in order to know which version of +/// wasm-bindgen-cli to use when running tests. +pub fn cargo_build_wasm_tests(path: &Path, debug: bool) -> Result<(), Error> { + let mut cmd = Command::new("cargo"); + cmd.current_dir(path).arg("build").arg("--tests"); + if !debug { + cmd.arg("--release"); + } + cmd.arg("--target").arg("wasm32-unknown-unknown"); + child::run(cmd, "cargo build").context("Compilation of your program failed")?; + Ok(()) +} diff --git a/src/command/test.rs b/src/command/test.rs index 829f3d3..45950fc 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -197,6 +197,7 @@ impl Test { BuildMode::Normal => steps![ step_check_rustc_version, step_add_wasm_target, + step_build_tests, step_install_wasm_bindgen, step_test_node if self.node, step_get_chromedriver if self.chrome && self.chromedriver.is_none(), @@ -208,6 +209,7 @@ impl Test { ], BuildMode::Force => steps![ step_add_wasm_target, + step_build_tests, step_install_wasm_bindgen, step_test_node if self.node, step_get_chromedriver if self.chrome && self.chromedriver.is_none(), @@ -218,6 +220,7 @@ impl Test { step_test_safari if self.safari, ], BuildMode::Noinstall => steps![ + step_build_tests, step_install_wasm_bindgen, step_test_node if self.node, step_get_chromedriver if self.chrome && self.chromedriver.is_none(), @@ -244,6 +247,18 @@ impl Test { Ok(()) } + fn step_build_tests(&mut self, step: &Step) -> Result<(), Error> { + info!("Compiling tests to wasm..."); + + let msg = format!("{}Compiling tests to WASM...", emoji::CYCLONE); + PBAR.step(step, &msg); + + build::cargo_build_wasm_tests(&self.crate_path, !self.release)?; + + info!("Finished compiling tests to wasm."); + Ok(()) + } + fn step_install_wasm_bindgen(&mut self, step: &Step) -> Result<(), Error> { info!("Identifying wasm-bindgen dependency..."); let lockfile = Lockfile::new(&self.crate_data)?;