diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/integration_tests.rs | 2 | ||||
-rw-r--r-- | cli/tests/lsp/did_open_notification.json | 12 | ||||
-rw-r--r-- | cli/tests/lsp/exit_notification.json | 5 | ||||
-rw-r--r-- | cli/tests/lsp/hover_request.json | 14 | ||||
-rw-r--r-- | cli/tests/lsp/initialize_request.json | 23 | ||||
-rw-r--r-- | cli/tests/lsp/initialized_notification.json | 5 | ||||
-rw-r--r-- | cli/tests/lsp/shutdown_request.json | 6 | ||||
-rw-r--r-- | cli/tests/lsp_tests.rs | 88 | ||||
-rw-r--r-- | cli/tests/type_directives_01.ts.out | 2 | ||||
-rw-r--r-- | cli/tests/type_directives_02.ts.out | 2 |
10 files changed, 156 insertions, 3 deletions
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index aca2df99c..42172a771 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -914,7 +914,7 @@ fn ts_reload() { assert!(std::str::from_utf8(&output.stdout) .unwrap() .trim() - .contains("\"host.writeFile(\\\"deno://002_hello.js\\\")\"")); + .contains("host.writeFile(\"deno://002_hello.js\")")); } #[test] diff --git a/cli/tests/lsp/did_open_notification.json b/cli/tests/lsp/did_open_notification.json new file mode 100644 index 000000000..04f12a7b3 --- /dev/null +++ b/cli/tests/lsp/did_open_notification.json @@ -0,0 +1,12 @@ +{ + "jsonrpc": "2.0", + "method": "textDocument/didOpen", + "params": { + "textDocument": { + "uri": "file:///a/file.ts", + "languageId": "typescript", + "version": 1, + "text": "console.log(Deno.args);\n" + } + } +} diff --git a/cli/tests/lsp/exit_notification.json b/cli/tests/lsp/exit_notification.json new file mode 100644 index 000000000..799a0d1d5 --- /dev/null +++ b/cli/tests/lsp/exit_notification.json @@ -0,0 +1,5 @@ +{ + "jsonrpc": "2.0", + "method": "exit", + "params": null +} diff --git a/cli/tests/lsp/hover_request.json b/cli/tests/lsp/hover_request.json new file mode 100644 index 000000000..f12bd52df --- /dev/null +++ b/cli/tests/lsp/hover_request.json @@ -0,0 +1,14 @@ +{ + "jsonrpc": "2.0", + "id": 2, + "method": "textDocument/hover", + "params": { + "textDocument": { + "uri": "file:///a/file.ts" + }, + "position": { + "line": 0, + "character": 19 + } + } +} diff --git a/cli/tests/lsp/initialize_request.json b/cli/tests/lsp/initialize_request.json new file mode 100644 index 000000000..960420bfd --- /dev/null +++ b/cli/tests/lsp/initialize_request.json @@ -0,0 +1,23 @@ +{ + "jsonrpc": "2.0", + "id": 1, + "method": "initialize", + "params": { + "processId": 0, + "clientInfo": { + "name": "test-harness", + "version": "1.0.0" + }, + "rootUri": null, + "capabilities": { + "textDocument": { + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + } + } + } + } +} diff --git a/cli/tests/lsp/initialized_notification.json b/cli/tests/lsp/initialized_notification.json new file mode 100644 index 000000000..972f8abc8 --- /dev/null +++ b/cli/tests/lsp/initialized_notification.json @@ -0,0 +1,5 @@ +{ + "jsonrpc": "2.0", + "method": "initialized", + "params": {} +} diff --git a/cli/tests/lsp/shutdown_request.json b/cli/tests/lsp/shutdown_request.json new file mode 100644 index 000000000..fd4d78460 --- /dev/null +++ b/cli/tests/lsp/shutdown_request.json @@ -0,0 +1,6 @@ +{ + "jsonrpc": "2.0", + "id": 3, + "method": "shutdown", + "params": null +} diff --git a/cli/tests/lsp_tests.rs b/cli/tests/lsp_tests.rs new file mode 100644 index 000000000..7de655ac8 --- /dev/null +++ b/cli/tests/lsp_tests.rs @@ -0,0 +1,88 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +///! +///! Integration test for the Deno Language Server (`deno lsp`) +///! +use std::fs; +use std::io::Read; +use std::io::Write; +use std::process::Stdio; + +struct LspIntegrationTest { + pub fixtures: Vec<&'static str>, +} + +impl LspIntegrationTest { + pub fn run(&self) -> (String, String) { + let root_path = test_util::root_path(); + let deno_exe = test_util::deno_exe_path(); + let tests_dir = root_path.join("cli/tests/lsp"); + println!("tests_dir: {:?} deno_exe: {:?}", tests_dir, deno_exe); + let mut command = test_util::deno_cmd(); + command + .arg("lsp") + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()); + + let process = command.spawn().expect("failed to execute deno"); + + for fixture in &self.fixtures { + let mut stdin = process.stdin.as_ref().unwrap(); + let fixture_path = tests_dir.join(fixture); + let content = + fs::read_to_string(&fixture_path).expect("could not read fixture"); + let content_length = content.chars().count(); + write!( + stdin, + "Content-Length: {}\r\n\r\n{}", + content_length, content + ) + .unwrap(); + } + + let mut so = String::new(); + process.stdout.unwrap().read_to_string(&mut so).unwrap(); + + let mut se = String::new(); + process.stderr.unwrap().read_to_string(&mut se).unwrap(); + + (so, se) + } +} + +#[test] +fn test_lsp_startup_shutdown() { + let test = LspIntegrationTest { + fixtures: vec![ + "initialize_request.json", + "initialized_notification.json", + "shutdown_request.json", + "exit_notification.json", + ], + }; + let (response, out) = test.run(); + assert!(response.contains("deno-language-server")); + assert!(out.contains("Connected to \"test-harness\" 1.0.0")); +} + +#[test] +fn test_lsp_hover() { + // a straight forward integration tests starts up the lsp, opens a document + // which logs `Deno.args` to the console, and hovers over the `args` property + // to get the intellisense about it, which is a total end-to-end test that + // includes sending information in and out of the TypeScript compiler. + let test = LspIntegrationTest { + fixtures: vec![ + "initialize_request.json", + "initialized_notification.json", + "did_open_notification.json", + "hover_request.json", + "shutdown_request.json", + "exit_notification.json", + ], + }; + let (response, out) = test.run(); + assert!(response.contains("const Deno.args: string[]")); + assert!(out.contains("Connected to \"test-harness\" 1.0.0")); +} diff --git a/cli/tests/type_directives_01.ts.out b/cli/tests/type_directives_01.ts.out index 8d285d3a8..77ed3ae26 100644 --- a/cli/tests/type_directives_01.ts.out +++ b/cli/tests/type_directives_01.ts.out @@ -1,3 +1,3 @@ [WILDCARD] -DEBUG TS - "host.getSourceFile(\"http://127.0.0.1:4545/xTypeScriptTypes.d.ts\", Latest)" +DEBUG TS - host.getSourceFile("http://127.0.0.1:4545/xTypeScriptTypes.d.ts", Latest) [WILDCARD]
\ No newline at end of file diff --git a/cli/tests/type_directives_02.ts.out b/cli/tests/type_directives_02.ts.out index aea1d4fd0..7949dfab5 100644 --- a/cli/tests/type_directives_02.ts.out +++ b/cli/tests/type_directives_02.ts.out @@ -1,3 +1,3 @@ [WILDCARD] -DEBUG TS - "host.getSourceFile(\"file:///[WILDCARD]cli/tests/subdir/type_reference.d.ts\", Latest)" +DEBUG TS - host.getSourceFile("file:///[WILDCARD]cli/tests/subdir/type_reference.d.ts", Latest) [WILDCARD]
\ No newline at end of file |