@@ -7,6 +7,7 @@ local T = MiniTest.new_set({
7
7
pre_case = function ()
8
8
-- Reset the module state before each test
9
9
package.loaded [" copilot.lsp.nodejs" ] = nil
10
+ M .nodejs = require (" copilot.lsp.nodejs" )
10
11
end ,
11
12
},
12
13
})
@@ -15,10 +16,8 @@ T["get_node_version()"] = MiniTest.new_set()
15
16
16
17
T [" get_node_version()" ][" default node command" ] = function ()
17
18
local captured_args = stub .valid_node (function ()
18
- local nodejs = require (" copilot.lsp.nodejs" )
19
- nodejs .setup ()
20
-
21
- local version , error = nodejs .get_node_version ()
19
+ M .nodejs .setup ()
20
+ local version , error = M .nodejs .get_node_version ()
22
21
23
22
eq (version , stub .valid_node_version )
24
23
eq (error , nil )
28
27
29
28
T [" get_node_version()" ][" custom node command as string" ] = function ()
30
29
local captured_args = stub .valid_node (function ()
31
- local nodejs = require (" copilot.lsp.nodejs" )
32
- nodejs .setup (" /usr/local/bin/node" )
30
+ M .nodejs .setup (" /usr/local/bin/node" )
33
31
34
- local version , error = nodejs .get_node_version ()
32
+ local version , error = M . nodejs .get_node_version ()
35
33
36
34
eq (version , stub .valid_node_version )
37
35
eq (error , nil )
41
39
42
40
T [" get_node_version()" ][" custom node command as string with spaces" ] = function ()
43
41
local captured_args = stub .valid_node (function ()
44
- local nodejs = require (" copilot.lsp.nodejs" )
45
- nodejs .setup (" /path to/node" )
42
+ M .nodejs .setup (" /path to/node" )
46
43
47
- local version , error = nodejs .get_node_version ()
44
+ local version , error = M . nodejs .get_node_version ()
48
45
49
46
eq (version , stub .valid_node_version )
50
47
eq (error , nil )
54
51
55
52
T [" get_node_version()" ][" custom node command as table" ] = function ()
56
53
local captured_args = stub .valid_node (function ()
57
- local nodejs = require (" copilot.lsp.nodejs" )
58
- nodejs .setup ({ " mise" , " x" , " node@lts" , " --" , " node" })
54
+ M .nodejs .setup ({ " mise" , " x" , " node@lts" , " --" , " node" })
59
55
60
- local version , error = nodejs .get_node_version ()
56
+ local version , error = M . nodejs .get_node_version ()
61
57
62
58
eq (version , stub .valid_node_version )
63
59
eq (error , nil )
67
63
68
64
T [" get_node_version()" ][" handles vim.system failure" ] = function ()
69
65
local captured_args = stub .process (" " , - 1 , true , function ()
70
- local nodejs = require (" copilot.lsp.nodejs" )
71
- nodejs .setup (" node" )
66
+ M .nodejs .setup (" node" )
72
67
73
- local _ , error = nodejs .get_node_version ()
68
+ local _ , error = M . nodejs .get_node_version ()
74
69
error = error or " "
75
70
76
71
eq (error :find (" Could not determine Node.js version" ) ~= nil , true )
80
75
81
76
T [" get_node_version()" ][" handles process with non-zero exit code" ] = function ()
82
77
local captured_args = stub .process (" " , 127 , false , function ()
83
- local nodejs = require (" copilot.lsp.nodejs" )
84
- nodejs .setup (" nonexistent-node" )
78
+ M .nodejs .setup (" nonexistent-node" )
85
79
86
- local _ , error = nodejs .get_node_version ()
80
+ local _ , error = M . nodejs .get_node_version ()
87
81
error = error or " "
88
82
89
83
eq (error :find (" Could not determine Node.js version" ) ~= nil , true )
93
87
94
88
T [" get_node_version()" ][" validates node version requirement" ] = function ()
95
89
local captured_args = stub .invalid_node (function ()
96
- local nodejs = require (" copilot.lsp.nodejs" )
97
- nodejs .setup (" node" )
90
+ M .nodejs .setup (" node" )
98
91
99
- local _ , error = nodejs .get_node_version ()
92
+ local _ , error = M . nodejs .get_node_version ()
100
93
error = error or " "
101
94
102
95
eq (error :find (" Node.js version 20 or newer required" ) ~= nil , true )
@@ -108,76 +101,68 @@ T["get_execute_command()"] = MiniTest.new_set()
108
101
109
102
T [" get_execute_command()" ][" default node command, default server path" ] = function ()
110
103
local captured_path = stub .get_runtime_server_path (function ()
111
- local nodejs = require (" copilot.lsp.nodejs" )
112
- eq (nodejs .setup (), true )
113
- local cmd = nodejs .get_execute_command ()
104
+ eq (M .nodejs .setup (), true )
105
+ local cmd = M .nodejs .get_execute_command ()
114
106
eq (cmd , { " node" , vim .fn .expand (stub .default_server_path ), " --stdio" })
115
107
end )
116
108
eq (captured_path , stub .default_server_path )
117
109
end
118
110
119
111
T [" get_execute_command()" ][" default node command, custom server path" ] = function ()
120
112
stub .get_runtime_server_path (function ()
121
- local nodejs = require (" copilot.lsp.nodejs" )
122
- eq (nodejs .setup (nil , vim .fn .expand (stub .custom_server_path )), true )
123
- local cmd = nodejs .get_execute_command ()
113
+ eq (M .nodejs .setup (nil , vim .fn .expand (stub .custom_server_path )), true )
114
+ local cmd = M .nodejs .get_execute_command ()
124
115
eq (cmd , { " node" , vim .fn .expand (stub .custom_server_path ), " --stdio" })
125
116
end )
126
117
end
127
118
128
119
T [" get_execute_command()" ][" custom node command as string, default server path" ] = function ()
129
120
local captured_path = stub .get_runtime_server_path (function ()
130
- local nodejs = require (" copilot.lsp.nodejs" )
131
- eq (nodejs .setup (" /usr/local/bin/node" ), true )
132
- local cmd = nodejs .get_execute_command ()
121
+ eq (M .nodejs .setup (" /usr/local/bin/node" ), true )
122
+ local cmd = M .nodejs .get_execute_command ()
133
123
eq (cmd , { " /usr/local/bin/node" , vim .fn .expand (stub .default_server_path ), " --stdio" })
134
124
end )
135
125
eq (captured_path , stub .default_server_path )
136
126
end
137
127
138
128
T [" get_execute_command()" ][" custom node command as string, custom server path" ] = function ()
139
129
stub .get_runtime_server_path (function ()
140
- local nodejs = require (" copilot.lsp.nodejs" )
141
- nodejs .setup (" /usr/local/bin/node" , stub .custom_server_path )
142
- local cmd = nodejs .get_execute_command ()
130
+ M .nodejs .setup (" /usr/local/bin/node" , stub .custom_server_path )
131
+ local cmd = M .nodejs .get_execute_command ()
143
132
eq (cmd , { " /usr/local/bin/node" , stub .custom_server_path , " --stdio" })
144
133
end )
145
134
end
146
135
147
136
T [" get_execute_command()" ][" custom node command as string with spaces, default server path" ] = function ()
148
137
local captured_path = stub .get_runtime_server_path (function ()
149
- local nodejs = require (" copilot.lsp.nodejs" )
150
- nodejs .setup (" /path to/node" )
151
- local cmd = nodejs .get_execute_command ()
138
+ M .nodejs .setup (" /path to/node" )
139
+ local cmd = M .nodejs .get_execute_command ()
152
140
eq (cmd , { " /path to/node" , vim .fn .expand (stub .default_server_path ), " --stdio" })
153
141
end )
154
142
eq (captured_path , stub .default_server_path )
155
143
end
156
144
157
145
T [" get_execute_command()" ][" custom node command as string with spaces, custom server path" ] = function ()
158
146
stub .get_runtime_server_path (function ()
159
- local nodejs = require (" copilot.lsp.nodejs" )
160
- nodejs .setup (" /path to/node" , stub .custom_server_path )
161
- local cmd = nodejs .get_execute_command ()
147
+ M .nodejs .setup (" /path to/node" , stub .custom_server_path )
148
+ local cmd = M .nodejs .get_execute_command ()
162
149
eq (cmd , { " /path to/node" , stub .custom_server_path , " --stdio" })
163
150
end )
164
151
end
165
152
166
153
T [" get_execute_command()" ][" custom node command as table, default server path" ] = function ()
167
154
local captured_path = stub .get_runtime_server_path (function ()
168
- local nodejs = require (" copilot.lsp.nodejs" )
169
- nodejs .setup ({ " mise" , " x" , " node@lts" , " --" , " node" })
170
- local cmd = nodejs .get_execute_command ()
155
+ M .nodejs .setup ({ " mise" , " x" , " node@lts" , " --" , " node" })
156
+ local cmd = M .nodejs .get_execute_command ()
171
157
eq (cmd , { " mise" , " x" , " node@lts" , " --" , " node" , vim .fn .expand (stub .default_server_path ), " --stdio" })
172
158
end )
173
159
eq (captured_path , stub .default_server_path )
174
160
end
175
161
176
162
T [" get_execute_command()" ][" custom node command as table, custom server path" ] = function ()
177
163
stub .get_runtime_server_path (function ()
178
- local nodejs = require (" copilot.lsp.nodejs" )
179
- nodejs .setup ({ " mise" , " x" , " node@lts" , " --" , " node" }, stub .custom_server_path )
180
- local cmd = nodejs .get_execute_command ()
164
+ M .nodejs .setup ({ " mise" , " x" , " node@lts" , " --" , " node" }, stub .custom_server_path )
165
+ local cmd = M .nodejs .get_execute_command ()
181
166
eq (cmd , { " mise" , " x" , " node@lts" , " --" , " node" , stub .custom_server_path , " --stdio" })
182
167
end )
183
168
end
0 commit comments