stick to the old and simple test-output layout for listing and detail view and disable hardtime-plugin on any testing-float
This commit is contained in:
@@ -1,6 +1,62 @@
|
||||
local test_samurai = require("test-samurai")
|
||||
local core = require("test-samurai.core")
|
||||
|
||||
local function close_output_container()
|
||||
local keys = vim.api.nvim_replace_termcodes("<esc><esc>", true, false, true)
|
||||
local attempts = 5
|
||||
while attempts > 0 do
|
||||
local float_win = nil
|
||||
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
local cfg = vim.api.nvim_win_get_config(win)
|
||||
if cfg.relative ~= "" then
|
||||
float_win = win
|
||||
break
|
||||
end
|
||||
end
|
||||
if not float_win then
|
||||
break
|
||||
end
|
||||
vim.api.nvim_set_current_win(float_win)
|
||||
vim.api.nvim_feedkeys(keys, "x", false)
|
||||
vim.wait(20, function()
|
||||
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
local cfg = vim.api.nvim_win_get_config(win)
|
||||
if cfg.relative ~= "" then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end)
|
||||
attempts = attempts - 1
|
||||
end
|
||||
end
|
||||
|
||||
local function has_nop_mapping(buf, lhs)
|
||||
local check = { lhs }
|
||||
if lhs == "<C-h>" then
|
||||
table.insert(check, "<BS>")
|
||||
end
|
||||
if lhs == "<C-j>" then
|
||||
table.insert(check, "<NL>")
|
||||
end
|
||||
for _, map in ipairs(vim.api.nvim_buf_get_keymap(buf, "n")) do
|
||||
local matched = false
|
||||
for _, key in ipairs(check) do
|
||||
if (map.lhs or ""):lower() == key:lower() then
|
||||
matched = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if matched then
|
||||
local rhs = map.rhs or ""
|
||||
if rhs == "<Nop>" or rhs == "<nop>" or rhs == "" then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
describe("test-samurai public API", function()
|
||||
it("delegates show_output to core", function()
|
||||
local called = false
|
||||
@@ -98,6 +154,25 @@ describe("test-samurai output formatting", function()
|
||||
test_samurai.setup()
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
close_output_container()
|
||||
end)
|
||||
|
||||
local function find_listing_win()
|
||||
local current = vim.api.nvim_get_current_win()
|
||||
local cfg = vim.api.nvim_win_get_config(current)
|
||||
if cfg.relative ~= "" then
|
||||
return current
|
||||
end
|
||||
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
local win_cfg = vim.api.nvim_win_get_config(win)
|
||||
if win_cfg.relative ~= "" then
|
||||
return win
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
it("formats JSON output as PASS/FAIL lines", function()
|
||||
local json = vim.json.encode({
|
||||
testResults = {
|
||||
@@ -265,8 +340,9 @@ describe("test-samurai output formatting", function()
|
||||
|
||||
core.run_nearest()
|
||||
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
local hl = vim.api.nvim_win_get_option(win, "winhighlight")
|
||||
local listing = find_listing_win()
|
||||
assert.is_not_nil(listing)
|
||||
local hl = vim.api.nvim_win_get_option(listing, "winhighlight")
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
|
||||
@@ -311,8 +387,9 @@ describe("test-samurai output formatting", function()
|
||||
|
||||
core.run_nearest()
|
||||
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
local hl = vim.api.nvim_win_get_option(win, "winhighlight")
|
||||
local listing = find_listing_win()
|
||||
assert.is_not_nil(listing)
|
||||
local hl = vim.api.nvim_win_get_option(listing, "winhighlight")
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
|
||||
@@ -1406,6 +1483,10 @@ describe("test-samurai output detail view", function()
|
||||
test_samurai.setup()
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
close_output_container()
|
||||
end)
|
||||
|
||||
local function find_float_wins()
|
||||
local wins = vim.api.nvim_tabpage_list_wins(0)
|
||||
local out = {}
|
||||
@@ -1418,10 +1499,9 @@ describe("test-samurai output detail view", function()
|
||||
return out
|
||||
end
|
||||
|
||||
local function find_non_float_win()
|
||||
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
local cfg = vim.api.nvim_win_get_config(win)
|
||||
if cfg.relative == "" then
|
||||
local function find_detail_win(listing)
|
||||
for _, win in ipairs(find_float_wins()) do
|
||||
if win ~= listing then
|
||||
return win
|
||||
end
|
||||
end
|
||||
@@ -1467,21 +1547,17 @@ describe("test-samurai output detail view", function()
|
||||
core.open_test_output_at_cursor()
|
||||
local wins = find_float_wins()
|
||||
assert.equals(2, #wins)
|
||||
local right = nil
|
||||
for _, win in ipairs(wins) do
|
||||
if win ~= output_win then
|
||||
right = win
|
||||
break
|
||||
end
|
||||
end
|
||||
local right = find_detail_win(output_win)
|
||||
assert.is_not_nil(right)
|
||||
local left_cfg = vim.api.nvim_win_get_config(output_win)
|
||||
local right_cfg = vim.api.nvim_win_get_config(right)
|
||||
assert.is_true(left_cfg.border == "rounded" or type(left_cfg.border) == "table")
|
||||
assert.is_true(right_cfg.border == "rounded" or type(right_cfg.border) == "table")
|
||||
assert.equals(left_cfg.row, right_cfg.row)
|
||||
assert.equals(left_cfg.height, right_cfg.height)
|
||||
assert.equals(left_cfg.col + left_cfg.width, right_cfg.col)
|
||||
assert.is_true(right_cfg.col >= left_cfg.col + left_cfg.width + 2)
|
||||
local total_width = left_cfg.width + right_cfg.width
|
||||
local expected_left = math.floor(total_width * 0.2)
|
||||
local expected_left = math.floor(total_width * 0.25)
|
||||
assert.is_true(math.abs(left_cfg.width - expected_left) <= 1)
|
||||
local right_buf = vim.api.nvim_win_get_buf(right)
|
||||
local detail = vim.api.nvim_buf_get_lines(right_buf, 0, -1, false)
|
||||
@@ -1532,13 +1608,7 @@ describe("test-samurai output detail view", function()
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
local wins = find_float_wins()
|
||||
local right = nil
|
||||
for _, win in ipairs(wins) do
|
||||
if win ~= output_win then
|
||||
right = win
|
||||
break
|
||||
end
|
||||
end
|
||||
local right = find_detail_win(output_win)
|
||||
assert.is_not_nil(right)
|
||||
local right_buf = vim.api.nvim_win_get_buf(right)
|
||||
vim.api.nvim_buf_set_lines(right_buf, 0, -1, false, { "old output" })
|
||||
@@ -1547,13 +1617,7 @@ describe("test-samurai output detail view", function()
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
local updated = find_float_wins()
|
||||
local updated_right = nil
|
||||
for _, win in ipairs(updated) do
|
||||
if win ~= output_win then
|
||||
updated_right = win
|
||||
break
|
||||
end
|
||||
end
|
||||
local updated_right = find_detail_win(output_win)
|
||||
assert.equals(right, updated_right)
|
||||
local detail = vim.api.nvim_buf_get_lines(right_buf, 0, -1, false)
|
||||
assert.are.same({
|
||||
@@ -1601,13 +1665,7 @@ describe("test-samurai output detail view", function()
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
local wins = find_float_wins()
|
||||
local right = nil
|
||||
for _, win in ipairs(wins) do
|
||||
if win ~= output_win then
|
||||
right = win
|
||||
break
|
||||
end
|
||||
end
|
||||
local right = find_detail_win(output_win)
|
||||
assert.is_not_nil(right)
|
||||
local right_buf = vim.api.nvim_win_get_buf(right)
|
||||
local detail = vim.api.nvim_buf_get_lines(right_buf, 0, -1, false)
|
||||
@@ -1622,6 +1680,156 @@ describe("test-samurai output detail view", function()
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("opens detail output for PASS entries", function()
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, {
|
||||
vim.json.encode({ Action = "output", Test = "TestFoo/Sub", Output = "PASS detail\n" }),
|
||||
vim.json.encode({ Action = "pass", Test = "TestFoo/Sub" }),
|
||||
}, nil)
|
||||
end
|
||||
if opts and opts.on_exit then
|
||||
opts.on_exit(1, 0, nil)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/output_detail_pass_test.go")
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
|
||||
test_samurai.test_file()
|
||||
|
||||
local out_buf = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(out_buf, 0, -1, false)
|
||||
local target = nil
|
||||
for i, line in ipairs(lines) do
|
||||
if line:match("^%[ PASS %] %- ") then
|
||||
target = i
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_not_nil(target)
|
||||
vim.api.nvim_win_set_cursor(0, { target, 0 })
|
||||
|
||||
local output_win = vim.api.nvim_get_current_win()
|
||||
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
local wins = find_float_wins()
|
||||
assert.equals(2, #wins)
|
||||
local right = find_detail_win(output_win)
|
||||
assert.is_not_nil(right)
|
||||
local right_buf = vim.api.nvim_win_get_buf(right)
|
||||
local detail = vim.api.nvim_buf_get_lines(right_buf, 0, -1, false)
|
||||
assert.are.same({ "PASS detail" }, detail)
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("colors detail border based on selected result", function()
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, {
|
||||
vim.json.encode({ Action = "output", Test = "TestFoo/Pass", Output = "PASS detail\n" }),
|
||||
vim.json.encode({ Action = "pass", Test = "TestFoo/Pass" }),
|
||||
vim.json.encode({ Action = "output", Test = "TestFoo/Fail", Output = "FAIL detail\n" }),
|
||||
vim.json.encode({ Action = "fail", Test = "TestFoo/Fail" }),
|
||||
}, nil)
|
||||
end
|
||||
if opts and opts.on_exit then
|
||||
opts.on_exit(1, 1, nil)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/output_detail_border_test.go")
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
|
||||
test_samurai.test_file()
|
||||
|
||||
local out_buf = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(out_buf, 0, -1, false)
|
||||
local pass_line = nil
|
||||
local fail_line = nil
|
||||
for i, line in ipairs(lines) do
|
||||
if line:match("^%[ PASS %] %- ") then
|
||||
pass_line = i
|
||||
elseif line:match("^%[ FAIL %] %- ") then
|
||||
fail_line = i
|
||||
end
|
||||
end
|
||||
assert.is_not_nil(pass_line)
|
||||
assert.is_not_nil(fail_line)
|
||||
|
||||
local output_win = vim.api.nvim_get_current_win()
|
||||
vim.api.nvim_win_set_cursor(0, { pass_line, 0 })
|
||||
core.open_test_output_at_cursor()
|
||||
local detail_win = find_detail_win(output_win)
|
||||
assert.is_not_nil(detail_win)
|
||||
local pass_hl = vim.api.nvim_win_get_option(detail_win, "winhighlight")
|
||||
assert.equals("FloatBorder:TestSamuraiBorderPass", pass_hl)
|
||||
|
||||
vim.api.nvim_set_current_win(output_win)
|
||||
vim.api.nvim_win_set_cursor(0, { fail_line, 0 })
|
||||
core.open_test_output_at_cursor()
|
||||
local fail_hl = vim.api.nvim_win_get_option(detail_win, "winhighlight")
|
||||
assert.equals("FloatBorder:TestSamuraiBorderFail", fail_hl)
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("does not open detail output for SKIP entries", function()
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, {
|
||||
vim.json.encode({ Action = "output", Test = "TestFoo/Sub", Output = "skip detail\n" }),
|
||||
vim.json.encode({ Action = "skip", Test = "TestFoo/Sub" }),
|
||||
}, nil)
|
||||
end
|
||||
if opts and opts.on_exit then
|
||||
opts.on_exit(1, 0, nil)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/output_detail_skip_test.go")
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
|
||||
test_samurai.test_file()
|
||||
|
||||
local out_buf = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(out_buf, 0, -1, false)
|
||||
local target = nil
|
||||
for i, line in ipairs(lines) do
|
||||
if line:match("^%[ SKIP %] %- ") then
|
||||
target = i
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_not_nil(target)
|
||||
vim.api.nvim_win_set_cursor(0, { target, 0 })
|
||||
|
||||
local output_win = vim.api.nvim_get_current_win()
|
||||
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
local wins = find_float_wins()
|
||||
assert.equals(1, #wins)
|
||||
local right = find_detail_win(output_win)
|
||||
assert.is_nil(right)
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("closes detail float and restores listing width", function()
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
@@ -1660,13 +1868,7 @@ describe("test-samurai output detail view", function()
|
||||
|
||||
local wins = find_float_wins()
|
||||
assert.equals(2, #wins)
|
||||
local right = nil
|
||||
for _, win in ipairs(wins) do
|
||||
if win ~= output_win then
|
||||
right = win
|
||||
break
|
||||
end
|
||||
end
|
||||
local right = find_detail_win(output_win)
|
||||
assert.is_not_nil(right)
|
||||
local left_cfg = vim.api.nvim_win_get_config(output_win)
|
||||
local right_cfg = vim.api.nvim_win_get_config(right)
|
||||
@@ -1676,13 +1878,400 @@ describe("test-samurai output detail view", function()
|
||||
|
||||
local remaining = find_float_wins()
|
||||
assert.equals(1, #remaining)
|
||||
local cfg = vim.api.nvim_win_get_config(remaining[1])
|
||||
assert.equals(total_width, cfg.width)
|
||||
local listing_cfg = vim.api.nvim_win_get_config(output_win)
|
||||
assert.is_true(listing_cfg.border == "rounded" or type(listing_cfg.border) == "table")
|
||||
assert.equals(total_width + 2, listing_cfg.width)
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("closes container when listing float is closed", function()
|
||||
it("closes detail float with <C-c> and restores listing width", function()
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, {
|
||||
vim.json.encode({ Action = "output", Test = "TestFoo/Sub", Output = "=== RUN TestFoo/Sub\n" }),
|
||||
vim.json.encode({ Action = "fail", Test = "TestFoo/Sub" }),
|
||||
}, nil)
|
||||
end
|
||||
if opts and opts.on_exit then
|
||||
opts.on_exit(1, 1, nil)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/output_detail_close_key_test.go")
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
|
||||
test_samurai.test_file()
|
||||
local out_buf = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(out_buf, 0, -1, false)
|
||||
local target = nil
|
||||
for i, line in ipairs(lines) do
|
||||
if line:match("^%[ FAIL %] %- ") then
|
||||
target = i
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_not_nil(target)
|
||||
vim.api.nvim_win_set_cursor(0, { target, 0 })
|
||||
|
||||
local output_win = vim.api.nvim_get_current_win()
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
local wins = find_float_wins()
|
||||
local detail_win = find_detail_win(output_win)
|
||||
assert.is_not_nil(detail_win)
|
||||
local left_cfg = vim.api.nvim_win_get_config(output_win)
|
||||
local right_cfg = vim.api.nvim_win_get_config(detail_win)
|
||||
local total_width = left_cfg.width + right_cfg.width
|
||||
|
||||
vim.api.nvim_set_current_win(detail_win)
|
||||
local keys = vim.api.nvim_replace_termcodes("<C-c>", true, false, true)
|
||||
vim.api.nvim_feedkeys(keys, "x", false)
|
||||
vim.wait(20, function()
|
||||
return #find_float_wins() == 1
|
||||
end)
|
||||
|
||||
local remaining = find_float_wins()
|
||||
assert.equals(1, #remaining)
|
||||
local listing_cfg = vim.api.nvim_win_get_config(output_win)
|
||||
assert.equals(total_width + 2, listing_cfg.width)
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("disables ctrl-j/ctrl-k mappings in listing and detail buffers", function()
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, {
|
||||
vim.json.encode({ Action = "output", Test = "TestFoo/Sub", Output = "=== RUN TestFoo/Sub\n" }),
|
||||
vim.json.encode({ Action = "fail", Test = "TestFoo/Sub" }),
|
||||
}, nil)
|
||||
end
|
||||
if opts and opts.on_exit then
|
||||
opts.on_exit(1, 1, nil)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/output_detail_ctrl_map_test.go")
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
|
||||
test_samurai.test_file()
|
||||
local listing_buf = vim.api.nvim_get_current_buf()
|
||||
assert.is_true(has_nop_mapping(listing_buf, "<C-j>"))
|
||||
assert.is_true(has_nop_mapping(listing_buf, "<C-k>"))
|
||||
|
||||
local lines = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
||||
local target = nil
|
||||
for i, line in ipairs(lines) do
|
||||
if line:match("^%[ FAIL %] %- ") then
|
||||
target = i
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_not_nil(target)
|
||||
vim.api.nvim_win_set_cursor(0, { target, 0 })
|
||||
|
||||
local output_win = vim.api.nvim_get_current_win()
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
local detail_win = find_detail_win(output_win)
|
||||
assert.is_not_nil(detail_win)
|
||||
local detail_buf = vim.api.nvim_win_get_buf(detail_win)
|
||||
assert.is_true(has_nop_mapping(detail_buf, "<C-j>"))
|
||||
assert.is_true(has_nop_mapping(detail_buf, "<C-k>"))
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("focuses listing with <C-h> from detail", function()
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, {
|
||||
vim.json.encode({ Action = "output", Test = "TestFoo/Sub", Output = "=== RUN TestFoo/Sub\n" }),
|
||||
vim.json.encode({ Action = "fail", Test = "TestFoo/Sub" }),
|
||||
}, nil)
|
||||
end
|
||||
if opts and opts.on_exit then
|
||||
opts.on_exit(1, 1, nil)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/output_detail_focus_h_test.go")
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
|
||||
test_samurai.test_file()
|
||||
local out_buf = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(out_buf, 0, -1, false)
|
||||
local target = nil
|
||||
for i, line in ipairs(lines) do
|
||||
if line:match("^%[ FAIL %] %- ") then
|
||||
target = i
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_not_nil(target)
|
||||
vim.api.nvim_win_set_cursor(0, { target, 0 })
|
||||
|
||||
local output_win = vim.api.nvim_get_current_win()
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
local detail_win = find_detail_win(output_win)
|
||||
assert.is_not_nil(detail_win)
|
||||
vim.api.nvim_set_current_win(detail_win)
|
||||
|
||||
local keys = vim.api.nvim_replace_termcodes("<C-h>", true, false, true)
|
||||
vim.api.nvim_feedkeys(keys, "x", false)
|
||||
vim.wait(20, function()
|
||||
return vim.api.nvim_get_current_win() == output_win
|
||||
end)
|
||||
|
||||
assert.equals(output_win, vim.api.nvim_get_current_win())
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("focuses detail with <C-l> from listing when detail is visible", function()
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, {
|
||||
vim.json.encode({ Action = "output", Test = "TestFoo/Sub", Output = "=== RUN TestFoo/Sub\n" }),
|
||||
vim.json.encode({ Action = "fail", Test = "TestFoo/Sub" }),
|
||||
}, nil)
|
||||
end
|
||||
if opts and opts.on_exit then
|
||||
opts.on_exit(1, 1, nil)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/output_detail_focus_l_test.go")
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
|
||||
test_samurai.test_file()
|
||||
local out_buf = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(out_buf, 0, -1, false)
|
||||
local target = nil
|
||||
for i, line in ipairs(lines) do
|
||||
if line:match("^%[ FAIL %] %- ") then
|
||||
target = i
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_not_nil(target)
|
||||
vim.api.nvim_win_set_cursor(0, { target, 0 })
|
||||
|
||||
local output_win = vim.api.nvim_get_current_win()
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
local detail_win = find_detail_win(output_win)
|
||||
assert.is_not_nil(detail_win)
|
||||
vim.api.nvim_set_current_win(output_win)
|
||||
|
||||
local keys = vim.api.nvim_replace_termcodes("<C-l>", true, false, true)
|
||||
vim.api.nvim_feedkeys(keys, "x", false)
|
||||
vim.wait(20, function()
|
||||
return vim.api.nvim_get_current_win() == detail_win
|
||||
end)
|
||||
|
||||
assert.equals(detail_win, vim.api.nvim_get_current_win())
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("expands detail to full width and toggles with <leader>z", function()
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, {
|
||||
vim.json.encode({ Action = "output", Test = "TestFoo/Sub", Output = "=== RUN TestFoo/Sub\n" }),
|
||||
vim.json.encode({ Action = "fail", Test = "TestFoo/Sub" }),
|
||||
}, nil)
|
||||
end
|
||||
if opts and opts.on_exit then
|
||||
opts.on_exit(1, 1, nil)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/output_detail_full_width_test.go")
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
|
||||
test_samurai.test_file()
|
||||
local out_buf = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(out_buf, 0, -1, false)
|
||||
local target = nil
|
||||
for i, line in ipairs(lines) do
|
||||
if line:match("^%[ FAIL %] %- ") then
|
||||
target = i
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_not_nil(target)
|
||||
vim.api.nvim_win_set_cursor(0, { target, 0 })
|
||||
|
||||
local output_win = vim.api.nvim_get_current_win()
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
local detail_win = find_detail_win(output_win)
|
||||
assert.is_not_nil(detail_win)
|
||||
local left_cfg = vim.api.nvim_win_get_config(output_win)
|
||||
local right_cfg = vim.api.nvim_win_get_config(detail_win)
|
||||
local total_width = left_cfg.width + right_cfg.width
|
||||
|
||||
vim.api.nvim_set_current_win(output_win)
|
||||
local leader_keys = vim.api.nvim_replace_termcodes("<leader>z", true, false, true)
|
||||
vim.api.nvim_feedkeys(leader_keys, "x", false)
|
||||
vim.wait(20, function()
|
||||
local updated_left = vim.api.nvim_win_get_config(output_win)
|
||||
return updated_left.width <= 1
|
||||
end)
|
||||
|
||||
local collapsed_left = vim.api.nvim_win_get_config(output_win)
|
||||
local expanded_right = vim.api.nvim_win_get_config(detail_win)
|
||||
assert.is_true(collapsed_left.width <= 1)
|
||||
assert.is_true(expanded_right.width >= total_width - 1)
|
||||
|
||||
vim.api.nvim_set_current_win(detail_win)
|
||||
local leader_toggle = vim.api.nvim_replace_termcodes("<leader>z", true, false, true)
|
||||
vim.api.nvim_feedkeys(leader_toggle, "x", false)
|
||||
vim.wait(20, function()
|
||||
local updated_left = vim.api.nvim_win_get_config(output_win)
|
||||
return updated_left.width > 1
|
||||
end)
|
||||
|
||||
local toggle_left = vim.api.nvim_win_get_config(output_win)
|
||||
local toggle_right = vim.api.nvim_win_get_config(detail_win)
|
||||
local toggle_total = toggle_left.width + toggle_right.width
|
||||
local toggle_expected = math.floor(toggle_total * 0.25)
|
||||
assert.is_true(math.abs(toggle_left.width - toggle_expected) <= 1)
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("closes floats via <esc><esc>", function()
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, {
|
||||
vim.json.encode({ Action = "pass", Test = "TestFoo/Sub" }),
|
||||
}, nil)
|
||||
end
|
||||
if opts and opts.on_exit then
|
||||
opts.on_exit(1, 0, nil)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/output_detail_close_container_test.go")
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
|
||||
test_samurai.test_file()
|
||||
|
||||
local wins = find_float_wins()
|
||||
assert.equals(1, #wins)
|
||||
|
||||
local keys = vim.api.nvim_replace_termcodes("<esc><esc>", true, false, true)
|
||||
vim.api.nvim_feedkeys(keys, "x", false)
|
||||
vim.wait(20, function()
|
||||
return #find_float_wins() == 0
|
||||
end)
|
||||
|
||||
local remaining = find_float_wins()
|
||||
assert.equals(0, #remaining)
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("disables hardtime in listing/detail and restores on close", function()
|
||||
local orig_hardtime = package.loaded["hardtime"]
|
||||
local disable_calls = 0
|
||||
local enable_calls = 0
|
||||
local hardtime_state = true
|
||||
local hardtime = {
|
||||
is_plugin_enabled = true,
|
||||
disable = function()
|
||||
disable_calls = disable_calls + 1
|
||||
hardtime_state = false
|
||||
hardtime.is_plugin_enabled = false
|
||||
end,
|
||||
enable = function()
|
||||
enable_calls = enable_calls + 1
|
||||
hardtime_state = true
|
||||
hardtime.is_plugin_enabled = true
|
||||
end,
|
||||
}
|
||||
package.loaded["hardtime"] = hardtime
|
||||
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, {
|
||||
vim.json.encode({ Action = "output", Test = "TestFoo/Sub", Output = "=== RUN TestFoo/Sub\n" }),
|
||||
vim.json.encode({ Action = "fail", Test = "TestFoo/Sub" }),
|
||||
}, nil)
|
||||
end
|
||||
if opts and opts.on_exit then
|
||||
opts.on_exit(1, 1, nil)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/output_detail_hardtime_test.go")
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
|
||||
test_samurai.test_file()
|
||||
|
||||
local out_buf = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(out_buf, 0, -1, false)
|
||||
local target = nil
|
||||
for i, line in ipairs(lines) do
|
||||
if line:match("^%[ FAIL %] %- ") then
|
||||
target = i
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_not_nil(target)
|
||||
vim.api.nvim_win_set_cursor(0, { target, 0 })
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
assert.is_true(disable_calls >= 1)
|
||||
assert.is_false(hardtime_state)
|
||||
|
||||
local keys = vim.api.nvim_replace_termcodes("<esc><esc>", true, false, true)
|
||||
vim.api.nvim_feedkeys(keys, "x", false)
|
||||
vim.wait(50, function()
|
||||
return #find_float_wins() == 0
|
||||
end)
|
||||
|
||||
assert.equals(1, enable_calls)
|
||||
assert.is_true(hardtime_state)
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
package.loaded["hardtime"] = orig_hardtime
|
||||
end)
|
||||
|
||||
it("closes detail when listing float is closed", function()
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
@@ -1726,7 +2315,7 @@ describe("test-samurai output detail view", function()
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("closes container when navigating out of floats", function()
|
||||
it("keeps floats open when navigating out of floats", function()
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
@@ -1761,17 +2350,24 @@ describe("test-samurai output detail view", function()
|
||||
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
local non_float = find_non_float_win()
|
||||
local non_float = nil
|
||||
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
local cfg = vim.api.nvim_win_get_config(win)
|
||||
if cfg.relative == "" then
|
||||
non_float = win
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_not_nil(non_float)
|
||||
vim.api.nvim_set_current_win(non_float)
|
||||
|
||||
local remaining = find_float_wins()
|
||||
assert.equals(0, #remaining)
|
||||
assert.equals(2, #remaining)
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("keeps container open when focusing listing from detail", function()
|
||||
it("keeps floats open when focusing listing from detail", function()
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
@@ -1808,13 +2404,7 @@ describe("test-samurai output detail view", function()
|
||||
core.open_test_output_at_cursor()
|
||||
|
||||
local wins = find_float_wins()
|
||||
local detail_win = nil
|
||||
for _, win in ipairs(wins) do
|
||||
if win ~= output_win then
|
||||
detail_win = win
|
||||
break
|
||||
end
|
||||
end
|
||||
local detail_win = find_detail_win(output_win)
|
||||
assert.is_not_nil(detail_win)
|
||||
vim.api.nvim_set_current_win(detail_win)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user