Skip to content

Commit

Permalink
Add tests for pack
Browse files Browse the repository at this point in the history
  • Loading branch information
Mackiovello committed Jul 16, 2018
1 parent 88fdbc5 commit 90c3fec
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pub mod init;
mod login;
mod pack;
pub mod pack;
mod publish;
pub mod utils;

Expand Down
2 changes: 2 additions & 0 deletions src/command/pack.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Pack function to use npm pack

use command::utils::{find_pkg_directory, set_crate_path};
use error::Error;
use npm;
Expand Down
27 changes: 27 additions & 0 deletions tests/manifest/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
});
}
6 changes: 6 additions & 0 deletions tests/manifest/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -31,3 +33,7 @@ pub fn read_package_json(path: &str) -> Result<NpmPackage, Error> {

Ok(serde_json::from_str(&pkg_contents)?)
}

pub fn get_nop_logger() -> Logger {
Logger::root(Discard {}, o!())
}

0 comments on commit 90c3fec

Please sign in to comment.