add grouping for test listing entries
This commit is contained in:
@@ -1276,16 +1276,18 @@ describe("test-samurai output formatting", function()
|
||||
assert.is_true(set_calls.TestSamuraiSummarySkip.fg == 333)
|
||||
end)
|
||||
|
||||
it("formats go subtests as short names", function()
|
||||
local json_line = vim.json.encode({
|
||||
Action = "pass",
|
||||
Test = "TestHandleGet/returns_200",
|
||||
})
|
||||
it("groups Go subtests under their parent in listing", function()
|
||||
local json_lines = {
|
||||
vim.json.encode({ Action = "pass", Test = "TestHandleGet/returns_200" }),
|
||||
vim.json.encode({ Action = "fail", Test = "TestOther/returns_500" }),
|
||||
vim.json.encode({ Action = "pass", Test = "TestHandleGet" }),
|
||||
vim.json.encode({ Action = "skip", Test = "TestOther" }),
|
||||
}
|
||||
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, { json_line }, nil)
|
||||
opts.on_stdout(1, json_lines, nil)
|
||||
end
|
||||
if opts and opts.on_exit then
|
||||
opts.on_exit(1, 0, nil)
|
||||
@@ -1294,21 +1296,23 @@ describe("test-samurai output formatting", function()
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/output_go_short_test.go")
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/output_go_grouped_test.go")
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {
|
||||
"package main",
|
||||
"import \"testing\"",
|
||||
"",
|
||||
"func TestHandleGet(t *testing.T) {",
|
||||
" t.Run(\"returns_200\", func(t *testing.T) {",
|
||||
" -- inside test",
|
||||
" })",
|
||||
" t.Run(\"returns_200\", func(t *testing.T) {})",
|
||||
"}",
|
||||
"",
|
||||
"func TestOther(t *testing.T) {",
|
||||
" t.Run(\"returns_500\", func(t *testing.T) {})",
|
||||
"}",
|
||||
})
|
||||
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
vim.api.nvim_win_set_cursor(0, { 6, 0 })
|
||||
vim.api.nvim_win_set_cursor(0, { 5, 0 })
|
||||
|
||||
core.run_nearest()
|
||||
|
||||
@@ -1317,17 +1321,97 @@ describe("test-samurai output formatting", function()
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
|
||||
local has_pass = false
|
||||
local has_raw_json = false
|
||||
for _, line in ipairs(lines) do
|
||||
if line == "[ PASS ] - returns_200" then
|
||||
has_pass = true
|
||||
elseif line == json_line then
|
||||
has_raw_json = true
|
||||
local idx_parent_1 = nil
|
||||
local idx_sub_1 = nil
|
||||
local idx_parent_2 = nil
|
||||
local idx_sub_2 = nil
|
||||
for i, line in ipairs(lines) do
|
||||
if line == "[ PASS ] - TestHandleGet" then
|
||||
idx_parent_1 = i
|
||||
elseif line == "[ PASS ] - TestHandleGet/returns_200" then
|
||||
idx_sub_1 = i
|
||||
elseif line == "[ SKIP ] - TestOther" then
|
||||
idx_parent_2 = i
|
||||
elseif line == "[ FAIL ] - TestOther/returns_500" then
|
||||
idx_sub_2 = i
|
||||
end
|
||||
end
|
||||
assert.is_true(has_pass)
|
||||
assert.is_false(has_raw_json)
|
||||
|
||||
assert.is_not_nil(idx_parent_1)
|
||||
assert.is_not_nil(idx_sub_1)
|
||||
assert.is_not_nil(idx_parent_2)
|
||||
assert.is_not_nil(idx_sub_2)
|
||||
assert.is_true(idx_parent_1 < idx_sub_1)
|
||||
assert.is_true(idx_parent_2 < idx_sub_2)
|
||||
end)
|
||||
|
||||
it("groups nested Go subtests under subtest parents in listing", function()
|
||||
local json_lines = {
|
||||
vim.json.encode({ Action = "pass", Test = "TestWriteJSON/returns_500_when/data_could_not_be_serialized_and_logs_it" }),
|
||||
vim.json.encode({ Action = "pass", Test = "TestWriteJSON" }),
|
||||
vim.json.encode({ Action = "pass", Test = "TestWriteJSON/returns_500_when" }),
|
||||
vim.json.encode({ Action = "pass", Test = "TestWriteJSON/returns_500_when/error_at_writing_response_occurs_and_logs_it" }),
|
||||
}
|
||||
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, json_lines, 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_go_nested_test.go")
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {
|
||||
"package main",
|
||||
"import \"testing\"",
|
||||
"",
|
||||
"func TestWriteJSON(t *testing.T) {",
|
||||
" t.Run(\"returns_500_when\", func(t *testing.T) {",
|
||||
" t.Run(\"data_could_not_be_serialized_and_logs_it\", func(t *testing.T) {})",
|
||||
" t.Run(\"error_at_writing_response_occurs_and_logs_it\", func(t *testing.T) {})",
|
||||
" })",
|
||||
"}",
|
||||
})
|
||||
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
vim.api.nvim_win_set_cursor(0, { 5, 0 })
|
||||
|
||||
core.run_nearest()
|
||||
|
||||
local out_buf = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(out_buf, 0, -1, false)
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
|
||||
local idx_parent = nil
|
||||
local idx_mid = nil
|
||||
local idx_child_1 = nil
|
||||
local idx_child_2 = nil
|
||||
for i, line in ipairs(lines) do
|
||||
if line == "[ PASS ] - TestWriteJSON" then
|
||||
idx_parent = i
|
||||
elseif line == "[ PASS ] - TestWriteJSON/returns_500_when" then
|
||||
idx_mid = i
|
||||
elseif line == "[ PASS ] - TestWriteJSON/returns_500_when/data_could_not_be_serialized_and_logs_it" then
|
||||
idx_child_1 = i
|
||||
elseif line == "[ PASS ] - TestWriteJSON/returns_500_when/error_at_writing_response_occurs_and_logs_it" then
|
||||
idx_child_2 = i
|
||||
end
|
||||
end
|
||||
|
||||
assert.is_not_nil(idx_parent)
|
||||
assert.is_not_nil(idx_mid)
|
||||
assert.is_not_nil(idx_child_1)
|
||||
assert.is_not_nil(idx_child_2)
|
||||
assert.is_true(idx_parent < idx_mid)
|
||||
assert.is_true(idx_mid < idx_child_1)
|
||||
assert.is_true(idx_mid < idx_child_2)
|
||||
end)
|
||||
|
||||
it("does not print raw JSON output for mocha json-stream", function()
|
||||
|
||||
Reference in New Issue
Block a user