Skip to content

Commit

Permalink
simplify tests and update stale comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mikrostew committed Aug 21, 2018
1 parent b820e8a commit 849e7d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 58 deletions.
51 changes: 7 additions & 44 deletions crates/notion-core/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,11 @@ impl Manifest {
let toolchain_value = serde_json::to_value(toolchain).unknown()?;
map.insert("toolchain".to_string(), toolchain_value);

// TODO: write to file
// serialize the updated contents back to package.json
let file = File::create(package_file).unknown()?;
let formatter =
serde_json::ser::PrettyFormatter::with_indent(indent.indent().as_bytes());
let mut ser = serde_json::Serializer::with_formatter(file, formatter);

map.serialize(&mut ser).unknown()?;
}
Ok(())
Expand All @@ -128,39 +127,21 @@ pub mod tests {
#[test]
fn gets_node_version() {
let project_path = fixture_path("basic");
let version = match Manifest::for_dir(&project_path) {
Ok(manifest) => manifest.node().unwrap(),
_ => panic!(
"Error: Could not get manifest for project {:?}",
project_path
),
};
let version = Manifest::for_dir(&project_path).expect("Could not get manifest").node().unwrap();
assert_eq!(version, VersionReq::parse("=6.11.1").unwrap());
}

#[test]
fn gets_yarn_version() {
let project_path = fixture_path("basic");
let version = match Manifest::for_dir(&project_path) {
Ok(manifest) => manifest.yarn(),
_ => panic!(
"Error: Could not get manifest for project {:?}",
project_path
),
};
let version = Manifest::for_dir(&project_path).expect("Could not get manifest").yarn();
assert_eq!(version.unwrap(), VersionReq::parse("=1.2").unwrap());
}

#[test]
fn gets_dependencies() {
let project_path = fixture_path("basic");
let dependencies = match Manifest::for_dir(&project_path) {
Ok(manifest) => manifest.dependencies,
_ => panic!(
"Error: Could not get manifest for project {:?}",
project_path
),
};
let dependencies = Manifest::for_dir(&project_path).expect("Could not get manifest").dependencies;
let mut expected_deps = HashMap::new();
expected_deps.insert("@namespace/some-dep".to_string(), "0.2.4".to_string());
expected_deps.insert("rsvp".to_string(), "^3.5.0".to_string());
Expand All @@ -170,13 +151,7 @@ pub mod tests {
#[test]
fn gets_dev_dependencies() {
let project_path = fixture_path("basic");
let dev_dependencies = match Manifest::for_dir(&project_path) {
Ok(manifest) => manifest.dev_dependencies,
_ => panic!(
"Error: Could not get manifest for project {:?}",
project_path
),
};
let dev_dependencies = Manifest::for_dir(&project_path).expect("Could not get manifest").dev_dependencies;
let mut expected_deps = HashMap::new();
expected_deps.insert(
"@namespaced/something-else".to_string(),
Expand All @@ -189,26 +164,14 @@ pub mod tests {
#[test]
fn node_for_no_toolchain() {
let project_path = fixture_path("no_toolchain");
let manifest = match Manifest::for_dir(&project_path) {
Ok(manifest) => manifest,
_ => panic!(
"Error: Could not get manifest for project {:?}",
project_path
),
};
let manifest = Manifest::for_dir(&project_path).expect("Could not get manifest");
assert_eq!(manifest.node(), None);
}

#[test]
fn yarn_for_no_toolchain() {
let project_path = fixture_path("no_toolchain");
let manifest = match Manifest::for_dir(&project_path) {
Ok(manifest) => manifest,
_ => panic!(
"Error: Could not get manifest for project {:?}",
project_path
),
};
let manifest = Manifest::for_dir(&project_path).expect("Could not get manifest");
assert_eq!(manifest.yarn(), None);
}

Expand Down
16 changes: 2 additions & 14 deletions crates/notion-core/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,7 @@ pub mod tests {
let project_path = fixture_path("basic");
let test_project = Project::for_dir(&project_path).unwrap().unwrap();

let all_deps = match test_project.all_dependencies() {
Ok(deps) => deps,
_ => panic!(
"Error: Could not get dependencies for project {:?}",
project_path
),
};
let all_deps = test_project.all_dependencies().expect("Could not get dependencies");
let mut expected_deps = HashSet::new();
expected_deps.insert("@namespace/some-dep".to_string());
expected_deps.insert("rsvp".to_string());
Expand All @@ -267,13 +261,7 @@ pub mod tests {
let project_path = fixture_path("basic");
let test_project = Project::for_dir(&project_path).unwrap().unwrap();

let dep_bins = match test_project.dependent_binaries() {
Ok(bin_map) => bin_map,
_ => panic!(
"Error: Could not get dependent binaries for project {:?}",
project_path
),
};
let dep_bins = test_project.dependent_binaries().expect("Could not get dependent binaries");
let mut expected_bins = HashMap::new();
expected_bins.insert("eslint".to_string(), "./bin/eslint.js".to_string());
expected_bins.insert("rsvp".to_string(), "./bin/rsvp.js".to_string());
Expand Down

0 comments on commit 849e7d1

Please sign in to comment.