Skip to content

Commit

Permalink
Merge pull request #408 from huangjj27/test-build-for-example
Browse files Browse the repository at this point in the history
test(command/build): add a test for build command
  • Loading branch information
fitzgen authored Oct 20, 2018
2 parents ceb4779 + 29c19f8 commit 600d02b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
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.");
}

0 comments on commit 600d02b

Please sign in to comment.