Skip to content

Commit

Permalink
Add server test
Browse files Browse the repository at this point in the history
  • Loading branch information
Étienne Lévesque committed Nov 25, 2020
1 parent 26fe78e commit 185a0d9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apps/language_server/test/fixtures/test_code_lens/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule TestCodeLens.MixProject do
use Mix.Project

def project do
[app: :references, version: "0.1.0"]
end

def application, do: []
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule TestCodeLensTest do
use ExUnit.Case

test "fixture test" do
assert true
end
end
56 changes: 56 additions & 0 deletions apps/language_server/test/server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,62 @@ defmodule ElixirLS.LanguageServer.ServerTest do
end)
end

test "returns code lenses for runnable tests", %{server: server} do
in_fixture(__DIR__, "test_code_lens", fn ->
file_path = "test/fixture_test.exs"
file_uri = SourceFile.path_to_uri(file_path)
file_absolute_path = SourceFile.path_from_uri(file_uri)
text = File.read!(file_path)

initialize(server)
Server.receive_packet(server, did_open(file_uri, "elixir", 1, text))

Server.receive_packet(
server,
code_lens_req(4, file_uri)
)

# :timer.sleep(1000)
# %{"result" => resp} = assert_received(%{"id" => 4})
resp = assert_receive(%{"id" => 4}, 5000)

assert response(4, [
%{
"command" => %{
"arguments" => [
%{
"filePath" => ^file_absolute_path,
"testName" => "fixture test"
}
],
"command" => "elixir.lens.test.run",
"title" => "Run test"
},
"range" => %{
"end" => %{"character" => 0, "line" => 3},
"start" => %{"character" => 0, "line" => 3}
}
},
%{
"command" => %{
"arguments" => [
%{
"filePath" => file_absolute_path,
"module" => "Elixir.TestCodeLensTest"
}
],
"command" => "elixir.lens.test.run",
"title" => "Run tests in module"
},
"range" => %{
"end" => %{"character" => 0, "line" => 0},
"start" => %{"character" => 0, "line" => 0}
}
}
]) = resp
end)
end

defp with_new_server(func) do
server = start_supervised!({Server, nil})
packet_capture = start_supervised!({PacketCapture, self()})
Expand Down

0 comments on commit 185a0d9

Please sign in to comment.