Skip to content

Commit

Permalink
add test case for copying 'homepage' field from Cargo.toml to package…
Browse files Browse the repository at this point in the history
….json
  • Loading branch information
rhysd committed Jan 27, 2019
1 parent bae98ef commit d616ea1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/all/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions tests/all/utils/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d616ea1

Please sign in to comment.