add rerun function from within the listing-float
All checks were successful
tests / test (push) Successful in 8s
All checks were successful
tests / test (push) Successful in 8s
This commit is contained in:
@@ -40,6 +40,7 @@ local close_detail_float
|
||||
local jump_to_first_quickfix
|
||||
local apply_summary_highlights
|
||||
local apply_result_highlights
|
||||
local run_command
|
||||
|
||||
local function disable_container_maps(buf)
|
||||
local opts = { buffer = buf, nowait = true, silent = true }
|
||||
@@ -66,6 +67,7 @@ local function help_lines()
|
||||
" <leader>sf Filter listing to [ FAIL ] only",
|
||||
" <leader>ss Filter listing to [ SKIP ] only",
|
||||
" <leader>sa Show all listing entries (clear filter)",
|
||||
" <leader>tt Run the test under the cursor",
|
||||
"",
|
||||
"Testing-Float (Listing):",
|
||||
" <cr> Open Detail-Float for selected test",
|
||||
@@ -779,6 +781,9 @@ local function create_output_win(initial_lines)
|
||||
vim.keymap.set("n", "<leader>sa", function()
|
||||
M.filter_listing_all()
|
||||
end, { buffer = buf, nowait = true, silent = true })
|
||||
vim.keymap.set("n", "<leader>tt", function()
|
||||
M.run_test_at_cursor()
|
||||
end, { buffer = buf, nowait = true, silent = true })
|
||||
vim.keymap.set("n", "?", function()
|
||||
M.show_help()
|
||||
end, { buffer = buf, nowait = true, silent = true })
|
||||
@@ -855,6 +860,9 @@ local function reopen_output_win()
|
||||
vim.keymap.set("n", "<leader>sa", function()
|
||||
M.filter_listing_all()
|
||||
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||
vim.keymap.set("n", "<leader>tt", function()
|
||||
M.run_test_at_cursor()
|
||||
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||
vim.keymap.set("n", "?", function()
|
||||
M.show_help()
|
||||
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||
@@ -1324,6 +1332,70 @@ function M.filter_listing_all()
|
||||
apply_listing_filter("all")
|
||||
end
|
||||
|
||||
function M.run_test_at_cursor()
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
local line = cursor[1]
|
||||
local text = vim.api.nvim_get_current_line()
|
||||
local status = text:match("^%[%s*(%u+)%s*%]%s*%-")
|
||||
if status ~= "PASS" and status ~= "FAIL" and status ~= "SKIP" then
|
||||
return
|
||||
end
|
||||
local test_name = state.last_result_line_map[line]
|
||||
if not test_name then
|
||||
test_name = text:match("^%[%s*[%u]+%s*%]%s*%-%s*(.+)$")
|
||||
end
|
||||
if not test_name or test_name == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local runner = state.last_scope_runner or state.last_runner
|
||||
if not runner or type(runner.build_command) ~= "function" then
|
||||
vim.notify("[test-samurai] Runner missing methods", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
local command_src = state.last_scope_command or state.last_command
|
||||
if not command_src then
|
||||
vim.notify("[test-samurai] No previous test command", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local spec = {
|
||||
file = command_src.file,
|
||||
cwd = command_src.cwd,
|
||||
test_name = test_name,
|
||||
full_name = test_name,
|
||||
}
|
||||
if runner._last_mocha_titles and type(runner._last_mocha_titles) == "table" then
|
||||
spec.mocha_full_title = runner._last_mocha_titles[test_name]
|
||||
end
|
||||
if not spec.mocha_full_title and test_name:find("/", 1, true) then
|
||||
spec.mocha_full_title = test_name:gsub("/", " ")
|
||||
end
|
||||
if not spec.file or spec.file == "" then
|
||||
vim.notify("[test-samurai] Missing test file for rerun", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local ok_cmd, command = pcall(runner.build_command, spec)
|
||||
if not ok_cmd or not command or type(command.cmd) ~= "table" or #command.cmd == 0 then
|
||||
vim.notify("[test-samurai] Runner failed to build command", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
command.file = spec.file
|
||||
|
||||
local parser = runner.output_parser
|
||||
if type(parser) == "function" then
|
||||
parser = parser()
|
||||
end
|
||||
run_command(command, {
|
||||
track_scope = true,
|
||||
runner = runner,
|
||||
scope_kind = "nearest",
|
||||
output_parser = parser or runner.parse_results,
|
||||
})
|
||||
end
|
||||
|
||||
function M.focus_listing()
|
||||
if state.last_win and vim.api.nvim_win_is_valid(state.last_win) then
|
||||
if state.detail_win and vim.api.nvim_win_is_valid(state.detail_win) then
|
||||
@@ -1776,7 +1848,7 @@ local function collect_failure_names_from_listing()
|
||||
return out
|
||||
end
|
||||
|
||||
local function run_command(command, opts)
|
||||
run_command = function(command, opts)
|
||||
local options = opts or {}
|
||||
state.last_test_outputs = {}
|
||||
state.last_result_line_map = {}
|
||||
|
||||
Reference in New Issue
Block a user