From d616ea17dcceca312bede820265349e53e9ea726 Mon Sep 17 00:00:00 2001 From: rhysd Date: Mon, 28 Jan 2019 03:53:50 +0900 Subject: [PATCH] add test case for copying 'homepage' field from Cargo.toml to package.json --- tests/all/manifest.rs | 57 +++++++++++++++++++++++++++++++++++++ tests/all/utils/manifest.rs | 2 ++ 2 files changed, 59 insertions(+) diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index 1d631c844..b00b8fe6c 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -279,6 +279,63 @@ fn it_errors_when_wasm_bindgen_is_not_declared() { assert!(crate_data.check_crate_config(&step).is_err()); } +#[test] +fn it_sets_homepage_field_if_available_in_cargo_toml() { + // When 'homepage' is available + let fixture = utils::fixture::Fixture::new(); + fixture.hello_world_src_lib().file( + "Cargo.toml", + r#" + [package] + authors = ["The wasm-pack developers"] + description = "so awesome rust+wasm package" + license = "WTFPL" + name = "homepage-field-test" + repository = "https://github.com/rustwasm/wasm-pack.git" + version = "0.1.0" + homepage = "https://rustwasm.github.io/wasm-pack/" + + [lib] + crate-type = ["cdylib"] + + [dependencies] + wasm-bindgen = "=0.2" + + [dev-dependencies] + wasm-bindgen-test = "=0.2" + "#, + ); + + let out_dir = fixture.path.join("pkg"); + let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); + + let step = wasm_pack::progressbar::Step::new(2); + wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); + crate_data + .write_package_json(&out_dir, &None, true, "", &step) + .unwrap(); + + let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); + assert_eq!( + pkg.homepage, + "https://rustwasm.github.io/wasm-pack/".to_string(), + ); + + // When 'homepage' is unavailable + let fixture = fixture::js_hello_world(); + let out_dir = fixture.path.join("pkg"); + let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); + + let step = wasm_pack::progressbar::Step::new(2); + wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); + crate_data + .write_package_json(&out_dir, &None, true, "", &step) + .unwrap(); + + let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); + assert_eq!(pkg.homepage, "".to_string()); +} + #[test] fn it_does_not_error_when_wasm_bindgen_is_declared() { let fixture = fixture::js_hello_world(); diff --git a/tests/all/utils/manifest.rs b/tests/all/utils/manifest.rs index 2f811eccc..a01b0769c 100644 --- a/tests/all/utils/manifest.rs +++ b/tests/all/utils/manifest.rs @@ -23,6 +23,8 @@ pub struct NpmPackage { pub types: String, #[serde(default = "default_none", rename = "sideEffects")] pub side_effects: String, + #[serde(default = "default_none")] + pub homepage: String, } fn default_none() -> String {