diff options
Diffstat (limited to 'cli/lsp')
-rw-r--r-- | cli/lsp/completions.rs | 8 | ||||
-rw-r--r-- | cli/lsp/diagnostics.rs | 36 | ||||
-rw-r--r-- | cli/lsp/documents.rs | 14 | ||||
-rw-r--r-- | cli/lsp/registries.rs | 14 | ||||
-rw-r--r-- | cli/lsp/tsc.rs | 30 |
5 files changed, 70 insertions, 32 deletions
diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs index b727c6198..860ca4b3d 100644 --- a/cli/lsp/completions.rs +++ b/cli/lsp/completions.rs @@ -578,7 +578,7 @@ mod tests { use std::collections::HashMap; use std::path::Path; use std::sync::Arc; - use tempfile::TempDir; + use test_util::TempDir; fn mock_documents( fixtures: &[(&str, &str, i32, LanguageId)], @@ -612,10 +612,10 @@ mod tests { } fn setup( + temp_dir: &TempDir, documents: &[(&str, &str, i32, LanguageId)], sources: &[(&str, &str)], ) -> Documents { - let temp_dir = TempDir::new().expect("could not create temp dir"); let location = temp_dir.path().join("deps"); mock_documents(documents, sources, &location) } @@ -717,7 +717,7 @@ mod tests { #[test] fn test_get_local_completions() { - let temp_dir = TempDir::new().expect("could not create temp dir"); + let temp_dir = TempDir::new(); let fixtures = temp_dir.path().join("fixtures"); std::fs::create_dir(&fixtures).expect("could not create"); let dir_a = fixtures.join("a"); @@ -776,7 +776,9 @@ mod tests { character: 21, }, }; + let temp_dir = TempDir::new(); let documents = setup( + &temp_dir, &[ ( "file:///a/b/c.ts", diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index 59fc1c43b..fd905f6e0 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -884,7 +884,7 @@ mod tests { use crate::lsp::language_server::StateSnapshot; use std::path::Path; use std::path::PathBuf; - use tempfile::TempDir; + use test_util::TempDir; fn mock_state_snapshot( fixtures: &[(&str, &str, i32, LanguageId)], @@ -922,9 +922,9 @@ mod tests { } fn setup( + temp_dir: &TempDir, sources: &[(&str, &str, i32, LanguageId)], ) -> (StateSnapshot, PathBuf) { - let temp_dir = TempDir::new().expect("could not create temp dir"); let location = temp_dir.path().join("deps"); let state_snapshot = mock_state_snapshot(sources, &location); (state_snapshot, location) @@ -932,16 +932,20 @@ mod tests { #[tokio::test] async fn test_enabled_then_disabled_specifier() { + let temp_dir = TempDir::new(); let specifier = ModuleSpecifier::parse("file:///a.ts").unwrap(); - let (snapshot, _) = setup(&[( - "file:///a.ts", - r#"import * as b from "./b.ts"; + let (snapshot, _) = setup( + &temp_dir, + &[( + "file:///a.ts", + r#"import * as b from "./b.ts"; let a: any = "a"; let c: number = "a"; "#, - 1, - LanguageId::TypeScript, - )]); + 1, + LanguageId::TypeScript, + )], + ); let snapshot = Arc::new(snapshot); let ts_server = TsServer::new(Default::default()); @@ -1026,12 +1030,16 @@ let c: number = "a"; #[tokio::test] async fn test_cancelled_ts_diagnostics_request() { - let (snapshot, _) = setup(&[( - "file:///a.ts", - r#"export let a: string = 5;"#, - 1, - LanguageId::TypeScript, - )]); + let temp_dir = TempDir::new(); + let (snapshot, _) = setup( + &temp_dir, + &[( + "file:///a.ts", + r#"export let a: string = 5;"#, + 1, + LanguageId::TypeScript, + )], + ); let snapshot = Arc::new(snapshot); let ts_server = TsServer::new(Default::default()); diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index 28ef19af9..61ab1c4b6 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -1134,10 +1134,9 @@ impl Documents { #[cfg(test)] mod tests { use super::*; - use tempfile::TempDir; + use test_util::TempDir; - fn setup() -> (Documents, PathBuf) { - let temp_dir = TempDir::new().unwrap(); + fn setup(temp_dir: &TempDir) -> (Documents, PathBuf) { let location = temp_dir.path().join("deps"); let documents = Documents::new(&location); (documents, location) @@ -1145,7 +1144,8 @@ mod tests { #[test] fn test_documents_open() { - let (mut documents, _) = setup(); + let temp_dir = TempDir::new(); + let (mut documents, _) = setup(&temp_dir); let specifier = ModuleSpecifier::parse("file:///a.ts").unwrap(); let content = Arc::new( r#"import * as b from "./b.ts"; @@ -1161,7 +1161,8 @@ console.log(b); #[test] fn test_documents_change() { - let (mut documents, _) = setup(); + let temp_dir = TempDir::new(); + let (mut documents, _) = setup(&temp_dir); let specifier = ModuleSpecifier::parse("file:///a.ts").unwrap(); let content = Arc::new( r#"import * as b from "./b.ts"; @@ -1207,7 +1208,8 @@ console.log(b, "hello deno"); fn test_documents_ensure_no_duplicates() { // it should never happen that a user of this API causes this to happen, // but we'll guard against it anyway - let (mut documents, documents_path) = setup(); + let temp_dir = TempDir::new(); + let (mut documents, documents_path) = setup(&temp_dir); let file_path = documents_path.join("file.ts"); let file_specifier = ModuleSpecifier::from_file_path(&file_path).unwrap(); fs::create_dir_all(&documents_path).unwrap(); diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs index 48a879185..45dac2f48 100644 --- a/cli/lsp/registries.rs +++ b/cli/lsp/registries.rs @@ -1050,7 +1050,7 @@ impl ModuleRegistry { #[cfg(test)] mod tests { use super::*; - use tempfile::TempDir; + use test_util::TempDir; #[test] fn test_validate_registry_configuration() { @@ -1205,7 +1205,7 @@ mod tests { #[tokio::test] async fn test_registry_completions_origin_match() { let _g = test_util::http_server(); - let temp_dir = TempDir::new().expect("could not create tmp"); + let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let mut module_registry = ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap(); @@ -1266,7 +1266,7 @@ mod tests { #[tokio::test] async fn test_registry_completions() { let _g = test_util::http_server(); - let temp_dir = TempDir::new().expect("could not create tmp"); + let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let mut module_registry = ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap(); @@ -1489,7 +1489,7 @@ mod tests { #[tokio::test] async fn test_registry_completions_key_first() { let _g = test_util::http_server(); - let temp_dir = TempDir::new().expect("could not create tmp"); + let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let mut module_registry = ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap(); @@ -1559,7 +1559,7 @@ mod tests { #[tokio::test] async fn test_registry_completions_complex() { let _g = test_util::http_server(); - let temp_dir = TempDir::new().expect("could not create tmp"); + let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let mut module_registry = ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap(); @@ -1610,7 +1610,7 @@ mod tests { #[tokio::test] async fn test_check_origin_supported() { let _g = test_util::http_server(); - let temp_dir = TempDir::new().expect("could not create tmp"); + let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let module_registry = ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap(); @@ -1621,7 +1621,7 @@ mod tests { #[tokio::test] async fn test_check_origin_not_supported() { let _g = test_util::http_server(); - let temp_dir = TempDir::new().expect("could not create tmp"); + let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let module_registry = ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap(); diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index e2aad4524..64560cefb 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -3298,7 +3298,7 @@ mod tests { use crate::lsp::text::LineIndex; use std::path::Path; use std::path::PathBuf; - use tempfile::TempDir; + use test_util::TempDir; fn mock_state_snapshot( fixtures: &[(&str, &str, i32, LanguageId)], @@ -3322,11 +3322,11 @@ mod tests { } fn setup( + temp_dir: &TempDir, debug: bool, config: Value, sources: &[(&str, &str, i32, LanguageId)], ) -> (JsRuntime, Arc<StateSnapshot>, PathBuf) { - let temp_dir = TempDir::new().expect("could not create temp dir"); let location = temp_dir.path().join("deps"); let state_snapshot = Arc::new(mock_state_snapshot(sources, &location)); let mut runtime = js_runtime(Default::default()); @@ -3363,7 +3363,9 @@ mod tests { #[test] fn test_project_configure() { + let temp_dir = TempDir::new(); setup( + &temp_dir, false, json!({ "target": "esnext", @@ -3376,7 +3378,9 @@ mod tests { #[test] fn test_project_reconfigure() { + let temp_dir = TempDir::new(); let (mut runtime, state_snapshot, _) = setup( + &temp_dir, false, json!({ "target": "esnext", @@ -3404,7 +3408,9 @@ mod tests { #[test] fn test_get_diagnostics() { + let temp_dir = TempDir::new(); let (mut runtime, state_snapshot, _) = setup( + &temp_dir, false, json!({ "target": "esnext", @@ -3453,7 +3459,9 @@ mod tests { #[test] fn test_get_diagnostics_lib() { + let temp_dir = TempDir::new(); let (mut runtime, state_snapshot, _) = setup( + &temp_dir, false, json!({ "target": "esnext", @@ -3483,7 +3491,9 @@ mod tests { #[test] fn test_module_resolution() { + let temp_dir = TempDir::new(); let (mut runtime, state_snapshot, _) = setup( + &temp_dir, false, json!({ "target": "esnext", @@ -3518,7 +3528,9 @@ mod tests { #[test] fn test_bad_module_specifiers() { + let temp_dir = TempDir::new(); let (mut runtime, state_snapshot, _) = setup( + &temp_dir, false, json!({ "target": "esnext", @@ -3569,7 +3581,9 @@ mod tests { #[test] fn test_remote_modules() { + let temp_dir = TempDir::new(); let (mut runtime, state_snapshot, _) = setup( + &temp_dir, false, json!({ "target": "esnext", @@ -3604,7 +3618,9 @@ mod tests { #[test] fn test_partial_modules() { + let temp_dir = TempDir::new(); let (mut runtime, state_snapshot, _) = setup( + &temp_dir, false, json!({ "target": "esnext", @@ -3676,7 +3692,9 @@ mod tests { #[test] fn test_no_debug_failure() { + let temp_dir = TempDir::new(); let (mut runtime, state_snapshot, _) = setup( + &temp_dir, false, json!({ "target": "esnext", @@ -3726,7 +3744,9 @@ mod tests { #[test] fn test_request_asset() { + let temp_dir = TempDir::new(); let (mut runtime, state_snapshot, _) = setup( + &temp_dir, false, json!({ "target": "esnext", @@ -3752,7 +3772,9 @@ mod tests { #[test] fn test_modify_sources() { + let temp_dir = TempDir::new(); let (mut runtime, state_snapshot, location) = setup( + &temp_dir, false, json!({ "target": "esnext", @@ -3839,7 +3861,9 @@ mod tests { #[test] fn test_op_exists() { + let temp_dir = TempDir::new(); let (mut rt, state_snapshot, _) = setup( + &temp_dir, false, json!({ "target": "esnext", @@ -3910,7 +3934,9 @@ mod tests { character: 16, }) .unwrap(); + let temp_dir = TempDir::new(); let (mut runtime, state_snapshot, _) = setup( + &temp_dir, false, json!({ "target": "esnext", |