Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Made config add target_type to type instead of "target_type" (#1988)
Browse files Browse the repository at this point in the history
* Made config add target_type to type instead of "target_type"

* Added test for toml generate and fixed a warning
  • Loading branch information
jspspike committed Jul 7, 2021
1 parent ecf636a commit bdda569
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
28 changes: 27 additions & 1 deletion src/settings/toml/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl Manifest {
config_template_doc["workers_dev"] = toml_edit::value(default_workers_dev);
}
if let Some(target_type) = &target_type {
config_template_doc["target_type"] = toml_edit::value(target_type.to_string());
config_template_doc["type"] = toml_edit::value(target_type.to_string());
}
if let Some(site) = site {
if config_template.site.is_none() {
Expand Down Expand Up @@ -685,3 +685,29 @@ fn get_namespaces(
Ok(Vec::new())
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn generate() -> Result<()> {
let toml_path = Path::new(".");

let toml = Manifest::generate(
"test".to_string(),
Some(TargetType::JavaScript),
toml_path,
None,
)?;
assert_eq!(toml.name.to_string(), "test".to_string());
assert_eq!(toml.target_type.to_string(), "javascript".to_string());
fs::remove_file(toml_path.with_file_name("wrangler.toml"))?;

let toml = Manifest::generate("test".to_string(), None, toml_path, None)?;
assert_eq!(toml.target_type.to_string(), "webpack".to_string());
fs::remove_file(toml_path.with_file_name("wrangler.toml"))?;

Ok(())
}
}
2 changes: 1 addition & 1 deletion src/settings/toml/target_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Default for TargetType {
impl fmt::Display for TargetType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let printable = match *self {
TargetType::JavaScript => "js",
TargetType::JavaScript => "javascript",
TargetType::Rust => "rust",
TargetType::Webpack => "webpack",
};
Expand Down
11 changes: 5 additions & 6 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ fn it_builds_with_webpack_name_output_warn() {

assert!(
stderr.contains("webpack's output filename is being renamed"),
format!("given: {}", stderr)
"given: {}",
stderr
);
}

Expand Down Expand Up @@ -415,11 +416,9 @@ fn build_fails_with(fixture: &Fixture, expected_message: &str) {
str::from_utf8(&output.stderr)
.unwrap()
.contains(expected_message),
format!(
"expected {:?} not found, given: {:?}",
expected_message,
str::from_utf8(&output.stderr)
)
"expected {:?} not found, given: {:?}",
expected_message,
str::from_utf8(&output.stderr)
);
}

Expand Down

0 comments on commit bdda569

Please sign in to comment.