diff --git a/src/command/mod.rs b/src/command/mod.rs index 2f477b9b9..150612c8b 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -2,7 +2,7 @@ pub mod init; mod login; -mod pack; +pub mod pack; mod publish; pub mod utils; diff --git a/src/command/pack.rs b/src/command/pack.rs index c9c9ffd48..ff2146abb 100644 --- a/src/command/pack.rs +++ b/src/command/pack.rs @@ -1,3 +1,5 @@ +//! Pack function to use npm pack + use command::utils::{find_pkg_directory, set_crate_path}; use error::Error; use npm; diff --git a/tests/manifest/main.rs b/tests/manifest/main.rs index cf661969d..05bbb6d59 100644 --- a/tests/manifest/main.rs +++ b/tests/manifest/main.rs @@ -3,12 +3,16 @@ extern crate failure; extern crate serde_derive; extern crate serde_json; extern crate wasm_pack; +#[macro_use] +extern crate slog; mod utils; use std::collections::HashSet; use std::fs; +use wasm_pack::command; +use wasm_pack::error; use wasm_pack::manifest; #[test] @@ -182,3 +186,26 @@ fn it_does_not_error_when_wasm_bindgen_is_declared() { let step = wasm_pack::progressbar::Step::new(1); assert!(manifest::check_crate_config("tests/fixtures/js-hello-world", &step).is_ok()); } + +#[test] +fn pack_does_not_error_when_path_is_to_pkg_dir() { + let path = "tests/fixtures/js-hello-world".to_owned(); + assert!(command::pack::pack(Some(path), &utils::get_nop_logger()).is_ok()) +} + +#[test] +fn pack_does_not_error_when_path_is_to_pkg_dir_parent() { + let path = "tests/fixtures/js-hello-world".to_owned(); + assert!(command::pack::pack(Some(path), &utils::get_nop_logger()).is_ok()) +} + +#[test] +fn pack_does_error_when_path_is_not_to_pkg_dir_or_parent() { + let path = "tests/manifest".to_owned(); + let result = command::pack::pack(Some(path), &utils::get_nop_logger()); + assert!(result.is_err()); + assert!(match result.unwrap_err() { + error::Error::PkgNotFound { .. } => true, + _ => false, + }); +} diff --git a/tests/manifest/utils.rs b/tests/manifest/utils.rs index 25add4640..38940e710 100644 --- a/tests/manifest/utils.rs +++ b/tests/manifest/utils.rs @@ -4,6 +4,8 @@ use std::io::prelude::*; use failure::Error; use serde_json; +use slog::{Discard, Logger}; + #[derive(Deserialize)] pub struct NpmPackage { pub name: String, @@ -31,3 +33,7 @@ pub fn read_package_json(path: &str) -> Result { Ok(serde_json::from_str(&pkg_contents)?) } + +pub fn get_nop_logger() -> Logger { + Logger::root(Discard {}, o!()) +}