-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_server_integration.lua
More file actions
82 lines (74 loc) · 2.44 KB
/
Copy pathtest_server_integration.lua
File metadata and controls
82 lines (74 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
local MiniTest = require("mini.test")
local eq = MiniTest.expect.equality
local child = MiniTest.new_child_neovim()
local function setup_test_environment()
_G.log = {}
_G.notifications = {}
Logger = require("eca.logger")
Logger.log = function(message, level)
table.insert(_G.log, { message = message, level = level })
end
Logger.notify = function(message, level, opts)
table.insert(_G.notifications, { message = message, level = level, opts = opts })
end
_G.server = require("eca.server").new()
end
local T = MiniTest.new_set({
hooks = {
pre_case = function()
child.restart({ "-u", "scripts/minimal_init.lua" })
child.lua_func(setup_test_environment)
end,
post_case = function()
child.lua("if _G.server and _G.server.process then _G.server.process:kill() end")
end,
post_once = child.stop,
},
})
-- See https://github.com/echasnovski/mini.nvim/issues/1863#issuecomment-2983629024
-- for why the sleep is necessary when testing something with a callback
local function sleep(ms)
vim.uv.sleep(ms)
-- Execute 'nvim_eval' (a deferred function) to
-- force at least one main_loop iteration
child.api.nvim_eval("1")
end
T["server"] = MiniTest.new_set()
T["server"]["start"] = function()
child.lua("_G.server:start({ clean = true })")
child.lua([[
_G.server_started = vim.wait(10000, function()
return _G.server and _G.server:is_running()
end, 100)
]])
eq(child.lua_get("_G.server_started"), true)
sleep(1000)
eq(child.lua_get("_G.server.initialized"), true)
end
T["server"]["start without initialize"] = function()
child.lua("_G.server:start({ clean = true, initialize = false })")
child.lua([[
_G.server_started = vim.wait(10000, function()
return _G.server and _G.server:is_running()
end, 100)
]])
eq(child.lua_get("_G.server_started"), true)
sleep(1000)
eq(child.lua_get("_G.server.initialized"), false)
end
T["server"]["start with inexistent path"] = function()
child.lua([[
Config = require("eca.config")
Config.setup({ server_path = "non-existing-path" } )
_G.server:start({ clean = true })
]])
child.lua([[
_G.server_started = vim.wait(1000, function()
return _G.server and _G.server:is_running()
end, 100)
]])
eq(string.find(child.lua_get("_G.notifications[1].message"), "non-existing-path", 1 , true) ~= nil, true)
eq(child.lua_get("_G.server_started"), false)
eq(child.lua_get("_G.server.initialized"), false)
end
return T