Skip to content

Commit 6e41ba7

Browse files
committed
ci: enable running on main instance
fix flakey tests
1 parent ef5a28b commit 6e41ba7

5 files changed

Lines changed: 34 additions & 3 deletions

File tree

tests/actions_spec.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ T["actions"]["vimcmd"] = new_set({
102102
},
103103
}, {
104104
function(action)
105+
-- store mini.test float so we can return to it when
106+
-- testing in main instance
107+
local win = vim.api.nvim_get_current_win()
105108
local ctx = function()
106109
return {
107110
buf = child.api.nvim_get_current_buf(),
@@ -149,6 +152,12 @@ T["actions"]["vimcmd"] = new_set({
149152
__expect_lines = true,
150153
__after_open = function()
151154
child.wait_until(function() return child.lua_get([[_G._fzf_load_called]]) == true end)
155+
-- Wait for previewer to load the LICENSE file entry and title to render
156+
child.wait_until(function()
157+
local entry = child.lua_get([[FzfLua.utils.fzf_winobj()._previewer.last_entry]])
158+
return entry and entry:match("LICENSE") ~= nil
159+
end)
160+
vim.uv.sleep(100) -- Allow async title update to render
152161
if helpers.IS_WIN() then vim.uv.sleep(250) end
153162
end,
154163
no_esc = true,
@@ -160,6 +169,9 @@ T["actions"]["vimcmd"] = new_set({
160169
eq({ "LICENSE", 3 }, { _ctx.name, child.fn.line(".") })
161170
end
162171
eq("live_grep", exec_lua([[return _G._fzf_info.cmd]]))
172+
-- close tab and return to mini.test float
173+
vim.api.nvim_buf_delete(0, { force = true })
174+
vim.api.nvim_set_current_win(win)
163175
end
164176
})
165177

tests/api_spec.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ T["api"]["fzf_live"]["table"] = function(multiprocess)
108108
{
109109
__expect_lines = true,
110110
__postprocess_wait = true,
111+
__after_open = function()
112+
child.wait_until(function() return child.lua_get([[_G._fzf_load_called]]) == true end)
113+
end,
111114
query = 100,
112115
keymap = { fzf = { load = "pos(-1)" } },
113116
multiprocess = multiprocess == true,

tests/path_spec.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ describe("Testing path module", function()
429429
stripped = "/tmp/test.txt:42",
430430
terminal = false
431431
})
432+
vim.api.nvim_buf_delete(buf, { force = true })
432433
end)
433434

434435
it("man://", function()
@@ -448,6 +449,7 @@ describe("Testing path module", function()
448449
stripped = "man://ls(1):42:7:",
449450
terminal = false
450451
})
452+
vim.api.nvim_buf_delete(buf, { force = true })
451453
end)
452454

453455
it("force_uri", function()
@@ -467,8 +469,9 @@ describe("Testing path module", function()
467469

468470
it("parse loaded path", function()
469471
helpers.SKIP_IF_WIN()
472+
local win = vim.api.nvim_get_current_win()
470473
local r = {}
471-
vim.cmd [[bwipe]]
474+
vim.cmd.new()
472475
local name = "/tmp/foo:bar.txt"
473476
vim.cmd.edit(name)
474477
vim.cmd([[sil write]])
@@ -480,6 +483,8 @@ describe("Testing path module", function()
480483
bufnr = vim.fn.bufnr(),
481484
bufname = name,
482485
})
486+
vim.api.nvim_buf_delete(0, { force = true })
487+
vim.api.nvim_set_current_win(win)
483488
end)
484489
end)
485490
end)

tests/utils_spec.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,22 @@ describe("Testing utils module", function()
9393
end)
9494

9595
it("wo", function()
96+
-- store mini.test float so we can return to it when
97+
-- testing in main instance
98+
local win = vim.api.nvim_get_current_win()
99+
vim.cmd.new()
96100
utils.wo.nonexist = "this is nop"
97101
eq(nil, utils.wo.nonexist)
98102

99103
vim.wo[0][0].nu = true -- setlocal
100104
vim.wo[0].rnu = true -- setglobal
101105
eq(vim.wo[0][0].nu, vim.wo.nu)
102106
eq(vim.wo[0][0].rnu, vim.wo.rnu)
107+
vim.api.nvim_buf_delete(0, { force = true })
103108
vim.cmd.new()
104109
eq(vim.wo[0][0].nu, vim.wo.nu)
105110
eq(vim.wo[0][0].rnu, vim.wo.rnu)
111+
vim.api.nvim_buf_delete(0, { force = true })
106112

107113
-- same behavior
108114
utils.wo[0][0].nu = true -- setlocal
@@ -112,6 +118,8 @@ describe("Testing utils module", function()
112118
vim.cmd.new()
113119
eq(utils.wo[0][0].nu, utils.wo.nu)
114120
eq(utils.wo[0][0].rnu, utils.wo.rnu)
121+
vim.api.nvim_buf_delete(0, { force = true })
122+
vim.api.nvim_set_current_win(win)
115123
end)
116124

117125
it("strsplit", function()

tests/win_spec.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ T["win"]["hide"]["can resume after close CTX win (#1936)"] = function()
111111
-- can :wqa when there're hide job #1817
112112
pcall(child.cmd, [[wqa]])
113113
-- child.is_running() didn't work as expected
114-
eq(vim.fn.jobwait({ assert(child.job).id }, 1000)[1], 0)
114+
local res = vim.fn.jobwait({ assert(child.job).id }, 1000)[1]
115+
-- 0 = normal exit, -3 = already exited/invalid (acceptable race)
116+
local valid_res = { [0] = true, [-3] = true }
117+
eq(valid_res[res] or res, true) -- HACK: show the res code in the assert
115118
end
116119

117120
T["win"]["hide"]["actions on multi-select but zero-match #1961"] = function()
@@ -323,7 +326,7 @@ T["win"]["relative=cursor"] = function()
323326
previewer = function() return require("fzf-lua.test.previewer").builtin end,
324327
__after_open = function()
325328
child.wait_until(function() return child.lua_get([[_G._fzf_load_called]]) == true end)
326-
if helpers.IS_WIN() then vim.uv.sleep(250) end
329+
if not helpers.IS_LINUX() then vim.uv.sleep(250) end
327330
end,
328331
}
329332
helpers.FzfLua.fzf_exec(child, { "foo", "bar", "baz" }, opts)

0 commit comments

Comments
 (0)