|
|
|
@ -14,46 +14,45 @@ fn it_gets_the_crate_name_default_path() { |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_gets_the_crate_name_provided_path() { |
|
|
|
|
let path = &PathBuf::from("tests/fixtures/js-hello-world"); |
|
|
|
|
assert!(manifest::get_crate_name(path).is_ok()); |
|
|
|
|
assert_eq!(manifest::get_crate_name(path).unwrap(), "js-hello-world"); |
|
|
|
|
let fixture = fixture::js_hello_world(); |
|
|
|
|
assert!(manifest::get_crate_name(&fixture.path).is_ok()); |
|
|
|
|
assert_eq!( |
|
|
|
|
manifest::get_crate_name(&fixture.path).unwrap(), |
|
|
|
|
"js-hello-world" |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_checks_has_cdylib_default_path() { |
|
|
|
|
let fixture = fixture::no_cdylib(); |
|
|
|
|
let step = wasm_pack::progressbar::Step::new(1); |
|
|
|
|
assert!(manifest::check_crate_config(&PathBuf::from("."), &step).is_err()); |
|
|
|
|
assert!(manifest::check_crate_config(&fixture.path, &step).is_err()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_checks_has_cdylib_provided_path() { |
|
|
|
|
let fixture = fixture::js_hello_world(); |
|
|
|
|
let step = wasm_pack::progressbar::Step::new(1); |
|
|
|
|
assert!( |
|
|
|
|
manifest::check_crate_config(&PathBuf::from("tests/fixtures/js-hello-world"), &step) |
|
|
|
|
.is_ok() |
|
|
|
|
); |
|
|
|
|
assert!(manifest::check_crate_config(&fixture.path, &step).is_ok()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_checks_has_cdylib_wrong_crate_type() { |
|
|
|
|
let fixture = fixture::bad_cargo_toml(); |
|
|
|
|
let step = wasm_pack::progressbar::Step::new(1); |
|
|
|
|
assert!( |
|
|
|
|
manifest::check_crate_config(&PathBuf::from("tests/fixtures/bad-cargo-toml"), &step) |
|
|
|
|
.is_err() |
|
|
|
|
); |
|
|
|
|
assert!(manifest::check_crate_config(&fixture.path, &step).is_err()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_recognizes_a_map_during_depcheck() { |
|
|
|
|
let fixture = fixture::serde_feature(); |
|
|
|
|
let step = wasm_pack::progressbar::Step::new(1); |
|
|
|
|
assert!( |
|
|
|
|
manifest::check_crate_config(&PathBuf::from("tests/fixtures/serde-feature"), &step).is_ok() |
|
|
|
|
); |
|
|
|
|
assert!(manifest::check_crate_config(&fixture.path, &step).is_ok()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_creates_a_package_json_default_path() { |
|
|
|
|
let fixture = fixture::fixture("."); |
|
|
|
|
let fixture = fixture::js_hello_world(); |
|
|
|
|
let out_dir = fixture.path.join("pkg"); |
|
|
|
|
let step = wasm_pack::progressbar::Step::new(1); |
|
|
|
|
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); |
|
|
|
@ -62,18 +61,22 @@ fn it_creates_a_package_json_default_path() { |
|
|
|
|
assert!(fs::metadata(package_json_path).is_ok()); |
|
|
|
|
assert!(utils::manifest::read_package_json(&fixture.path, &out_dir).is_ok()); |
|
|
|
|
let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); |
|
|
|
|
assert_eq!(pkg.name, "wasm-pack"); |
|
|
|
|
assert_eq!(pkg.name, "js-hello-world"); |
|
|
|
|
assert_eq!(pkg.repository.ty, "git"); |
|
|
|
|
assert_eq!( |
|
|
|
|
pkg.repository.url, |
|
|
|
|
"https://github.com/ashleygwilliams/wasm-pack.git" |
|
|
|
|
"https://github.com/rustwasm/wasm-pack.git" |
|
|
|
|
); |
|
|
|
|
assert_eq!(pkg.module, "wasm_pack.js"); |
|
|
|
|
assert_eq!(pkg.types, "wasm_pack.d.ts"); |
|
|
|
|
assert_eq!(pkg.module, "js_hello_world.js"); |
|
|
|
|
assert_eq!(pkg.types, "js_hello_world.d.ts"); |
|
|
|
|
assert_eq!(pkg.side_effects, "false"); |
|
|
|
|
|
|
|
|
|
let actual_files: HashSet<String> = pkg.files.into_iter().collect(); |
|
|
|
|
let expected_files: HashSet<String> = ["wasm_pack_bg.wasm", "wasm_pack.d.ts", "wasm_pack.js"] |
|
|
|
|
let expected_files: HashSet<String> = [ |
|
|
|
|
"js_hello_world_bg.wasm", |
|
|
|
|
"js_hello_world.d.ts", |
|
|
|
|
"js_hello_world.js", |
|
|
|
|
] |
|
|
|
|
.iter() |
|
|
|
|
.map(|&s| String::from(s)) |
|
|
|
|
.collect(); |
|
|
|
@ -82,14 +85,14 @@ fn it_creates_a_package_json_default_path() { |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_creates_a_package_json_provided_path() { |
|
|
|
|
let fixture = fixture::fixture("tests/fixtures/js-hello-world"); |
|
|
|
|
let fixture = fixture::js_hello_world(); |
|
|
|
|
let out_dir = fixture.path.join("pkg"); |
|
|
|
|
let step = wasm_pack::progressbar::Step::new(1); |
|
|
|
|
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); |
|
|
|
|
assert!(manifest::write_package_json(&fixture.path, &out_dir, &None, false, "", &step).is_ok()); |
|
|
|
|
let package_json_path = &fixture.path.join("pkg").join("package.json"); |
|
|
|
|
assert!(fs::metadata(package_json_path).is_ok()); |
|
|
|
|
assert!(utils::manifest::read_package_json(&fixture.path, &out_dir).is_ok()); |
|
|
|
|
utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); |
|
|
|
|
let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); |
|
|
|
|
assert_eq!(pkg.name, "js-hello-world"); |
|
|
|
|
assert_eq!(pkg.module, "js_hello_world.js"); |
|
|
|
@ -108,7 +111,7 @@ fn it_creates_a_package_json_provided_path() { |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_creates_a_package_json_provided_path_with_scope() { |
|
|
|
|
let fixture = fixture::fixture("tests/fixtures/scopes"); |
|
|
|
|
let fixture = fixture::js_hello_world(); |
|
|
|
|
let out_dir = fixture.path.join("pkg"); |
|
|
|
|
let step = wasm_pack::progressbar::Step::new(1); |
|
|
|
|
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); |
|
|
|
@ -126,14 +129,14 @@ fn it_creates_a_package_json_provided_path_with_scope() { |
|
|
|
|
assert!(fs::metadata(package_json_path).is_ok()); |
|
|
|
|
assert!(utils::manifest::read_package_json(&fixture.path, &out_dir).is_ok()); |
|
|
|
|
let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); |
|
|
|
|
assert_eq!(pkg.name, "@test/scopes-hello-world"); |
|
|
|
|
assert_eq!(pkg.module, "scopes_hello_world.js"); |
|
|
|
|
assert_eq!(pkg.name, "@test/js-hello-world"); |
|
|
|
|
assert_eq!(pkg.module, "js_hello_world.js"); |
|
|
|
|
|
|
|
|
|
let actual_files: HashSet<String> = pkg.files.into_iter().collect(); |
|
|
|
|
let expected_files: HashSet<String> = [ |
|
|
|
|
"scopes_hello_world_bg.wasm", |
|
|
|
|
"scopes_hello_world.d.ts", |
|
|
|
|
"scopes_hello_world.js", |
|
|
|
|
"js_hello_world_bg.wasm", |
|
|
|
|
"js_hello_world.d.ts", |
|
|
|
|
"js_hello_world.js", |
|
|
|
|
] |
|
|
|
|
.iter() |
|
|
|
|
.map(|&s| String::from(s)) |
|
|
|
@ -143,7 +146,7 @@ fn it_creates_a_package_json_provided_path_with_scope() { |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_creates_a_pkg_json_with_correct_files_on_node() { |
|
|
|
|
let fixture = fixture::fixture("."); |
|
|
|
|
let fixture = fixture::js_hello_world(); |
|
|
|
|
let out_dir = fixture.path.join("pkg"); |
|
|
|
|
let step = wasm_pack::progressbar::Step::new(1); |
|
|
|
|
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); |
|
|
|
@ -153,29 +156,32 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() { |
|
|
|
|
); |
|
|
|
|
let package_json_path = &out_dir.join("package.json"); |
|
|
|
|
assert!(fs::metadata(package_json_path).is_ok()); |
|
|
|
|
assert!(utils::manifest::read_package_json(&fixture.path, &out_dir).is_ok()); |
|
|
|
|
utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); |
|
|
|
|
let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); |
|
|
|
|
assert_eq!(pkg.name, "wasm-pack"); |
|
|
|
|
assert_eq!(pkg.name, "js-hello-world"); |
|
|
|
|
assert_eq!(pkg.repository.ty, "git"); |
|
|
|
|
assert_eq!( |
|
|
|
|
pkg.repository.url, |
|
|
|
|
"https://github.com/ashleygwilliams/wasm-pack.git" |
|
|
|
|
"https://github.com/rustwasm/wasm-pack.git" |
|
|
|
|
); |
|
|
|
|
assert_eq!(pkg.main, "wasm_pack.js"); |
|
|
|
|
assert_eq!(pkg.types, "wasm_pack.d.ts"); |
|
|
|
|
assert_eq!(pkg.main, "js_hello_world.js"); |
|
|
|
|
assert_eq!(pkg.types, "js_hello_world.d.ts"); |
|
|
|
|
|
|
|
|
|
let actual_files: HashSet<String> = pkg.files.into_iter().collect(); |
|
|
|
|
let expected_files: HashSet<String> = |
|
|
|
|
["wasm_pack_bg.wasm", "wasm_pack_bg.js", "wasm_pack.d.ts"] |
|
|
|
|
.iter() |
|
|
|
|
.map(|&s| String::from(s)) |
|
|
|
|
.collect(); |
|
|
|
|
let expected_files: HashSet<String> = [ |
|
|
|
|
"js_hello_world_bg.wasm", |
|
|
|
|
"js_hello_world_bg.js", |
|
|
|
|
"js_hello_world.d.ts", |
|
|
|
|
] |
|
|
|
|
.iter() |
|
|
|
|
.map(|&s| String::from(s)) |
|
|
|
|
.collect(); |
|
|
|
|
assert_eq!(actual_files, expected_files); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_creates_a_pkg_json_in_out_dir() { |
|
|
|
|
let fixture = fixture::fixture("tests/fixtures/js-hello-world"); |
|
|
|
|
let fixture = fixture::js_hello_world(); |
|
|
|
|
let out_dir = fixture.path.join("./custom/out"); |
|
|
|
|
let step = wasm_pack::progressbar::Step::new(1); |
|
|
|
|
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); |
|
|
|
@ -188,7 +194,7 @@ fn it_creates_a_pkg_json_in_out_dir() { |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() { |
|
|
|
|
let fixture = fixture::fixture("."); |
|
|
|
|
let fixture = fixture::js_hello_world(); |
|
|
|
|
let out_dir = fixture.path.join("pkg"); |
|
|
|
|
let step = wasm_pack::progressbar::Step::new(1); |
|
|
|
|
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); |
|
|
|
@ -197,16 +203,16 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() { |
|
|
|
|
assert!(fs::metadata(package_json_path).is_ok()); |
|
|
|
|
assert!(utils::manifest::read_package_json(&fixture.path, &out_dir).is_ok()); |
|
|
|
|
let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); |
|
|
|
|
assert_eq!(pkg.name, "wasm-pack"); |
|
|
|
|
assert_eq!(pkg.name, "js-hello-world"); |
|
|
|
|
assert_eq!(pkg.repository.ty, "git"); |
|
|
|
|
assert_eq!( |
|
|
|
|
pkg.repository.url, |
|
|
|
|
"https://github.com/ashleygwilliams/wasm-pack.git" |
|
|
|
|
"https://github.com/rustwasm/wasm-pack.git" |
|
|
|
|
); |
|
|
|
|
assert_eq!(pkg.module, "wasm_pack.js"); |
|
|
|
|
assert_eq!(pkg.module, "js_hello_world.js"); |
|
|
|
|
|
|
|
|
|
let actual_files: HashSet<String> = pkg.files.into_iter().collect(); |
|
|
|
|
let expected_files: HashSet<String> = ["wasm_pack_bg.wasm", "wasm_pack.js"] |
|
|
|
|
let expected_files: HashSet<String> = ["js_hello_world_bg.wasm", "js_hello_world.js"] |
|
|
|
|
.iter() |
|
|
|
|
.map(|&s| String::from(s)) |
|
|
|
|
.collect(); |
|
|
|
@ -215,30 +221,30 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() { |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_errors_when_wasm_bindgen_is_not_declared() { |
|
|
|
|
let fixture = fixture::fixture("tests/fixtures/bad-cargo-toml"); |
|
|
|
|
let fixture = fixture::bad_cargo_toml(); |
|
|
|
|
let step = wasm_pack::progressbar::Step::new(1); |
|
|
|
|
assert!(manifest::check_crate_config(&fixture.path, &step).is_err()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_does_not_error_when_wasm_bindgen_is_declared() { |
|
|
|
|
let fixture = fixture::fixture("tests/fixtures/js-hello-world"); |
|
|
|
|
let fixture = fixture::js_hello_world(); |
|
|
|
|
let step = wasm_pack::progressbar::Step::new(1); |
|
|
|
|
assert!(manifest::check_crate_config(&fixture.path, &step).is_ok()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_gets_wasm_bindgen_version() { |
|
|
|
|
let fixture = fixture::fixture("tests/fixtures/js-hello-world"); |
|
|
|
|
let fixture = fixture::js_hello_world(); |
|
|
|
|
assert_eq!( |
|
|
|
|
manifest::get_wasm_bindgen_version(&fixture.path).unwrap(), |
|
|
|
|
"0.2" |
|
|
|
|
"0.2.21" |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn it_gets_wasm_bindgen_version_with_underscores() { |
|
|
|
|
let fixture = fixture::fixture("tests/fixtures/with-underscores"); |
|
|
|
|
let fixture = fixture::with_underscores(); |
|
|
|
|
assert_eq!( |
|
|
|
|
manifest::get_wasm_bindgen_version(&fixture.path).unwrap(), |
|
|
|
|
"0.2" |
|
|
|
@ -247,13 +253,14 @@ fn it_gets_wasm_bindgen_version_with_underscores() { |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn the_wasm_bindgen_test_version_should_match_the_wasm_bindgen_version() { |
|
|
|
|
let fixture = fixture::fixture("tests/fixtures/wbg-test-bad-versions"); |
|
|
|
|
let fixture = fixture::wbg_test_bad_versions(); |
|
|
|
|
let step = wasm_pack::progressbar::Step::new(1); |
|
|
|
|
let result = manifest::check_crate_config(&fixture.path, &step); |
|
|
|
|
assert!(result.is_err()); |
|
|
|
|
let msg = result.unwrap_err().to_string(); |
|
|
|
|
println!("{}", msg); |
|
|
|
|
assert!(msg.contains(&format!( |
|
|
|
|
"The `wasm-bindgen-test` dependency version (0.2.19) must match \ |
|
|
|
|
the `wasm-bindgen` dependency version (0.2.21), but it does not." |
|
|
|
|
"The `wasm-bindgen-test` dependency version (=0.2.19) must match \ |
|
|
|
|
the `wasm-bindgen` dependency version (=0.2.21), but it does not." |
|
|
|
|
))); |
|
|
|
|
} |
|
|
|
|