Skip to content

Commit

Permalink
Update to use consistent wait throughout
Browse files Browse the repository at this point in the history
  • Loading branch information
chipsenkbeil committed Apr 22, 2024
1 parent 68e3d53 commit 68233c9
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 30 deletions.
4 changes: 2 additions & 2 deletions spec/events_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe("org-roam.events", function()
vim.cmd.edit(test_path_one)

-- Wait a moment for async events to process
vim.wait(1)
utils.wait()

assert.are.same({ "1", "2", "", "3", "1" }, nodes)
end)
Expand Down Expand Up @@ -116,7 +116,7 @@ describe("org-roam.events", function()
move_cursor_to_line(7)

-- Wait a moment for async events to process
vim.wait(1)
utils.wait()

assert.are.same({ "1234", "5678", "1234" }, nodes)
end)
Expand Down
4 changes: 2 additions & 2 deletions spec/setup_autocmds_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("org-roam.setup.autocmds", function()
vim.cmd.write()

-- Wait a bit to have the changes apply
vim.wait(100)
utils.wait()

-- Verify that the database reflects the change
ids = roam.db:ids()
Expand Down Expand Up @@ -72,7 +72,7 @@ describe("org-roam.setup.autocmds", function()
vim.cmd.write()

-- Wait a bit to have the changes apply
vim.wait(100)
utils.wait()

-- Verify that the database does not reflect change
ids = roam.db:ids()
Expand Down
16 changes: 8 additions & 8 deletions spec/setup_commands_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("org-roam.setup.commands", function()

-- Trigger the command and wait a bit
vim.cmd("RoamSave")
vim.wait(100)
utils.wait()

-- Verify the database file exists again
assert.are.equal(1, vim.fn.filereadable(roam.config.database.path))
Expand Down Expand Up @@ -60,7 +60,7 @@ describe("org-roam.setup.commands", function()

-- Trigger the command and wait a bit
vim.cmd("RoamUpdate")
vim.wait(100)
utils.wait()

-- Verify the existing file was updated
local ids = roam.db:ids()
Expand Down Expand Up @@ -93,7 +93,7 @@ describe("org-roam.setup.commands", function()

-- Trigger the command and wait a bit
vim.cmd("RoamUpdate!")
vim.wait(100)
utils.wait()

-- Verify the new file was loaded
local ids = roam.db:ids()
Expand Down Expand Up @@ -134,7 +134,7 @@ describe("org-roam.setup.commands", function()

-- Trigger the command and wait a bit
vim.cmd("RoamDatabaseReset")
vim.wait(100)
utils.wait()

-- Verify database has latest status
ids = roam.db:ids()
Expand Down Expand Up @@ -177,7 +177,7 @@ describe("org-roam.setup.commands", function()

-- Trigger the command and wait a bit
vim.cmd("RoamAddAlias some alias")
vim.wait(100)
utils.wait()

assert.are.same({
":PROPERTIES:",
Expand Down Expand Up @@ -222,7 +222,7 @@ describe("org-roam.setup.commands", function()

-- Trigger the command and wait a bit
vim.cmd("RoamRemoveAlias one")
vim.wait(100)
utils.wait()

assert.are.same({
":PROPERTIES:",
Expand Down Expand Up @@ -266,7 +266,7 @@ describe("org-roam.setup.commands", function()

-- Trigger the command and wait a bit
vim.cmd("RoamAddOrigin node origin")
vim.wait(100)
utils.wait()

assert.are.same({
":PROPERTIES:",
Expand Down Expand Up @@ -313,7 +313,7 @@ describe("org-roam.setup.commands", function()

-- Trigger the command and wait a bit
vim.cmd("RoamRemoveOrigin")
vim.wait(100)
utils.wait()

assert.are.same({
":PROPERTIES:",
Expand Down
4 changes: 2 additions & 2 deletions spec/setup_keybindings_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ describe("org-roam.setup.keybindings", function()
-- NOTE: We do this before any tests as any failure before capture
-- buffer is closed can cause issues.
vim.cmd("wq")
vim.wait(100)
utils.wait()

-- Verify we have switched to the appropriate buffer, stubbing out
-- the randomly-generated id
Expand Down Expand Up @@ -598,7 +598,7 @@ describe("org-roam.setup.keybindings", function()
-- NOTE: We do this before any tests as any failure before capture
-- buffer is closed can cause issues.
vim.cmd("wq")
vim.wait(100)
utils.wait()

-- Verify we have switched to the appropriate buffer, stubbing out
-- the randomly-generated id
Expand Down
4 changes: 2 additions & 2 deletions spec/ui_node_buffer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("org-roam.ui.node-buffer", function()

-- Switch back to our node window and change it to move cursor
vim.api.nvim_set_current_win(two_win)
vim.wait(100)
utils.wait()

assert.are.same({
"Press <Enter> to open a link in another window",
Expand Down Expand Up @@ -282,7 +282,7 @@ describe("org-roam.ui.node-buffer", function()

-- Switch back to our node window and change it to move cursor
vim.api.nvim_set_current_win(two_win)
vim.wait(100)
utils.wait()

-- Verify it is unchanged despite cursor moving
assert.are.same({
Expand Down
6 changes: 3 additions & 3 deletions spec/ui_quickfix_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("org-roam.ui.quickfix", function()

-- Trigger a quickfix error navigation
vim.cmd([[cc]])
vim.wait(100)
utils.wait()

-- Verify position and contents
local pos = vim.api.nvim_win_get_cursor(0)
Expand Down Expand Up @@ -91,7 +91,7 @@ describe("org-roam.ui.quickfix", function()

-- Trigger a quickfix error navigation
vim.cmd([[cc]])
vim.wait(100)
utils.wait()

-- Verify position and contents
local pos = vim.api.nvim_win_get_cursor(0)
Expand Down Expand Up @@ -148,7 +148,7 @@ describe("org-roam.ui.quickfix", function()

-- Trigger a quickfix error navigation
vim.cmd([[cc]])
vim.wait(100)
utils.wait()

assert.are.same({
":PROPERTIES:",
Expand Down
20 changes: 10 additions & 10 deletions spec/ui_select_node_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("org-roam.ui.select-node", function()
vim.api.nvim_buf_set_lines(buf, 0, 1, true, { text })
vim.api.nvim_exec_autocmds("TextChangedI", { buffer = buf })

local wait = opts.wait or 100
local wait = opts.wait or utils.wait_time()
if wait > 0 then
vim.wait(wait)
end
Expand Down Expand Up @@ -78,7 +78,7 @@ describe("org-roam.ui.select-node", function()

-- Load up the selection interface for all nodes
roam.ui.select_node(function() end)
vim.wait(100)
utils.wait()

-- Grab lines from current buffer
local lines = read_trimmed_sorted_buf_lines()
Expand All @@ -99,7 +99,7 @@ describe("org-roam.ui.select-node", function()

-- Load up the selection interface for nodes 2 and 3
roam.ui.select_node({ include = { "2", "3" } }, function() end)
vim.wait(100)
utils.wait()

-- Grab lines from current buffer
local lines = read_trimmed_sorted_buf_lines()
Expand All @@ -119,7 +119,7 @@ describe("org-roam.ui.select-node", function()

-- Load up the selection interface for all nodes except 1
roam.ui.select_node({ exclude = { "1" } }, function() end)
vim.wait(100)
utils.wait()

-- Grab lines from current buffer
local lines = read_trimmed_sorted_buf_lines()
Expand All @@ -139,7 +139,7 @@ describe("org-roam.ui.select-node", function()

-- Load up the selection interface for all nodes that contain "o"
roam.ui.select_node({ init_input = "o" }, function() end)
vim.wait(100)
utils.wait()

-- Grab lines from current buffer
local lines = read_trimmed_sorted_buf_lines()
Expand All @@ -165,7 +165,7 @@ describe("org-roam.ui.select-node", function()
id = node.id
selected = true
end)
vim.wait(100)
utils.wait()

-- Verify we're on the original window
assert.are.equal(win, vim.api.nvim_get_current_win())
Expand All @@ -186,7 +186,7 @@ describe("org-roam.ui.select-node", function()
roam.ui.select_node({ auto_select = true, init_input = "o" }, function()
selected = true
end)
vim.wait(100)
utils.wait()

-- Grab lines from current buffer
local lines = read_trimmed_sorted_buf_lines()
Expand Down Expand Up @@ -215,7 +215,7 @@ describe("org-roam.ui.select-node", function()
end, function()
canceled = true
end)
vim.wait(100)
utils.wait()

-- Should be at original window with no modifications
assert.are.equal(win, vim.api.nvim_get_current_win())
Expand All @@ -237,7 +237,7 @@ describe("org-roam.ui.select-node", function()
label = node.label
selected = true
end)
vim.wait(100)
utils.wait()

-- Verify that we're at the selection dialog
assert.are_not.equal(win, vim.api.nvim_get_current_win())
Expand Down Expand Up @@ -277,7 +277,7 @@ describe("org-roam.ui.select-node", function()
label = node.label
selected = true
end)
vim.wait(100)
utils.wait()

-- Verify that we're at the selection dialog
assert.are_not.equal(win, vim.api.nvim_get_current_win())
Expand Down
28 changes: 27 additions & 1 deletion spec/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,33 @@ end
---This can be adjusted for CI usage.
---@param time? integer
function M.wait(time)
vim.wait(time or 300)
vim.wait(time or M.wait_time())
end

---@type integer|nil
local __wait_time

---Returns the standard wait time used across tests.
---@return integer
function M.wait_time()
-- Calculate our wait time the first time we are executed
if not __wait_time then
local stime = vim.env.ROAM_WAIT_TIME

-- If we were given `ROAM_WAIT_TIME`, try to parse it as milliseconds
if type(stime) == "string" then
stime = tonumber(stime)
end

-- If no explicit time set, but we are in a CI, use bigger number
if not stime and vim.env.CI == "true" then
stime = 500
end

__wait_time = type(stime) == "number" and stime or 100
end

return __wait_time
end

---Takes string, splits into lines, and removes common indentation.
Expand Down

0 comments on commit 68233c9

Please sign in to comment.