1- local child = MiniTest .new_child_neovim ()
1+ local child_helper = require (" tests.child_helper" )
2+ local child = child_helper .new_child_neovim (" test_auth" )
23local u = require (" tests.utils" )
3- local env = require (" tests.env" )
44
55local config_path = require (" copilot.auth" ).find_config_path ()
66local config_path_renamed = config_path .. " _temp_renamed"
77
88local T = MiniTest .new_set ({
99 hooks = {
1010 pre_once = function ()
11- if vim .fn .filereadable (" ./tests/logs/test_auth.log" ) == 1 then
12- vim .fn .delete (" ./tests/logs/test_auth.log" )
13- end
14-
1511 if vim .fn .isdirectory (config_path ) == 1 then
1612 vim .fn .rename (config_path , config_path_renamed )
1713 end
1814 end ,
1915 pre_case = function ()
20- child .restart ({ " -u " , " tests/scripts/minimal_init.lua " } )
16+ child .run_pre_case ( )
2117 child .lua (" M = require('copilot')" )
2218 child .lua (" c = require('copilot.client')" )
2319 child .lua (" s = require('copilot.status')" )
2420 child .lua (" cmd = require('copilot.command')" )
2521 child .lua (" a = require('copilot.api')" )
2622 child .lua (" logger = require('copilot.logger')" )
23+ child .fn .setenv (" GITHUB_COPILOT_TOKEN" , vim .NIL )
2724 end ,
2825 post_once = function ()
2926 child .stop ()
@@ -37,43 +34,23 @@ local T = MiniTest.new_set({
3734
3835T [" auth()" ] = MiniTest .new_set ()
3936
40- -- TODO: This test currently assumes you are not auth'd, so the token env var cannot be used
37+ -- TODO: callback for this too
4138T [" auth()" ][" auth before attaching, should not give error" ] = function ()
42- child .lua ([[ M.setup({
43- logger = {
44- file_log_level = vim.log.levels.TRACE,
45- file = "./tests/logs/test_auth.log",
46- trace_lsp = "verbose",
47- log_lsp_messages = true,
48- trace_lsp_progress = true,
49- },
50- })]] )
51-
52- vim .loop .sleep (500 )
39+ child .configure_copilot ()
5340 child .cmd (" Copilot auth" )
54- vim .loop .sleep (500 )
41+ vim .loop .sleep (3000 )
5542 local messages = child .cmd_capture (" messages" )
56- u .expect_match (messages , " .*Online.*Enabled .*" )
43+ u .expect_match (messages , " .*Authenticated as GitHub user .*" )
5744end
5845
5946T [" auth()" ][" auth issue replication" ] = function ()
60- child .fn .setenv (" GITHUB_COPILOT_TOKEN" , env .COPILOT_TOKEN )
61- child .lua ([[ M.setup({
62- logger = {
63- file_log_level = vim.log.levels.TRACE,
64- file = "./tests/logs/test_auth.log",
65- trace_lsp = "verbose",
66- log_lsp_messages = true,
67- trace_lsp_progress = true,
68- },
69- })]] )
70-
71- vim .loop .sleep (500 )
47+ child .configure_copilot ()
7248 child .cmd (" Copilot auth" )
73- vim .loop .sleep (500 )
49+ vim .loop .sleep (2000 )
7450 child .cmd (" Copilot status" )
51+ vim .loop .sleep (500 )
7552 local messages = child .cmd_capture (" messages" )
76- u .expect_match (messages , " .*Online.*Authenticated .*" )
53+ u .expect_match (messages , " .*Online.*Enabled .*" )
7754end
7855
7956return T
0 commit comments