diff --git a/spec/events_spec.lua b/spec/events_spec.lua index 04a94d5..a146691 100644 --- a/spec/events_spec.lua +++ b/spec/events_spec.lua @@ -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) @@ -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) diff --git a/spec/setup_autocmds_spec.lua b/spec/setup_autocmds_spec.lua index 8e3010f..93a26a2 100644 --- a/spec/setup_autocmds_spec.lua +++ b/spec/setup_autocmds_spec.lua @@ -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() @@ -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() diff --git a/spec/setup_commands_spec.lua b/spec/setup_commands_spec.lua index f84f2f6..fe33f19 100644 --- a/spec/setup_commands_spec.lua +++ b/spec/setup_commands_spec.lua @@ -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)) @@ -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() @@ -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() @@ -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() @@ -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:", @@ -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:", @@ -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:", @@ -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:", diff --git a/spec/setup_keybindings_spec.lua b/spec/setup_keybindings_spec.lua index 1e8efc2..c7ac07a 100644 --- a/spec/setup_keybindings_spec.lua +++ b/spec/setup_keybindings_spec.lua @@ -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 @@ -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 diff --git a/spec/ui_node_buffer_spec.lua b/spec/ui_node_buffer_spec.lua index 8f3cc78..87a6c0c 100644 --- a/spec/ui_node_buffer_spec.lua +++ b/spec/ui_node_buffer_spec.lua @@ -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 to open a link in another window", @@ -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({ diff --git a/spec/ui_quickfix_spec.lua b/spec/ui_quickfix_spec.lua index 7d477fb..4b07b7d 100644 --- a/spec/ui_quickfix_spec.lua +++ b/spec/ui_quickfix_spec.lua @@ -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) @@ -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) @@ -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:", diff --git a/spec/ui_select_node_spec.lua b/spec/ui_select_node_spec.lua index 4b52bc2..5da0a7d 100644 --- a/spec/ui_select_node_spec.lua +++ b/spec/ui_select_node_spec.lua @@ -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 @@ -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() @@ -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() @@ -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() @@ -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() @@ -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()) @@ -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() @@ -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()) @@ -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()) @@ -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()) diff --git a/spec/utils.lua b/spec/utils.lua index fdb4f3c..d83cb10 100644 --- a/spec/utils.lua +++ b/spec/utils.lua @@ -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.