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

Made config add target_type to type instead of "target_type" #1988

Merged
merged 3 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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