Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(command/build): add a test for build command #408

Merged
merged 5 commits into from
Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Functionality related to installing and running `wasm-bindgen`.

use binaries::{self, bin_path, install_binaries_from_targz_at_url};
use cargo_metadata;
use child;
use emoji;
use error::Error;
Expand Down Expand Up @@ -127,10 +128,17 @@ pub fn wasm_bindgen_build(
let out_dir = out_dir.to_str().unwrap();

if let Some(wasm_bindgen_path) = wasm_bindgen_path(log, path) {
let wasm_path = format!(
"target/wasm32-unknown-unknown/{}/{}.wasm",
release_or_debug, binary_name
);
let manifest = path.join("Cargo.toml");
let target_path = cargo_metadata::metadata(Some(&manifest))
.unwrap()
.target_directory;
let mut wasm_path = PathBuf::from(&target_path)
.join("wasm32-unknown-unknown")
.join(release_or_debug)
.join(binary_name);
wasm_path.set_extension("wasm");
let wasm_path = wasm_path.display().to_string();

let dts_arg = if disable_dts {
"--no-typescript"
} else {
Expand Down
15 changes: 15 additions & 0 deletions tests/all/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,18 @@ fn build_in_non_crate_directory_doesnt_panic() {
let err_msg = result.unwrap_err().to_string();
assert!(err_msg.contains("missing a `Cargo.toml`"));
}

#[test]
fn it_should_build_js_hello_world_example() {
let fixture = utils::fixture::js_hello_world();
fixture.install_local_wasm_bindgen();
let cli = Cli::from_iter_safe(vec![
"wasm-pack",
"build",
&fixture.path.display().to_string(),
])
.unwrap();
let logger = logger::new(&cli.cmd, cli.verbosity).unwrap();
command::run_wasm_pack(cli.cmd, &logger)
.expect("running wasm-pack in a js-hello-world directory should succeed.");
}