forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_nodejs.lua
More file actions
185 lines (152 loc) · 6.32 KB
/
test_nodejs.lua
File metadata and controls
185 lines (152 loc) · 6.32 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
local eq = MiniTest.expect.equality
local stub = require("tests.stubs.nodejs")
local T = MiniTest.new_set({
hooks = {
pre_once = function() end,
pre_case = function()
-- Reset the module state before each test
package.loaded["copilot.lsp.nodejs"] = nil
end,
},
})
T["get_node_version()"] = MiniTest.new_set()
T["get_node_version()"]["default node command"] = function()
local captured_args = stub.valid_node(function()
local nodejs = require("copilot.lsp.nodejs")
nodejs.setup()
local version, error = nodejs.get_node_version()
eq(version, stub.valid_node_version)
eq(error, nil)
end)
eq(captured_args, { "node", "--version" })
end
T["get_node_version()"]["custom node command as string"] = function()
local captured_args = stub.valid_node(function()
local nodejs = require("copilot.lsp.nodejs")
nodejs.setup("/usr/local/bin/node")
local version, error = nodejs.get_node_version()
eq(version, stub.valid_node_version)
eq(error, nil)
end)
eq(captured_args, { "/usr/local/bin/node", "--version" })
end
T["get_node_version()"]["custom node command as string with spaces"] = function()
local captured_args = stub.valid_node(function()
local nodejs = require("copilot.lsp.nodejs")
nodejs.setup("/path to/node")
local version, error = nodejs.get_node_version()
eq(version, stub.valid_node_version)
eq(error, nil)
end)
eq(captured_args, { "/path to/node", "--version" })
end
T["get_node_version()"]["custom node command as table"] = function()
local captured_args = stub.valid_node(function()
local nodejs = require("copilot.lsp.nodejs")
nodejs.setup({ "mise", "x", "node@lts", "--", "node" })
local version, error = nodejs.get_node_version()
eq(version, stub.valid_node_version)
eq(error, nil)
end)
eq(captured_args, { "mise", "x", "node@lts", "--", "node", "--version" })
end
T["get_node_version()"]["handles vim.system failure"] = function()
local captured_args = stub.process("", -1, true, function()
local nodejs = require("copilot.lsp.nodejs")
nodejs.setup("node")
local _, error = nodejs.get_node_version()
error = error or ""
eq(error:find("Could not determine Node.js version") ~= nil, true)
end)
eq(captured_args, { "node", "--version" })
end
T["get_node_version()"]["handles process with non-zero exit code"] = function()
local captured_args = stub.process("", 127, false, function()
local nodejs = require("copilot.lsp.nodejs")
nodejs.setup("nonexistent-node")
local _, error = nodejs.get_node_version()
error = error or ""
eq(error:find("Could not determine Node.js version") ~= nil, true)
end)
eq(captured_args, { "nonexistent-node", "--version" })
end
T["get_node_version()"]["validates node version requirement"] = function()
local captured_args = stub.invalid_node(function()
local nodejs = require("copilot.lsp.nodejs")
nodejs.setup("node")
local _, error = nodejs.get_node_version()
error = error or ""
eq(error:find("Node.js version 20 or newer required") ~= nil, true)
end)
eq(captured_args, { "node", "--version" })
end
T["get_execute_command()"] = MiniTest.new_set()
T["get_execute_command()"]["default node command, default server path"] = function()
local captured_path = stub.get_runtime_server_path(function()
local nodejs = require("copilot.lsp.nodejs")
eq(nodejs.setup(), true)
local cmd = nodejs.get_execute_command()
eq(cmd, { "node", stub.default_server_path, "--stdio" })
end)
eq(captured_path, stub.default_server_path)
end
T["get_execute_command()"]["default node command, custom server path"] = function()
stub.get_runtime_server_path(function()
local nodejs = require("copilot.lsp.nodejs")
eq(nodejs.setup(nil, stub.custom_server_path), true)
local cmd = nodejs.get_execute_command()
eq(cmd, { "node", stub.custom_server_path, "--stdio" })
end)
end
T["get_execute_command()"]["custom node command as string, default server path"] = function()
local captured_path = stub.get_runtime_server_path(function()
local nodejs = require("copilot.lsp.nodejs")
eq(nodejs.setup("/usr/local/bin/node"), true)
local cmd = nodejs.get_execute_command()
eq(cmd, { "/usr/local/bin/node", stub.default_server_path, "--stdio" })
end)
eq(captured_path, stub.default_server_path)
end
T["get_execute_command()"]["custom node command as string, custom server path"] = function()
stub.get_runtime_server_path(function()
local nodejs = require("copilot.lsp.nodejs")
nodejs.setup("/usr/local/bin/node", stub.custom_server_path)
local cmd = nodejs.get_execute_command()
eq(cmd, { "/usr/local/bin/node", stub.custom_server_path, "--stdio" })
end)
end
T["get_execute_command()"]["custom node command as string with spaces, default server path"] = function()
local captured_path = stub.get_runtime_server_path(function()
local nodejs = require("copilot.lsp.nodejs")
nodejs.setup("/path to/node")
local cmd = nodejs.get_execute_command()
eq(cmd, { "/path to/node", stub.default_server_path, "--stdio" })
end)
eq(captured_path, stub.default_server_path)
end
T["get_execute_command()"]["custom node command as string with spaces, custom server path"] = function()
stub.get_runtime_server_path(function()
local nodejs = require("copilot.lsp.nodejs")
nodejs.setup("/path to/node", stub.custom_server_path)
local cmd = nodejs.get_execute_command()
eq(cmd, { "/path to/node", stub.custom_server_path, "--stdio" })
end)
end
T["get_execute_command()"]["custom node command as table, default server path"] = function()
local captured_path = stub.get_runtime_server_path(function()
local nodejs = require("copilot.lsp.nodejs")
nodejs.setup({ "mise", "x", "node@lts", "--", "node" })
local cmd = nodejs.get_execute_command()
eq(cmd, { "mise", "x", "node@lts", "--", "node", stub.default_server_path, "--stdio" })
end)
eq(captured_path, stub.default_server_path)
end
T["get_execute_command()"]["custom node command as table, custom server path"] = function()
stub.get_runtime_server_path(function()
local nodejs = require("copilot.lsp.nodejs")
nodejs.setup({ "mise", "x", "node@lts", "--", "node" }, stub.custom_server_path)
local cmd = nodejs.get_execute_command()
eq(cmd, { "mise", "x", "node@lts", "--", "node", stub.custom_server_path, "--stdio" })
end)
end
return T