|
1 | 1 | defmodule Expert.ExpertTest do |
2 | | - use ExUnit.Case, async: true |
| 2 | + alias Forge.Test.Fixtures |
| 3 | + |
| 4 | + use ExUnit.Case, async: false |
| 5 | + use Forge.Test.EventualAssertions |
3 | 6 | use Patch |
4 | 7 |
|
5 | 8 | require GenLSP.Test |
6 | 9 |
|
7 | 10 | import Expert.Test.Protocol.TransportSupport |
8 | 11 |
|
| 12 | + describe "server testing" do |
| 13 | + defp buffer_opts do |
| 14 | + [communication: {GenLSP.Communication.TCP, [port: 0]}] |
| 15 | + end |
| 16 | + |
| 17 | + defp start_application_children do |
| 18 | + pids = |
| 19 | + for child_spec <- Expert.Application.children(buffer: buffer_opts()) do |
| 20 | + start_supervised!(child_spec) |
| 21 | + end |
| 22 | + |
| 23 | + on_exit(fn -> |
| 24 | + # NOTE: The test hangs for some reason without manually exiting |
| 25 | + for pid <- pids do |
| 26 | + Process.exit(pid, :normal) |
| 27 | + end |
| 28 | + end) |
| 29 | + end |
| 30 | + |
| 31 | + setup do |
| 32 | + start_application_children() |
| 33 | + |
| 34 | + comm_state = GenLSP.Buffer.comm_state(Expert.Buffer) |
| 35 | + |
| 36 | + {:ok, port} = :inet.port(comm_state.lsocket) |
| 37 | + %{lsp: lsp} = :sys.get_state(Expert.Buffer) |
| 38 | + |
| 39 | + expert = %{lsp: lsp, port: port} |
| 40 | + client = GenLSP.Test.client(expert) |
| 41 | + |
| 42 | + [expert: expert, client: client] |
| 43 | + end |
| 44 | + |
| 45 | + test "replies to initialize with expert info and capabilities", %{client: client} do |
| 46 | + id = System.unique_integer([:positive]) |
| 47 | + |
| 48 | + project = Fixtures.project() |
| 49 | + |
| 50 | + root_uri = project.root_uri |
| 51 | + root_path = Forge.Project.root_path(project) |
| 52 | + |
| 53 | + assert :ok == |
| 54 | + GenLSP.Test.request(client, %{ |
| 55 | + "id" => id, |
| 56 | + "jsonrpc" => "2.0", |
| 57 | + "method" => "initialize", |
| 58 | + "params" => %{ |
| 59 | + "rootPath" => root_path, |
| 60 | + "rootUri" => root_uri, |
| 61 | + "capabilities" => %{}, |
| 62 | + "workspaceFolders" => [ |
| 63 | + %{ |
| 64 | + uri: root_uri, |
| 65 | + name: root_path |
| 66 | + } |
| 67 | + ] |
| 68 | + } |
| 69 | + }) |
| 70 | + |
| 71 | + GenLSP.Test.assert_result(^id, result, 500) |
| 72 | + |
| 73 | + {:ok, initialize_result} = |
| 74 | + GenLSP.Requests.Initialize.result() |
| 75 | + |> Schematic.dump(Expert.State.initialize_result()) |
| 76 | + |
| 77 | + assert result == initialize_result |
| 78 | + end |
| 79 | + end |
| 80 | + |
9 | 81 | test "sends an error message on engine initialization error" do |
10 | 82 | with_patched_transport() |
11 | 83 |
|
|
0 commit comments