@ -8,16 +8,16 @@ use wasm_pack::{self, manifest};
#[ test ]
#[ test ]
fn it_gets_the_crate_name_default_path ( ) {
fn it_gets_the_crate_name_default_path ( ) {
let path = & PathBuf ::from ( "." ) ;
let path = & PathBuf ::from ( "." ) ;
let crate_data = manifest ::CargoManifest ::read ( & path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & path ) . unwrap ( ) ;
let name = crate_data . get_ crate_name( ) ;
let name = crate_data . crate_name ( ) ;
assert_eq! ( name , "wasm- pack" ) ;
assert_eq! ( name , "wasm_ pack" ) ;
}
}
#[ test ]
#[ test ]
fn it_gets_the_crate_name_provided_path ( ) {
fn it_gets_the_crate_name_provided_path ( ) {
let fixture = fixture ::js_hello_world ( ) ;
let fixture = fixture ::js_hello_world ( ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
assert_eq! ( crate_data . get_ crate_name( ) , "js-hello- world" ) ;
assert_eq! ( crate_data . crate_name ( ) , "js_hello_ world" ) ;
}
}
#[ test ]
#[ test ]
@ -25,7 +25,7 @@ fn it_checks_has_cdylib_default_path() {
let fixture = fixture ::no_cdylib ( ) ;
let fixture = fixture ::no_cdylib ( ) ;
// Ensure that there is a `Cargo.lock`.
// Ensure that there is a `Cargo.lock`.
fixture . cargo_check ( ) ;
fixture . cargo_check ( ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
assert! ( crate_data . check_crate_config ( & step ) . is_err ( ) ) ;
assert! ( crate_data . check_crate_config ( & step ) . is_err ( ) ) ;
}
}
@ -35,15 +35,15 @@ fn it_checks_has_cdylib_provided_path() {
let fixture = fixture ::js_hello_world ( ) ;
let fixture = fixture ::js_hello_world ( ) ;
// Ensure that there is a `Cargo.lock`.
// Ensure that there is a `Cargo.lock`.
fixture . cargo_check ( ) ;
fixture . cargo_check ( ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
assert! ( crate_data . check_crate_config ( & step ) . is_ok ( ) ) ;
crate_data . check_crate_config ( & step ) . unwrap ( ) ;
}
}
#[ test ]
#[ test ]
fn it_checks_has_cdylib_wrong_crate_type ( ) {
fn it_checks_has_cdylib_wrong_crate_type ( ) {
let fixture = fixture ::bad_cargo_toml ( ) ;
let fixture = fixture ::bad_cargo_toml ( ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
assert! ( crate_data . check_crate_config ( & step ) . is_err ( ) ) ;
assert! ( crate_data . check_crate_config ( & step ) . is_err ( ) ) ;
}
}
@ -53,24 +53,24 @@ fn it_recognizes_a_map_during_depcheck() {
let fixture = fixture ::serde_feature ( ) ;
let fixture = fixture ::serde_feature ( ) ;
// Ensure that there is a `Cargo.lock`.
// Ensure that there is a `Cargo.lock`.
fixture . cargo_check ( ) ;
fixture . cargo_check ( ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
assert! ( crate_data . check_crate_config ( & step ) . is_ok ( ) ) ;
crate_data . check_crate_config ( & step ) . unwrap ( ) ;
}
}
#[ test ]
#[ test ]
fn it_creates_a_package_json_default_path ( ) {
fn it_creates_a_package_json_default_path ( ) {
let fixture = fixture ::js_hello_world ( ) ;
let fixture = fixture ::js_hello_world ( ) ;
let out_dir = fixture . path . join ( "pkg" ) ;
let out_dir = fixture . path . join ( "pkg" ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
assert! ( crate_data
assert! ( crate_data
. write_package_json ( & out_dir , & None , false , "" , & step )
. write_package_json ( & out_dir , & None , false , "" , & step )
. is_ok ( ) ) ;
. is_ok ( ) ) ;
let package_json_path = & fixture . path . join ( "pkg" ) . join ( "package.json" ) ;
let package_json_path = & fixture . path . join ( "pkg" ) . join ( "package.json" ) ;
assert! ( fs ::metadata ( package_json_path ) . is_ok ( ) ) ;
fs ::metadata ( package_json_path ) . unwrap ( ) ;
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 ( ) ;
let pkg = utils ::manifest ::read_package_json ( & fixture . path , & out_dir ) . unwrap ( ) ;
assert_eq! ( pkg . name , "js-hello-world" ) ;
assert_eq! ( pkg . name , "js-hello-world" ) ;
assert_eq! ( pkg . repository . ty , "git" ) ;
assert_eq! ( pkg . repository . ty , "git" ) ;
@ -98,14 +98,14 @@ fn it_creates_a_package_json_default_path() {
fn it_creates_a_package_json_provided_path ( ) {
fn it_creates_a_package_json_provided_path ( ) {
let fixture = fixture ::js_hello_world ( ) ;
let fixture = fixture ::js_hello_world ( ) ;
let out_dir = fixture . path . join ( "pkg" ) ;
let out_dir = fixture . path . join ( "pkg" ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
assert! ( crate_data
assert! ( crate_data
. write_package_json ( & out_dir , & None , false , "" , & step )
. write_package_json ( & out_dir , & None , false , "" , & step )
. is_ok ( ) ) ;
. is_ok ( ) ) ;
let package_json_path = & fixture . path . join ( "pkg" ) . join ( "package.json" ) ;
let package_json_path = & fixture . path . join ( "pkg" ) . join ( "package.json" ) ;
assert! ( fs ::metadata ( package_json_path ) . is_ok ( ) ) ;
fs ::metadata ( package_json_path ) . unwrap ( ) ;
utils ::manifest ::read_package_json ( & fixture . path , & out_dir ) . unwrap ( ) ;
utils ::manifest ::read_package_json ( & fixture . path , & out_dir ) . unwrap ( ) ;
let pkg = 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 . name , "js-hello-world" ) ;
@ -127,15 +127,15 @@ fn it_creates_a_package_json_provided_path() {
fn it_creates_a_package_json_provided_path_with_scope ( ) {
fn it_creates_a_package_json_provided_path_with_scope ( ) {
let fixture = fixture ::js_hello_world ( ) ;
let fixture = fixture ::js_hello_world ( ) ;
let out_dir = fixture . path . join ( "pkg" ) ;
let out_dir = fixture . path . join ( "pkg" ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
assert! ( crate_data
assert! ( crate_data
. write_package_json ( & out_dir , & Some ( "test" . to_string ( ) ) , false , "" , & step )
. write_package_json ( & out_dir , & Some ( "test" . to_string ( ) ) , false , "" , & step )
. is_ok ( ) ) ;
. is_ok ( ) ) ;
let package_json_path = & fixture . path . join ( "pkg" ) . join ( "package.json" ) ;
let package_json_path = & fixture . path . join ( "pkg" ) . join ( "package.json" ) ;
assert! ( fs ::metadata ( package_json_path ) . is_ok ( ) ) ;
fs ::metadata ( package_json_path ) . unwrap ( ) ;
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 ( ) ;
let pkg = utils ::manifest ::read_package_json ( & fixture . path , & out_dir ) . unwrap ( ) ;
assert_eq! ( pkg . name , "@test/js-hello-world" ) ;
assert_eq! ( pkg . name , "@test/js-hello-world" ) ;
assert_eq! ( pkg . module , "js_hello_world.js" ) ;
assert_eq! ( pkg . module , "js_hello_world.js" ) ;
@ -156,14 +156,14 @@ fn it_creates_a_package_json_provided_path_with_scope() {
fn it_creates_a_pkg_json_with_correct_files_on_node ( ) {
fn it_creates_a_pkg_json_with_correct_files_on_node ( ) {
let fixture = fixture ::js_hello_world ( ) ;
let fixture = fixture ::js_hello_world ( ) ;
let out_dir = fixture . path . join ( "pkg" ) ;
let out_dir = fixture . path . join ( "pkg" ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
assert! ( crate_data
assert! ( crate_data
. write_package_json ( & out_dir , & None , false , "nodejs" , & step )
. write_package_json ( & out_dir , & None , false , "nodejs" , & step )
. is_ok ( ) ) ;
. is_ok ( ) ) ;
let package_json_path = & out_dir . join ( "package.json" ) ;
let package_json_path = & out_dir . join ( "package.json" ) ;
assert! ( fs ::metadata ( package_json_path ) . is_ok ( ) ) ;
fs ::metadata ( package_json_path ) . unwrap ( ) ;
utils ::manifest ::read_package_json ( & fixture . path , & out_dir ) . unwrap ( ) ;
utils ::manifest ::read_package_json ( & fixture . path , & out_dir ) . unwrap ( ) ;
let pkg = 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 . name , "js-hello-world" ) ;
@ -180,6 +180,7 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() {
"js_hello_world_bg.wasm" ,
"js_hello_world_bg.wasm" ,
"js_hello_world_bg.js" ,
"js_hello_world_bg.js" ,
"js_hello_world.d.ts" ,
"js_hello_world.d.ts" ,
"js_hello_world.js" ,
]
]
. iter ( )
. iter ( )
. map ( | & s | String ::from ( s ) )
. map ( | & s | String ::from ( s ) )
@ -191,14 +192,14 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() {
fn it_creates_a_pkg_json_with_correct_files_on_nomodules ( ) {
fn it_creates_a_pkg_json_with_correct_files_on_nomodules ( ) {
let fixture = fixture ::js_hello_world ( ) ;
let fixture = fixture ::js_hello_world ( ) ;
let out_dir = fixture . path . join ( "pkg" ) ;
let out_dir = fixture . path . join ( "pkg" ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
assert! ( crate_data
assert! ( crate_data
. write_package_json ( & out_dir , & None , false , "no-modules" , & step )
. write_package_json ( & out_dir , & None , false , "no-modules" , & step )
. is_ok ( ) ) ;
. is_ok ( ) ) ;
let package_json_path = & out_dir . join ( "package.json" ) ;
let package_json_path = & out_dir . join ( "package.json" ) ;
assert! ( fs ::metadata ( package_json_path ) . is_ok ( ) ) ;
fs ::metadata ( package_json_path ) . unwrap ( ) ;
utils ::manifest ::read_package_json ( & fixture . path , & out_dir ) . unwrap ( ) ;
utils ::manifest ::read_package_json ( & fixture . path , & out_dir ) . unwrap ( ) ;
let pkg = 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 . name , "js-hello-world" ) ;
@ -226,7 +227,7 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() {
fn it_creates_a_pkg_json_in_out_dir ( ) {
fn it_creates_a_pkg_json_in_out_dir ( ) {
let fixture = fixture ::js_hello_world ( ) ;
let fixture = fixture ::js_hello_world ( ) ;
let out_dir = fixture . path . join ( "./custom/out" ) ;
let out_dir = fixture . path . join ( "./custom/out" ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
assert! ( crate_data
assert! ( crate_data
@ -234,23 +235,23 @@ fn it_creates_a_pkg_json_in_out_dir() {
. is_ok ( ) ) ;
. is_ok ( ) ) ;
let package_json_path = & fixture . path . join ( & out_dir ) . join ( "package.json" ) ;
let package_json_path = & fixture . path . join ( & out_dir ) . join ( "package.json" ) ;
assert! ( fs ::metadata ( package_json_path ) . is_ok ( ) ) ;
fs ::metadata ( package_json_path ) . unwrap ( ) ;
assert! ( utils ::manifest ::read_package_json ( & fixture . path , & out_dir ) . is_ok ( ) ) ;
utils ::manifest ::read_package_json ( & fixture . path , & out_dir ) . unwrap ( ) ;
}
}
#[ test ]
#[ test ]
fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped ( ) {
fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped ( ) {
let fixture = fixture ::js_hello_world ( ) ;
let fixture = fixture ::js_hello_world ( ) ;
let out_dir = fixture . path . join ( "pkg" ) ;
let out_dir = fixture . path . join ( "pkg" ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
wasm_pack ::command ::utils ::create_pkg_dir ( & out_dir , & step ) . unwrap ( ) ;
assert! ( crate_data
assert! ( crate_data
. write_package_json ( & out_dir , & None , true , "" , & step )
. write_package_json ( & out_dir , & None , true , "" , & step )
. is_ok ( ) ) ;
. is_ok ( ) ) ;
let package_json_path = & out_dir . join ( "package.json" ) ;
let package_json_path = & out_dir . join ( "package.json" ) ;
assert! ( fs ::metadata ( package_json_path ) . is_ok ( ) ) ;
fs ::metadata ( package_json_path ) . unwrap ( ) ;
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 ( ) ;
let pkg = utils ::manifest ::read_package_json ( & fixture . path , & out_dir ) . unwrap ( ) ;
assert_eq! ( pkg . name , "js-hello-world" ) ;
assert_eq! ( pkg . name , "js-hello-world" ) ;
assert_eq! ( pkg . repository . ty , "git" ) ;
assert_eq! ( pkg . repository . ty , "git" ) ;
@ -271,7 +272,7 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() {
#[ test ]
#[ test ]
fn it_errors_when_wasm_bindgen_is_not_declared ( ) {
fn it_errors_when_wasm_bindgen_is_not_declared ( ) {
let fixture = fixture ::bad_cargo_toml ( ) ;
let fixture = fixture ::bad_cargo_toml ( ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
assert! ( crate_data . check_crate_config ( & step ) . is_err ( ) ) ;
assert! ( crate_data . check_crate_config ( & step ) . is_err ( ) ) ;
}
}
@ -281,7 +282,7 @@ fn it_does_not_error_when_wasm_bindgen_is_declared() {
let fixture = fixture ::js_hello_world ( ) ;
let fixture = fixture ::js_hello_world ( ) ;
// Ensure that there is a `Cargo.lock`.
// Ensure that there is a `Cargo.lock`.
fixture . cargo_check ( ) ;
fixture . cargo_check ( ) ;
let crate_data = manifest ::CargoManifest ::read ( & fixture . path ) . unwrap ( ) ;
let crate_data = manifest ::CrateData ::new ( & fixture . path ) . unwrap ( ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
let step = wasm_pack ::progressbar ::Step ::new ( 1 ) ;
assert! ( crate_data . check_crate_config ( & step ) . is_ok ( ) ) ;
crate_data . check_crate_config ( & step ) . unwrap ( ) ;
}
}