summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/fmt_tests.rs31
-rw-r--r--cli/tests/integration/lsp_tests.rs163
-rw-r--r--cli/tests/testdata/fmt/deno.jsonc15
-rw-r--r--cli/tests/testdata/fmt/deno.malformed.jsonc12
-rw-r--r--cli/tests/testdata/fmt/deno.malformed2.jsonc12
-rw-r--r--cli/tests/testdata/fmt/fmt_with_config.out1
-rw-r--r--cli/tests/testdata/fmt/fmt_with_config/a.ts46
-rw-r--r--cli/tests/testdata/fmt/fmt_with_config/b.ts15
-rw-r--r--cli/tests/testdata/fmt/fmt_with_config/c.md17
-rw-r--r--cli/tests/testdata/fmt/fmt_with_config_and_flags.out1
-rw-r--r--cli/tests/testdata/fmt/fmt_with_malformed_config.out4
-rw-r--r--cli/tests/testdata/fmt/fmt_with_malformed_config2.out4
-rw-r--r--cli/tests/testdata/fmt/regular/formatted1.js (renamed from cli/tests/testdata/fmt/formatted1.js)0
-rw-r--r--cli/tests/testdata/fmt/regular/formatted2.ts (renamed from cli/tests/testdata/fmt/formatted2.ts)0
-rw-r--r--cli/tests/testdata/fmt/regular/formatted3.md (renamed from cli/tests/testdata/fmt/formatted3.md)0
-rw-r--r--cli/tests/testdata/fmt/regular/formatted4.jsonc (renamed from cli/tests/testdata/fmt/formatted4.jsonc)0
-rw-r--r--cli/tests/testdata/lsp/deno.fmt.jsonc11
17 files changed, 328 insertions, 4 deletions
diff --git a/cli/tests/integration/fmt_tests.rs b/cli/tests/integration/fmt_tests.rs
index 00565a5d0..2d7451694 100644
--- a/cli/tests/integration/fmt_tests.rs
+++ b/cli/tests/integration/fmt_tests.rs
@@ -129,25 +129,25 @@ fn fmt_ignore_unexplicit_files() {
}
itest!(fmt_check_tests_dir {
- args: "fmt --check ./ --ignore=.test_coverage",
+ args: "fmt --check ./ --ignore=.test_coverage,fmt/fmt_with_config/",
output: "fmt/expected_fmt_check_tests_dir.out",
exit_code: 1,
});
itest!(fmt_quiet_check_fmt_dir {
- args: "fmt --check --quiet fmt/",
+ args: "fmt --check --quiet fmt/regular/",
output_str: Some(""),
exit_code: 0,
});
itest!(fmt_check_formatted_files {
- args: "fmt --check fmt/formatted1.js fmt/formatted2.ts fmt/formatted3.md fmt/formatted4.jsonc",
+ args: "fmt --check fmt/regular/formatted1.js fmt/regular/formatted2.ts fmt/regular/formatted3.md fmt/regular/formatted4.jsonc",
output: "fmt/expected_fmt_check_formatted_files.out",
exit_code: 0,
});
itest!(fmt_check_ignore {
- args: "fmt --check --ignore=fmt/formatted1.js fmt/",
+ args: "fmt --check --ignore=fmt/regular/formatted1.js fmt/regular/",
output: "fmt/expected_fmt_check_ignore.out",
exit_code: 0,
});
@@ -181,3 +181,26 @@ itest!(fmt_stdin_check_not_formatted {
input: Some("const a = 1\n"),
output_str: Some("Not formatted stdin\n"),
});
+
+itest!(fmt_with_config {
+ args: "fmt --config fmt/deno.jsonc fmt/fmt_with_config/",
+ output: "fmt/fmt_with_config.out",
+});
+
+// Check if CLI flags take precedence
+itest!(fmt_with_config_and_flags {
+ args: "fmt --config fmt/deno.jsonc --ignore=fmt/fmt_with_config/a.ts,fmt/fmt_with_config/b.ts",
+ output: "fmt/fmt_with_config_and_flags.out",
+});
+
+itest!(fmt_with_malformed_config {
+ args: "fmt --config fmt/deno.malformed.jsonc",
+ output: "fmt/fmt_with_malformed_config.out",
+ exit_code: 1,
+});
+
+itest!(fmt_with_malformed_config2 {
+ args: "fmt --config fmt/deno.malformed2.jsonc",
+ output: "fmt/fmt_with_malformed_config2.out",
+ exit_code: 1,
+});
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs
index 1b8d35108..3d87c222d 100644
--- a/cli/tests/integration/lsp_tests.rs
+++ b/cli/tests/integration/lsp_tests.rs
@@ -3197,6 +3197,169 @@ fn lsp_format_markdown() {
}
#[test]
+fn lsp_format_with_config() {
+ let temp_dir = TempDir::new().expect("could not create temp dir");
+ let mut params: lsp::InitializeParams =
+ serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
+ let deno_fmt_jsonc =
+ serde_json::to_vec_pretty(&load_fixture("deno.fmt.jsonc")).unwrap();
+ fs::write(temp_dir.path().join("deno.fmt.jsonc"), deno_fmt_jsonc).unwrap();
+
+ params.root_uri = Some(Url::from_file_path(temp_dir.path()).unwrap());
+ if let Some(Value::Object(mut map)) = params.initialization_options {
+ map.insert("config".to_string(), json!("./deno.fmt.jsonc"));
+ params.initialization_options = Some(Value::Object(map));
+ }
+
+ let deno_exe = deno_exe_path();
+ let mut client = LspClient::new(&deno_exe).unwrap();
+ client
+ .write_request::<_, _, Value>("initialize", params)
+ .unwrap();
+
+ client
+ .write_notification(
+ "textDocument/didOpen",
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts",
+ "languageId": "typescript",
+ "version": 1,
+ "text": "export async function someVeryLongFunctionName() {\nconst response = fetch(\"http://localhost:4545/some/non/existent/path.json\");\nconsole.log(response.text());\nconsole.log(\"finished!\")\n}"
+ }
+ }),
+ )
+ .unwrap();
+
+ // The options below should be ignored in favor of configuration from config file.
+ let (maybe_res, maybe_err) = client
+ .write_request::<_, _, Value>(
+ "textDocument/formatting",
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts"
+ },
+ "options": {
+ "tabSize": 2,
+ "insertSpaces": true
+ }
+ }),
+ )
+ .unwrap();
+
+ assert!(maybe_err.is_none());
+ assert_eq!(
+ maybe_res,
+ Some(json!([{
+ "range": {
+ "start": {
+ "line": 1,
+ "character": 0
+ },
+ "end": {
+ "line": 1,
+ "character": 0
+ }
+ },
+ "newText": "\t"
+ },
+ {
+ "range": {
+ "start": {
+ "line": 1,
+ "character": 23
+ },
+ "end": {
+ "line": 1,
+ "character": 24
+ }
+ },
+ "newText": "\n\t\t'"
+ },
+ {
+ "range": {
+ "start": {
+ "line": 1,
+ "character": 73
+ },
+ "end": {
+ "line": 1,
+ "character": 74
+ }
+ },
+ "newText": "',\n\t"
+ },
+ {
+ "range": {
+ "start": {
+ "line": 2,
+ "character": 0
+ },
+ "end": {
+ "line": 2,
+ "character": 0
+ }
+ },
+ "newText": "\t"
+ },
+ {
+ "range": {
+ "start": {
+ "line": 3,
+ "character": 0
+ },
+ "end": {
+ "line": 3,
+ "character": 0
+ }
+ },
+ "newText": "\t"
+ },
+ {
+ "range": {
+ "start": {
+ "line": 3,
+ "character": 12
+ },
+ "end": {
+ "line": 3,
+ "character": 13
+ }
+ },
+ "newText": "'"
+ },
+ {
+ "range": {
+ "start": {
+ "line": 3,
+ "character": 22
+ },
+ "end": {
+ "line": 3,
+ "character": 24
+ }
+ },
+ "newText": "');"
+ },
+ {
+ "range": {
+ "start": {
+ "line": 4,
+ "character": 1
+ },
+ "end": {
+ "line": 4,
+ "character": 1
+ }
+ },
+ "newText": "\n"
+ }]
+ ))
+ );
+ shutdown(&mut client);
+}
+
+#[test]
fn lsp_markdown_no_diagnostics() {
let mut client = init("initialize_params.json");
client
diff --git a/cli/tests/testdata/fmt/deno.jsonc b/cli/tests/testdata/fmt/deno.jsonc
new file mode 100644
index 000000000..0e682cf36
--- /dev/null
+++ b/cli/tests/testdata/fmt/deno.jsonc
@@ -0,0 +1,15 @@
+{
+ "fmt": {
+ "files": {
+ "include": ["fmt/fmt_with_config/"],
+ "exclude": ["fmt/fmt_with_config/b.ts"]
+ },
+ "options": {
+ "useTabs": true,
+ "lineWidth": 40,
+ "indentWidth": 8,
+ "singleQuote": true,
+ "proseWrap": "always"
+ }
+ }
+}
diff --git a/cli/tests/testdata/fmt/deno.malformed.jsonc b/cli/tests/testdata/fmt/deno.malformed.jsonc
new file mode 100644
index 000000000..667480bdc
--- /dev/null
+++ b/cli/tests/testdata/fmt/deno.malformed.jsonc
@@ -0,0 +1,12 @@
+{
+ "fmt": {
+ "files": {
+ "include": ["fmt/fmt_with_config/"],
+ "exclude": ["fmt/fmt_with_config/b.ts"]
+ },
+ "dont_know_this_field": {},
+ "options": {
+ "useTabs": true
+ }
+ }
+}
diff --git a/cli/tests/testdata/fmt/deno.malformed2.jsonc b/cli/tests/testdata/fmt/deno.malformed2.jsonc
new file mode 100644
index 000000000..2210dc0c7
--- /dev/null
+++ b/cli/tests/testdata/fmt/deno.malformed2.jsonc
@@ -0,0 +1,12 @@
+{
+ "fmt": {
+ "files": {
+ "include": ["fmt/fmt_with_config/"],
+ "exclude": ["fmt/fmt_with_config/b.ts"],
+ "dont_know_this_field": {}
+ },
+ "options": {
+ "useTabs": true
+ }
+ }
+}
diff --git a/cli/tests/testdata/fmt/fmt_with_config.out b/cli/tests/testdata/fmt/fmt_with_config.out
new file mode 100644
index 000000000..158c556c2
--- /dev/null
+++ b/cli/tests/testdata/fmt/fmt_with_config.out
@@ -0,0 +1 @@
+Checked 2 files
diff --git a/cli/tests/testdata/fmt/fmt_with_config/a.ts b/cli/tests/testdata/fmt/fmt_with_config/a.ts
new file mode 100644
index 000000000..e0f32647b
--- /dev/null
+++ b/cli/tests/testdata/fmt/fmt_with_config/a.ts
@@ -0,0 +1,46 @@
+unitTest(
+ { perms: { net: true } },
+ async function responseClone() {
+ const response =
+ await fetch(
+ 'http://localhost:4545/fixture.json',
+ );
+ const response1 =
+ response.clone();
+ assert(
+ response !==
+ response1,
+ );
+ assertEquals(
+ response.status,
+ response1
+ .status,
+ );
+ assertEquals(
+ response.statusText,
+ response1
+ .statusText,
+ );
+ const u8a =
+ new Uint8Array(
+ await response
+ .arrayBuffer(),
+ );
+ const u8a1 =
+ new Uint8Array(
+ await response1
+ .arrayBuffer(),
+ );
+ for (
+ let i = 0;
+ i <
+ u8a.byteLength;
+ i++
+ ) {
+ assertEquals(
+ u8a[i],
+ u8a1[i],
+ );
+ }
+ },
+);
diff --git a/cli/tests/testdata/fmt/fmt_with_config/b.ts b/cli/tests/testdata/fmt/fmt_with_config/b.ts
new file mode 100644
index 000000000..5c37d51d2
--- /dev/null
+++ b/cli/tests/testdata/fmt/fmt_with_config/b.ts
@@ -0,0 +1,15 @@
+// This file should be excluded from formatting
+unitTest(
+ { perms: { net: true } },
+ async function fetchBodyUsedCancelStream() {
+ const response = await fetch(
+ "http://localhost:4545/fixture.json",
+ );
+ assert(response.body !== null);
+
+ assertEquals(response.bodyUsed, false);
+ const promise = response.body.cancel();
+ assertEquals(response.bodyUsed, true);
+ await promise;
+ },
+); \ No newline at end of file
diff --git a/cli/tests/testdata/fmt/fmt_with_config/c.md b/cli/tests/testdata/fmt/fmt_with_config/c.md
new file mode 100644
index 000000000..012f7e3d4
--- /dev/null
+++ b/cli/tests/testdata/fmt/fmt_with_config/c.md
@@ -0,0 +1,17 @@
+## Permissions
+
+Deno is secure by default. Therefore,
+unless you specifically enable it, a
+program run with Deno has no file,
+network, or environment access. Access
+to security sensitive functionality
+requires that permisisons have been
+granted to an executing script through
+command line flags, or a runtime
+permission prompt.
+
+For the following example `mod.ts` has
+been granted read-only access to the
+file system. It cannot write to the file
+system, or perform any other security
+sensitive functions.
diff --git a/cli/tests/testdata/fmt/fmt_with_config_and_flags.out b/cli/tests/testdata/fmt/fmt_with_config_and_flags.out
new file mode 100644
index 000000000..c05ac45a1
--- /dev/null
+++ b/cli/tests/testdata/fmt/fmt_with_config_and_flags.out
@@ -0,0 +1 @@
+Checked 1 file
diff --git a/cli/tests/testdata/fmt/fmt_with_malformed_config.out b/cli/tests/testdata/fmt/fmt_with_malformed_config.out
new file mode 100644
index 000000000..1a55613ef
--- /dev/null
+++ b/cli/tests/testdata/fmt/fmt_with_malformed_config.out
@@ -0,0 +1,4 @@
+error: Failed to parse "fmt" configuration
+
+Caused by:
+ unknown field `dont_know_this_field`, expected `options` or `files`
diff --git a/cli/tests/testdata/fmt/fmt_with_malformed_config2.out b/cli/tests/testdata/fmt/fmt_with_malformed_config2.out
new file mode 100644
index 000000000..948b6b5b8
--- /dev/null
+++ b/cli/tests/testdata/fmt/fmt_with_malformed_config2.out
@@ -0,0 +1,4 @@
+error: Failed to parse "fmt" configuration
+
+Caused by:
+ unknown field `dont_know_this_field`, expected `include` or `exclude`
diff --git a/cli/tests/testdata/fmt/formatted1.js b/cli/tests/testdata/fmt/regular/formatted1.js
index 587aa5b96..587aa5b96 100644
--- a/cli/tests/testdata/fmt/formatted1.js
+++ b/cli/tests/testdata/fmt/regular/formatted1.js
diff --git a/cli/tests/testdata/fmt/formatted2.ts b/cli/tests/testdata/fmt/regular/formatted2.ts
index 4a8036806..4a8036806 100644
--- a/cli/tests/testdata/fmt/formatted2.ts
+++ b/cli/tests/testdata/fmt/regular/formatted2.ts
diff --git a/cli/tests/testdata/fmt/formatted3.md b/cli/tests/testdata/fmt/regular/formatted3.md
index e6e616584..e6e616584 100644
--- a/cli/tests/testdata/fmt/formatted3.md
+++ b/cli/tests/testdata/fmt/regular/formatted3.md
diff --git a/cli/tests/testdata/fmt/formatted4.jsonc b/cli/tests/testdata/fmt/regular/formatted4.jsonc
index f0f72a6ed..f0f72a6ed 100644
--- a/cli/tests/testdata/fmt/formatted4.jsonc
+++ b/cli/tests/testdata/fmt/regular/formatted4.jsonc
diff --git a/cli/tests/testdata/lsp/deno.fmt.jsonc b/cli/tests/testdata/lsp/deno.fmt.jsonc
new file mode 100644
index 000000000..a0a851731
--- /dev/null
+++ b/cli/tests/testdata/lsp/deno.fmt.jsonc
@@ -0,0 +1,11 @@
+{
+ "fmt": {
+ "options": {
+ "useTabs": true,
+ "lineWidth": 40,
+ "indentWidth": 8,
+ "singleQuote": true,
+ "proseWrap": "always"
+ }
+ }
+}