Skip to content

Commit 185a0d9

Browse files
author
Étienne Lévesque
committed
Add server test
1 parent 26fe78e commit 185a0d9

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule TestCodeLens.MixProject do
2+
use Mix.Project
3+
4+
def project do
5+
[app: :references, version: "0.1.0"]
6+
end
7+
8+
def application, do: []
9+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule TestCodeLensTest do
2+
use ExUnit.Case
3+
4+
test "fixture test" do
5+
assert true
6+
end
7+
end

apps/language_server/test/server_test.exs

+56
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,62 @@ defmodule ElixirLS.LanguageServer.ServerTest do
621621
end)
622622
end
623623

624+
test "returns code lenses for runnable tests", %{server: server} do
625+
in_fixture(__DIR__, "test_code_lens", fn ->
626+
file_path = "test/fixture_test.exs"
627+
file_uri = SourceFile.path_to_uri(file_path)
628+
file_absolute_path = SourceFile.path_from_uri(file_uri)
629+
text = File.read!(file_path)
630+
631+
initialize(server)
632+
Server.receive_packet(server, did_open(file_uri, "elixir", 1, text))
633+
634+
Server.receive_packet(
635+
server,
636+
code_lens_req(4, file_uri)
637+
)
638+
639+
# :timer.sleep(1000)
640+
# %{"result" => resp} = assert_received(%{"id" => 4})
641+
resp = assert_receive(%{"id" => 4}, 5000)
642+
643+
assert response(4, [
644+
%{
645+
"command" => %{
646+
"arguments" => [
647+
%{
648+
"filePath" => ^file_absolute_path,
649+
"testName" => "fixture test"
650+
}
651+
],
652+
"command" => "elixir.lens.test.run",
653+
"title" => "Run test"
654+
},
655+
"range" => %{
656+
"end" => %{"character" => 0, "line" => 3},
657+
"start" => %{"character" => 0, "line" => 3}
658+
}
659+
},
660+
%{
661+
"command" => %{
662+
"arguments" => [
663+
%{
664+
"filePath" => file_absolute_path,
665+
"module" => "Elixir.TestCodeLensTest"
666+
}
667+
],
668+
"command" => "elixir.lens.test.run",
669+
"title" => "Run tests in module"
670+
},
671+
"range" => %{
672+
"end" => %{"character" => 0, "line" => 0},
673+
"start" => %{"character" => 0, "line" => 0}
674+
}
675+
}
676+
]) = resp
677+
end)
678+
end
679+
624680
defp with_new_server(func) do
625681
server = start_supervised!({Server, nil})
626682
packet_capture = start_supervised!({PacketCapture, self()})

0 commit comments

Comments
 (0)