diff options
-rw-r--r-- | tests/integration/lsp_tests.rs | 60 | ||||
-rw-r--r-- | tests/specs/README.md | 1 | ||||
-rw-r--r-- | tests/specs/check/types_resolved_relative_config/__test__.json | 5 | ||||
-rw-r--r-- | tests/specs/check/types_resolved_relative_config/main.out | 3 | ||||
-rw-r--r-- | tests/specs/check/types_resolved_relative_config/main.ts | 0 | ||||
-rw-r--r-- | tests/specs/check/types_resolved_relative_config/sub_dir/deno.json | 7 | ||||
-rw-r--r-- | tests/specs/mod.rs | 4 | ||||
-rw-r--r-- | tests/util/server/src/lib.rs | 11 |
8 files changed, 84 insertions, 7 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index f1a368413..09178cd46 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -80,12 +80,60 @@ fn lsp_tsconfig_types() { let mut client = context.new_lsp_command().build(); client.initialize(|builder| { - builder.set_config("types.tsconfig.json"); + builder + .set_config("types.tsconfig.json") + // avoid finding the declaration file via the document preload + .set_preload_limit(0); }); let diagnostics = client.did_open(json!({ "textDocument": { - "uri": Url::from_file_path(temp_dir.path().join("test.ts")).unwrap(), + "uri": temp_dir.uri().join("test.ts").unwrap(), + "languageId": "typescript", + "version": 1, + "text": "console.log(a);\n" + } + })); + + assert_eq!(diagnostics.all().len(), 0); + + client.shutdown(); +} + +#[test] +fn lsp_tsconfig_types_config_sub_dir() { + let context = TestContextBuilder::new().use_temp_cwd().build(); + let temp_dir = context.temp_dir(); + + let sub_dir = temp_dir.path().join("sub_dir"); + sub_dir.create_dir_all(); + sub_dir.join("types.tsconfig.json").write( + r#"{ + "compilerOptions": { + "types": ["./a.d.ts"] + }, + "lint": { + "rules": { + "tags": [] + } + } +}"#, + ); + let a_dts = "// deno-lint-ignore-file no-var\ndeclare var a: string;"; + sub_dir.join("a.d.ts").write(a_dts); + temp_dir.write("deno.json", "{}"); + + let mut client = context.new_lsp_command().build(); + client.initialize(|builder| { + builder + .set_config("sub_dir/types.tsconfig.json") + // avoid finding the declaration file via the document preload + .set_preload_limit(0); + }); + + let diagnostics = client.did_open(json!({ + "textDocument": { + "uri": temp_dir.uri().join("test.ts").unwrap(), "languageId": "typescript", "version": 1, "text": "console.log(a);\n" @@ -164,7 +212,7 @@ fn lsp_import_map() { builder.set_import_map("import-map.json"); }); - let uri = Url::from_file_path(temp_dir.path().join("a.ts")).unwrap(); + let uri = temp_dir.uri().join("a.ts").unwrap(); let diagnostics = client.did_open(json!({ "textDocument": { @@ -10801,7 +10849,7 @@ fn lsp_data_urls_with_jsx_compiler_option() { let mut client = context.new_lsp_command().build(); client.initialize_default(); - let uri = Url::from_file_path(temp_dir.path().join("main.ts")).unwrap(); + let uri = temp_dir.uri().join("main.ts").unwrap(); let diagnostics = client.did_open(json!({ "textDocument": { @@ -11683,7 +11731,7 @@ fn decorators_tc39() { let mut client = context.new_lsp_command().build(); client.initialize_default(); - let uri = Url::from_file_path(temp_dir.path().join("main.ts")).unwrap(); + let uri = temp_dir.uri().join("main.ts").unwrap(); let diagnostics = client .did_open(json!({ @@ -11734,7 +11782,7 @@ fn decorators_ts() { let mut client = context.new_lsp_command().build(); client.initialize_default(); - let uri = Url::from_file_path(temp_dir.path().join("main.ts")).unwrap(); + let uri = temp_dir.uri().join("main.ts").unwrap(); let diagnostics = client .did_open(json!({ diff --git a/tests/specs/README.md b/tests/specs/README.md index bbd9b880c..d04adbb62 100644 --- a/tests/specs/README.md +++ b/tests/specs/README.md @@ -90,3 +90,4 @@ Within the file, you can use the following for matching: - `[WILDCHARS(5)]` - match any of the next 5 characters - `[UNORDERED_START]` followed by many lines then `[UNORDERED_END]` will match the lines in any order (useful for non-deterministic output) +- `[# example]` - line comments start with `[#` and end with `]` diff --git a/tests/specs/check/types_resolved_relative_config/__test__.json b/tests/specs/check/types_resolved_relative_config/__test__.json new file mode 100644 index 000000000..6f4937209 --- /dev/null +++ b/tests/specs/check/types_resolved_relative_config/__test__.json @@ -0,0 +1,5 @@ +{ + "args": "check --config sub_dir/deno.json main.ts", + "output": "main.out", + "exitCode": 1 +} diff --git a/tests/specs/check/types_resolved_relative_config/main.out b/tests/specs/check/types_resolved_relative_config/main.out new file mode 100644 index 000000000..212e1224c --- /dev/null +++ b/tests/specs/check/types_resolved_relative_config/main.out @@ -0,0 +1,3 @@ +[# It should be resolving relative the config in sub_dir instead of the cwd] +error: Module not found "file:///[WILDLINE]/sub_dir/a.d.ts". + at file:///[WILDLINE]/sub_dir/deno.json:1:1 diff --git a/tests/specs/check/types_resolved_relative_config/main.ts b/tests/specs/check/types_resolved_relative_config/main.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/specs/check/types_resolved_relative_config/main.ts diff --git a/tests/specs/check/types_resolved_relative_config/sub_dir/deno.json b/tests/specs/check/types_resolved_relative_config/sub_dir/deno.json new file mode 100644 index 000000000..ba7f3344d --- /dev/null +++ b/tests/specs/check/types_resolved_relative_config/sub_dir/deno.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "types": [ + "./a.d.ts" + ] + } +} diff --git a/tests/specs/mod.rs b/tests/specs/mod.rs index 6a61ae2a6..7795f47de 100644 --- a/tests/specs/mod.rs +++ b/tests/specs/mod.rs @@ -24,6 +24,10 @@ pub fn main() { // todo(dsherret): the output should be changed to be terse // when it passes, but verbose on failure for category in &categories { + if category.tests.is_empty() { + continue; // skip output when all the tests have been filtered out + } + eprintln!(); eprintln!(" {} {}", colors::green_bold("Running"), category.name); eprintln!(); diff --git a/tests/util/server/src/lib.rs b/tests/util/server/src/lib.rs index 5fd403992..6bc729199 100644 --- a/tests/util/server/src/lib.rs +++ b/tests/util/server/src/lib.rs @@ -668,7 +668,16 @@ pub fn wildcard_match_detailed( // Normalize line endings let original_text = text.replace("\r\n", "\n"); let mut current_text = original_text.as_str(); - let pattern = pattern.replace("\r\n", "\n"); + // normalize line endings and strip comments + let pattern = pattern + .split('\n') + .map(|line| line.trim_end_matches('\r')) + .filter(|l| { + let is_comment = l.starts_with("[#") && l.ends_with(']'); + !is_comment + }) + .collect::<Vec<_>>() + .join("\n"); let mut output_lines = Vec::new(); let parts = parse_wildcard_pattern_text(&pattern).unwrap(); |