Skip to content

Commit

Permalink
use absolutize crate instead of std canonicalize for crate absolute path
Browse files Browse the repository at this point in the history
add two tests from use cases:
- transitive dependencies
- crc crate
  • Loading branch information
xmclark committed Oct 30, 2018
1 parent d689c50 commit 87c9ae0
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 52 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ indicatif = "0.9.0"
lazy_static = "1.1.0"
openssl = { version = '0.10.11', optional = true }
parking_lot = "0.6"
path-absolutize = "1.1.1"
serde = "1.0.74"
serde_derive = "1.0.74"
serde_json = "1.0.26"
Expand Down
8 changes: 4 additions & 4 deletions src/command/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

use emoji;
use failure;
use path_absolutize::*;
use progressbar::Step;
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
use PBAR;

/// If an explicit path is given, then use it, otherwise assume the current
/// directory is the crate path.
pub fn set_crate_path(path: Option<PathBuf>) -> io::Result<PathBuf> {
pub fn set_crate_path(path: Option<PathBuf>) -> Result<PathBuf, failure::Error> {
let crate_path = match path {
Some(p) => p,
None => PathBuf::from("."),
};

crate_path.canonicalize()
let absolute_crate_path = crate_path.absolutize()?;
Ok(absolute_crate_path)
}

/// Construct our `pkg` directory in the crate.
Expand Down
5 changes: 1 addition & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ pub enum Error {
/// An error invoking another CLI tool.
#[fail(
display = "Process exited with {}: {}.\n\nstdout:{}\n\nstderr:\n\n{}",
exit_status,
message,
stdout,
stderr
exit_status, message, stdout, stderr
)]
Cli {
/// Error message.
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern crate indicatif;
#[macro_use]
extern crate lazy_static;
extern crate parking_lot;
extern crate path_absolutize;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
Expand Down
26 changes: 12 additions & 14 deletions tests/all/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ fn can_download_prebuilt_wasm_bindgen() {
use std::env;
let dir = tempfile::TempDir::new().unwrap();
bindgen::download_prebuilt_wasm_bindgen(dir.path(), "0.2.21").unwrap();
assert!(
dir.path()
.join("bin")
.join("wasm-bindgen")
.with_extension(env::consts::EXE_EXTENSION)
.is_file()
);
assert!(
dir.path()
.join("bin")
.join("wasm-bindgen-test-runner")
.with_extension(env::consts::EXE_EXTENSION)
.is_file()
);
assert!(dir
.path()
.join("bin")
.join("wasm-bindgen")
.with_extension(env::consts::EXE_EXTENSION)
.is_file());
assert!(dir
.path()
.join("bin")
.join("wasm-bindgen-test-runner")
.with_extension(env::consts::EXE_EXTENSION)
.is_file());
}

#[test]
Expand Down
30 changes: 30 additions & 0 deletions tests/all/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,33 @@ fn it_should_build_js_hello_world_example() {
command::run_wasm_pack(cli.cmd, &logger)
.expect("running wasm-pack in a js-hello-world directory should succeed.");
}

#[test]
fn it_should_build_nested_project_with_transitive_dependencies() {
let fixture = utils::fixture::transitive_dependencies();
fixture.install_local_wasm_bindgen();
let cli = Cli::from_iter_safe(vec![
"wasm-pack",
"build",
&fixture.path.join("main").display().to_string(),
])
.unwrap();
let logger = logger::new(&cli.cmd, cli.verbosity).unwrap();
command::run_wasm_pack(cli.cmd, &logger)
.expect("running wasm-pack in a project with transitive dependencies should succeed.");
}

#[test]
fn it_should_build_project_with_dependency_on_crc_crate() {
let fixture = utils::fixture::project_with_crc();
fixture.install_local_wasm_bindgen();
let cli = Cli::from_iter_safe(vec![
"wasm-pack",
"build",
&fixture.path.display().to_string(),
])
.unwrap();
let logger = logger::new(&cli.cmd, cli.verbosity).unwrap();
command::run_wasm_pack(cli.cmd, &logger)
.expect("running wasm-pack in a project with dependency on crc crate should succeed.");
}
63 changes: 33 additions & 30 deletions tests/all/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ fn it_creates_a_package_json_default_path() {
"js_hello_world.d.ts",
"js_hello_world.js",
]
.iter()
.map(|&s| String::from(s))
.collect();
.iter()
.map(|&s| String::from(s))
.collect();
assert_eq!(actual_files, expected_files);
}

Expand All @@ -109,9 +109,9 @@ fn it_creates_a_package_json_provided_path() {
"js_hello_world.d.ts",
"js_hello_world.js",
]
.iter()
.map(|&s| String::from(s))
.collect();
.iter()
.map(|&s| String::from(s))
.collect();
assert_eq!(actual_files, expected_files);
}

Expand All @@ -121,17 +121,15 @@ fn it_creates_a_package_json_provided_path_with_scope() {
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,
&Some("test".to_string()),
false,
"",
&step
)
.is_ok()
);
assert!(manifest::write_package_json(
&fixture.path,
&out_dir,
&Some("test".to_string()),
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());
Expand All @@ -145,9 +143,9 @@ fn it_creates_a_package_json_provided_path_with_scope() {
"js_hello_world.d.ts",
"js_hello_world.js",
]
.iter()
.map(|&s| String::from(s))
.collect();
.iter()
.map(|&s| String::from(s))
.collect();
assert_eq!(actual_files, expected_files);
}

Expand Down Expand Up @@ -180,9 +178,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() {
"js_hello_world_bg.js",
"js_hello_world.d.ts",
]
.iter()
.map(|&s| String::from(s))
.collect();
.iter()
.map(|&s| String::from(s))
.collect();
assert_eq!(actual_files, expected_files);
}

Expand All @@ -192,10 +190,15 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() {
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, "no-modules", &step)
.is_ok()
);
assert!(manifest::write_package_json(
&fixture.path,
&out_dir,
&None,
false,
"no-modules",
&step
)
.is_ok());
let package_json_path = &out_dir.join("package.json");
assert!(fs::metadata(package_json_path).is_ok());
utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
Expand All @@ -215,9 +218,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() {
"js_hello_world.js",
"js_hello_world.d.ts",
]
.iter()
.map(|&s| String::from(s))
.collect();
.iter()
.map(|&s| String::from(s))
.collect();
assert_eq!(actual_files, expected_files);
}

Expand Down
Loading

0 comments on commit 87c9ae0

Please sign in to comment.