diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/integration/lsp_tests.rs | 118 | ||||
-rw-r--r-- | cli/tests/testdata/lsp/did_open_params_tls_cert.json | 8 | ||||
-rw-r--r-- | cli/tests/testdata/lsp/initialize_params.json | 3 | ||||
-rw-r--r-- | cli/tests/testdata/lsp/initialize_params_tls_cert.json | 71 |
4 files changed, 200 insertions, 0 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index c992ca4cb..e831e8627 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -3216,6 +3216,124 @@ fn lsp_cache_location() { shutdown(&mut client); } +/// Sets the TLS root certificate on startup, which allows the LSP to connect to +/// the custom signed test server and be able to retrieve the registry config +/// and cache files. +#[test] +fn lsp_tls_cert() { + let _g = http_server(); + let mut params: lsp::InitializeParams = + serde_json::from_value(load_fixture("initialize_params_tls_cert.json")) + .unwrap(); + + params.root_uri = Some(Url::from_file_path(testdata_path()).unwrap()); + + let deno_exe = deno_exe_path(); + let mut client = LspClient::new(&deno_exe).unwrap(); + client + .write_request::<_, _, Value>("initialize", params) + .unwrap(); + + client.write_notification("initialized", json!({})).unwrap(); + did_open( + &mut client, + json!({ + "textDocument": { + "uri": "file:///a/file_01.ts", + "languageId": "typescript", + "version": 1, + "text": "export const a = \"a\";\n", + } + }), + ); + let diagnostics = + did_open(&mut client, load_fixture("did_open_params_tls_cert.json")); + let diagnostics = diagnostics.into_iter().flat_map(|x| x.diagnostics); + assert_eq!(diagnostics.count(), 14); + let (maybe_res, maybe_err) = client + .write_request::<_, _, Value>( + "deno/cache", + json!({ + "referrer": { + "uri": "file:///a/file.ts", + }, + "uris": [], + }), + ) + .unwrap(); + assert!(maybe_err.is_none()); + assert!(maybe_res.is_some()); + let (maybe_res, maybe_err) = client + .write_request( + "textDocument/hover", + json!({ + "textDocument": { + "uri": "file:///a/file.ts", + }, + "position": { + "line": 0, + "character": 28 + } + }), + ) + .unwrap(); + assert!(maybe_err.is_none()); + assert_eq!( + maybe_res, + Some(json!({ + "contents": { + "kind": "markdown", + "value": "**Resolved Dependency**\n\n**Code**: https​://localhost:5545/xTypeScriptTypes.js\n" + }, + "range": { + "start": { + "line": 0, + "character": 19 + }, + "end":{ + "line": 0, + "character": 63 + } + } + })) + ); + let (maybe_res, maybe_err) = client + .write_request::<_, _, Value>( + "textDocument/hover", + json!({ + "textDocument": { + "uri": "file:///a/file.ts", + }, + "position": { + "line": 7, + "character": 28 + } + }), + ) + .unwrap(); + assert!(maybe_err.is_none()); + assert_eq!( + maybe_res, + Some(json!({ + "contents": { + "kind": "markdown", + "value": "**Resolved Dependency**\n\n**Code**: http​://localhost:4545/x/a/mod.ts\n\n\n---\n\n**a**\n\nmod.ts" + }, + "range": { + "start": { + "line": 7, + "character": 19 + }, + "end": { + "line": 7, + "character": 53 + } + } + })) + ); + shutdown(&mut client); +} + #[test] fn lsp_diagnostics_warn() { let _g = http_server(); diff --git a/cli/tests/testdata/lsp/did_open_params_tls_cert.json b/cli/tests/testdata/lsp/did_open_params_tls_cert.json new file mode 100644 index 000000000..2942bfcbe --- /dev/null +++ b/cli/tests/testdata/lsp/did_open_params_tls_cert.json @@ -0,0 +1,8 @@ +{ + "textDocument": { + "uri": "file:///a/file.ts", + "languageId": "typescript", + "version": 1, + "text": "import * as a from \"https://localhost:5545/xTypeScriptTypes.js\";\n// @deno-types=\"https://localhost:5545/type_definitions/foo.d.ts\"\nimport * as b from \"https://localhost:5545/type_definitions/foo.js\";\nimport * as c from \"https://localhost:5545/subdir/type_reference.js\";\nimport * as d from \"https://localhost:5545/subdir/mod1.ts\";\nimport * as e from \"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=\";\nimport * as f from \"./file_01.ts\";\nimport * as g from \"http://localhost:4545/x/a/mod.ts\";\n\nconsole.log(a, b, c, d, e, f, g);\n" + } +} diff --git a/cli/tests/testdata/lsp/initialize_params.json b/cli/tests/testdata/lsp/initialize_params.json index 3b99be4f0..9fd197fe4 100644 --- a/cli/tests/testdata/lsp/initialize_params.json +++ b/cli/tests/testdata/lsp/initialize_params.json @@ -8,6 +8,7 @@ "initializationOptions": { "enable": true, "cache": null, + "certificateStores": null, "codeLens": { "implementations": true, "references": true, @@ -25,6 +26,8 @@ "hosts": {} } }, + "tlsCertificate": null, + "unsafelyIgnoreCertificateErrors": null, "unstable": false }, "capabilities": { diff --git a/cli/tests/testdata/lsp/initialize_params_tls_cert.json b/cli/tests/testdata/lsp/initialize_params_tls_cert.json new file mode 100644 index 000000000..e231bf25f --- /dev/null +++ b/cli/tests/testdata/lsp/initialize_params_tls_cert.json @@ -0,0 +1,71 @@ +{ + "processId": 0, + "clientInfo": { + "name": "test-harness", + "version": "1.0.0" + }, + "rootUri": null, + "initializationOptions": { + "enable": true, + "cache": null, + "certificateStores": null, + "codeLens": { + "implementations": true, + "references": true, + "test": true + }, + "config": "", + "importMap": null, + "lint": true, + "suggest": { + "autoImports": true, + "completeFunctionCalls": false, + "names": true, + "paths": true, + "imports": { + "hosts": { + "https://localhost:5545": true, + "http://localhost:4545": true + } + } + }, + "tlsCertificate": "tls/RootCA.pem", + "unsafelyIgnoreCertificateErrors": null, + "unstable": false + }, + "capabilities": { + "textDocument": { + "codeAction": { + "codeActionLiteralSupport": { + "codeActionKind": { + "valueSet": [ + "quickfix", + "refactor" + ] + } + }, + "isPreferredSupport": true, + "dataSupport": true, + "disabledSupport": true, + "resolveSupport": { + "properties": [ + "edit" + ] + } + }, + "foldingRange": { + "lineFoldingOnly": true + }, + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + } + }, + "workspace": { + "configuration": true, + "workspaceFolders": true + } + } +} |