summaryrefslogtreecommitdiff
path: root/cli/tests/lsp_tests.rs
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-12-07 21:46:39 +1100
committerGitHub <noreply@github.com>2020-12-07 21:46:39 +1100
commit301d3e4b6849d24154ac2d65c00a9b30223d000e (patch)
treeab3bc074493e6c9be8d1875233bc141bdc0da3b4 /cli/tests/lsp_tests.rs
parentc8e9b2654ec0d54c77bb3f49fa31c3986203d517 (diff)
feat: add mvp language server (#8515)
Resolves #8400
Diffstat (limited to 'cli/tests/lsp_tests.rs')
-rw-r--r--cli/tests/lsp_tests.rs88
1 files changed, 88 insertions, 0 deletions
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"));
+}