added tests for --out-name flag

master
ibaryshnikov 6 years ago
parent 7a96d8d754
commit f17e65954c
  1. 2
      src/manifest/mod.rs
  2. 47
      tests/all/manifest.rs

@ -349,7 +349,7 @@ impl CrateData {
}
/// Get the prefix for output file names
fn name_prefix(&self) -> String {
pub fn name_prefix(&self) -> String {
match &self.out_name {
Some(value) => value.clone(),
None => self.crate_name(),

@ -21,6 +21,22 @@ fn it_gets_the_crate_name_provided_path() {
assert_eq!(crate_data.crate_name(), "js_hello_world");
}
#[test]
fn it_gets_the_default_name_prefix() {
let path = &PathBuf::from(".");
let crate_data = manifest::CrateData::new(&path, None).unwrap();
let name = crate_data.name_prefix();
assert_eq!(name, "wasm_pack");
}
#[test]
fn it_gets_the_name_prefix_passed_from_cli() {
let path = &PathBuf::from(".");
let crate_data = manifest::CrateData::new(&path, Some("index".to_owned())).unwrap();
let name = crate_data.name_prefix();
assert_eq!(name, "index");
}
#[test]
fn it_checks_has_cdylib_default_path() {
let fixture = fixture::no_cdylib();
@ -215,6 +231,37 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() {
assert_eq!(actual_files, expected_files);
}
#[test]
fn it_creates_a_package_json_with_correct_files_when_out_name_is_provided() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, Some("index".to_owned())).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, &Target::Bundler)
.is_ok());
let package_json_path = &fixture.path.join("pkg").join("package.json");
fs::metadata(package_json_path).unwrap();
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.repository.ty, "git");
assert_eq!(
pkg.repository.url,
"https://github.com/rustwasm/wasm-pack.git"
);
assert_eq!(pkg.module, "index.js");
assert_eq!(pkg.types, "index.d.ts");
assert_eq!(pkg.side_effects, "false");
let actual_files: HashSet<String> = pkg.files.into_iter().collect();
let expected_files: HashSet<String> = ["index_bg.wasm", "index.d.ts", "index.js"]
.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::js_hello_world();

Loading…
Cancel
Save