diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/integration/lsp_tests.rs | 52 | ||||
-rw-r--r-- | cli/tests/integration/run_tests.rs | 13 |
2 files changed, 64 insertions, 1 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index 711d0bcd8..9283b4021 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -10668,3 +10668,55 @@ fn lsp_sloppy_imports_warn() { client.shutdown(); } + +#[test] +fn sloppy_imports_not_enabled() { + let context = TestContextBuilder::new().use_temp_cwd().build(); + let temp_dir = context.temp_dir(); + let temp_dir = temp_dir.path(); + temp_dir.join("deno.json").write(r#"{}"#); + // The enhanced, more helpful error message is only available + // when the file exists on the file system at the moment because + // it's a little more complicated to hook it up otherwise. + temp_dir.join("a.ts").write("export class A {}"); + let mut client = context.new_lsp_command().build(); + client.initialize(|builder| { + builder.set_root_uri(temp_dir.uri_dir()); + }); + let diagnostics = client.did_open(json!({ + "textDocument": { + "uri": temp_dir.join("file.ts").uri_file(), + "languageId": "typescript", + "version": 1, + "text": "import * as a from './a';\nconsole.log(a)\n", + }, + })); + assert_eq!( + diagnostics.messages_with_source("deno"), + lsp::PublishDiagnosticsParams { + uri: temp_dir.join("file.ts").uri_file(), + diagnostics: vec![lsp::Diagnostic { + range: lsp::Range { + start: lsp::Position { + line: 0, + character: 19 + }, + end: lsp::Position { + line: 0, + character: 24 + } + }, + severity: Some(lsp::DiagnosticSeverity::ERROR), + code: Some(lsp::NumberOrString::String("no-local".to_string())), + source: Some("deno".to_string()), + message: format!( + "Unable to load a local module: {}\nMaybe add a '.ts' extension.", + temp_dir.join("a").uri_file(), + ), + ..Default::default() + }], + version: Some(1), + } + ); + client.shutdown(); +} diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 4e0bbdfd2..03de97ee7 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -4740,7 +4740,6 @@ itest!(unsafe_proto_flag { fn test_unstable_sloppy_imports() { let context = TestContextBuilder::new().use_temp_cwd().build(); let temp_dir = context.temp_dir(); - temp_dir.write("deno.json", r#"{ "unstable": ["sloppy-imports"] }"#); temp_dir.write("a.ts", "export class A {}"); temp_dir.write("b.js", "export class B {}"); temp_dir.write("c.mts", "export class C {}"); @@ -4771,6 +4770,18 @@ console.log(g.G); "#, ); + // run without sloppy imports + context + .new_command() + .args("run main.ts") + .run() + .assert_matches_text(r#"error: Module not found "file:///[WILDCARD]/a.js". Maybe change the extension to '.ts' or run with --unstable-sloppy-imports + at file:///[WILDCARD]/main.ts:1:20 +"#) + .assert_exit_code(1); + + // now run with sloppy imports + temp_dir.write("deno.json", r#"{ "unstable": ["sloppy-imports"] }"#); context .new_command() .args("run main.ts") |