summaryrefslogtreecommitdiff
path: root/cli/tests/integration_tests.rs
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2021-02-18 22:01:32 +0530
committerGitHub <noreply@github.com>2021-02-18 17:31:32 +0100
commitd9b1f96897239bf7de8cdfd11d40e3f99bb29a4a (patch)
tree4a1c60d4850111f738b485bbad5f43659bd9ed09 /cli/tests/integration_tests.rs
parentc0f10e72ee64f1512e6aff20a841f4696e774217 (diff)
feat: add json(c) support to deno fmt (#9292)
This commit adds support for formatting JSON and JSONC in "deno fmt". New values "json" and "jsonc" are added to "--ext" flag for standard input processing.
Diffstat (limited to 'cli/tests/integration_tests.rs')
-rw-r--r--cli/tests/integration_tests.rs42
1 files changed, 33 insertions, 9 deletions
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 988372b17..b55111154 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -496,30 +496,43 @@ mod integration {
fn fmt_test() {
let t = TempDir::new().expect("tempdir fail");
let fixed_js = util::root_path().join("cli/tests/badly_formatted_fixed.js");
- let fixed_md = util::root_path().join("cli/tests/badly_formatted_fixed.md");
let badly_formatted_original_js =
util::root_path().join("cli/tests/badly_formatted.mjs");
- let badly_formatted_original_md =
- util::root_path().join("cli/tests/badly_formatted.md");
let badly_formatted_js = t.path().join("badly_formatted.js");
- let badly_formatted_md = t.path().join("badly_formatted.md");
let badly_formatted_js_str = badly_formatted_js.to_str().unwrap();
- let badly_formatted_md_str = badly_formatted_md.to_str().unwrap();
std::fs::copy(&badly_formatted_original_js, &badly_formatted_js)
.expect("Failed to copy file");
+
+ let fixed_md = util::root_path().join("cli/tests/badly_formatted_fixed.md");
+ let badly_formatted_original_md =
+ util::root_path().join("cli/tests/badly_formatted.md");
+ let badly_formatted_md = t.path().join("badly_formatted.md");
+ let badly_formatted_md_str = badly_formatted_md.to_str().unwrap();
std::fs::copy(&badly_formatted_original_md, &badly_formatted_md)
.expect("Failed to copy file");
+
+ let fixed_json =
+ util::root_path().join("cli/tests/badly_formatted_fixed.json");
+ let badly_formatted_original_json =
+ util::root_path().join("cli/tests/badly_formatted.json");
+ let badly_formatted_json = t.path().join("badly_formatted.json");
+ let badly_formatted_json_str = badly_formatted_json.to_str().unwrap();
+ std::fs::copy(&badly_formatted_original_json, &badly_formatted_json)
+ .expect("Failed to copy file");
// First, check formatting by ignoring the badly formatted file.
let status = util::deno_cmd()
.current_dir(util::root_path())
.arg("fmt")
.arg(format!(
- "--ignore={},{}",
- badly_formatted_js_str, badly_formatted_md_str
+ "--ignore={},{},{}",
+ badly_formatted_js_str,
+ badly_formatted_md_str,
+ badly_formatted_json_str
))
.arg("--check")
.arg(badly_formatted_js_str)
.arg(badly_formatted_md_str)
+ .arg(badly_formatted_json_str)
.spawn()
.expect("Failed to spawn script")
.wait()
@@ -532,6 +545,7 @@ mod integration {
.arg("--check")
.arg(badly_formatted_js_str)
.arg(badly_formatted_md_str)
+ .arg(badly_formatted_json_str)
.spawn()
.expect("Failed to spawn script")
.wait()
@@ -543,6 +557,7 @@ mod integration {
.arg("fmt")
.arg(badly_formatted_js_str)
.arg(badly_formatted_md_str)
+ .arg(badly_formatted_json_str)
.spawn()
.expect("Failed to spawn script")
.wait()
@@ -550,10 +565,13 @@ mod integration {
assert!(status.success());
let expected_js = std::fs::read_to_string(fixed_js).unwrap();
let expected_md = std::fs::read_to_string(fixed_md).unwrap();
+ let expected_json = std::fs::read_to_string(fixed_json).unwrap();
let actual_js = std::fs::read_to_string(badly_formatted_js).unwrap();
let actual_md = std::fs::read_to_string(badly_formatted_md).unwrap();
+ let actual_json = std::fs::read_to_string(badly_formatted_json).unwrap();
assert_eq!(expected_js, actual_js);
assert_eq!(expected_md, actual_md);
+ assert_eq!(expected_json, actual_json);
}
mod file_watcher {
@@ -2838,7 +2856,7 @@ console.log("finish");
});
itest!(fmt_check_tests_dir {
- args: "fmt --check ./",
+ args: "fmt --check ./ --ignore=.test_coverage",
output: "fmt/expected_fmt_check_tests_dir.out",
exit_code: 1,
});
@@ -2850,7 +2868,7 @@ console.log("finish");
});
itest!(fmt_check_formatted_files {
- args: "fmt --check fmt/formatted1.js fmt/formatted2.ts fmt/formatted3.md",
+ args: "fmt --check fmt/formatted1.js fmt/formatted2.ts fmt/formatted3.md fmt/formatted4.jsonc",
output: "fmt/expected_fmt_check_formatted_files.out",
exit_code: 0,
});
@@ -2875,6 +2893,12 @@ console.log("finish");
),
});
+ itest!(fmt_stdin_json {
+ args: "fmt --ext=json -",
+ input: Some("{ \"key\": \"value\"}"),
+ output_str: Some("{ \"key\": \"value\" }\n"),
+ });
+
itest!(fmt_stdin_check_formatted {
args: "fmt --check -",
input: Some("const a = 1;\n"),