change output format for TSamAll from short- to fullname
This commit is contained in:
@@ -311,28 +311,31 @@ local function run_cmd(cmd, cwd, handlers)
|
||||
})
|
||||
end
|
||||
|
||||
local function pick_display(results, key)
|
||||
local function pick_display(results, key, scope_kind)
|
||||
if scope_kind == "all" then
|
||||
return results[key]
|
||||
end
|
||||
if type(results.display) == "table" and type(results.display[key]) == "table" then
|
||||
return results.display[key]
|
||||
end
|
||||
return results[key]
|
||||
end
|
||||
|
||||
local function format_results(results)
|
||||
local function format_results(results, scope_kind)
|
||||
local lines = {}
|
||||
local passes = pick_display(results, "passes")
|
||||
local passes = pick_display(results, "passes", scope_kind)
|
||||
if type(passes) == "table" then
|
||||
for _, title in ipairs(passes) do
|
||||
table.insert(lines, "[ PASS ] - " .. title)
|
||||
end
|
||||
end
|
||||
local skips = pick_display(results, "skips")
|
||||
local skips = pick_display(results, "skips", scope_kind)
|
||||
if type(skips) == "table" then
|
||||
for _, title in ipairs(skips) do
|
||||
table.insert(lines, "[ SKIP ] - " .. title)
|
||||
end
|
||||
end
|
||||
local failures = pick_display(results, "failures")
|
||||
local failures = pick_display(results, "failures", scope_kind)
|
||||
if type(failures) == "table" then
|
||||
for _, title in ipairs(failures) do
|
||||
table.insert(lines, "[ FAIL ] - " .. title)
|
||||
@@ -373,6 +376,7 @@ local function run_command(command, opts)
|
||||
parser = { on_complete = parser }
|
||||
end
|
||||
local parser_state = {}
|
||||
parser_state.scope_kind = options.scope_kind
|
||||
local had_parsed_output = false
|
||||
|
||||
local output_lines = {}
|
||||
@@ -413,7 +417,7 @@ local function run_command(command, opts)
|
||||
state.last_scope_failures = results.failures
|
||||
end
|
||||
end
|
||||
local lines = format_results(results)
|
||||
local lines = format_results(results, options.scope_kind)
|
||||
if #lines == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -934,6 +934,9 @@ function M.new(opts)
|
||||
if results then
|
||||
state.done = true
|
||||
state.saw_stream = true
|
||||
if _state and _state.scope_kind == "all" and jest_streamed then
|
||||
return emit_jest_results(results, false)
|
||||
end
|
||||
return emit_jest_results(results, not jest_streamed)
|
||||
end
|
||||
return nil
|
||||
|
||||
@@ -316,6 +316,140 @@ describe("test-samurai output formatting", function()
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
vim.api.nvim_win_set_cursor(0, { 7, 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 has_pass = false
|
||||
local has_skip = false
|
||||
local has_fail = false
|
||||
local has_raw_verbose = false
|
||||
for _, line in ipairs(lines) do
|
||||
if line == "[ PASS ] - inner 1" then
|
||||
has_pass = true
|
||||
elseif line == "[ SKIP ] - inner skip" then
|
||||
has_skip = true
|
||||
elseif line == "[ FAIL ] - inner 2" then
|
||||
has_fail = true
|
||||
elseif line:match("^%s*PASS%s+") then
|
||||
has_raw_verbose = true
|
||||
end
|
||||
end
|
||||
assert.is_true(has_pass)
|
||||
assert.is_true(has_skip)
|
||||
assert.is_true(has_fail)
|
||||
assert.is_false(has_raw_verbose)
|
||||
end)
|
||||
|
||||
it("formats jest JSON output for TSamAll as full names", function()
|
||||
local json = vim.json.encode({
|
||||
testResults = {
|
||||
{
|
||||
assertionResults = {
|
||||
{ status = "passed", title = "inner 1", fullName = "outer inner 1" },
|
||||
{ status = "skipped", title = "inner skip", fullName = "outer inner skip" },
|
||||
{ status = "failed", title = "inner 2", fullName = "outer inner 2" },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, { json }, 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_fullname_all.test.ts")
|
||||
vim.bo[bufnr].filetype = "typescript"
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {
|
||||
'describe("outer", function() {',
|
||||
' it("inner 1", function() {',
|
||||
" -- inside 1",
|
||||
" })",
|
||||
"",
|
||||
' it("inner 2", function() {',
|
||||
" -- inside 2",
|
||||
" })",
|
||||
"})",
|
||||
})
|
||||
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
vim.api.nvim_win_set_cursor(0, { 7, 0 })
|
||||
|
||||
core.run_all()
|
||||
|
||||
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 has_pass = false
|
||||
local has_skip = false
|
||||
local has_fail = false
|
||||
for _, line in ipairs(lines) do
|
||||
if line == "[ PASS ] - outer inner 1" then
|
||||
has_pass = true
|
||||
elseif line == "[ SKIP ] - outer inner skip" then
|
||||
has_skip = true
|
||||
elseif line == "[ FAIL ] - outer inner 2" then
|
||||
has_fail = true
|
||||
end
|
||||
end
|
||||
|
||||
assert.is_true(has_pass)
|
||||
assert.is_true(has_skip)
|
||||
assert.is_true(has_fail)
|
||||
end)
|
||||
|
||||
it("formats jest verbose output for TSamAll as short names", function()
|
||||
local check = string.char(0xE2, 0x9C, 0x93)
|
||||
local cross = string.char(0xE2, 0x9C, 0x95)
|
||||
local circle = string.char(0xE2, 0x97, 0x8B)
|
||||
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, {
|
||||
" PASS /tmp/output_verbose_all.test.ts",
|
||||
" " .. check .. " inner 1 (5 ms)",
|
||||
" " .. circle .. " inner skip (skipped)",
|
||||
" " .. cross .. " inner 2 (1 ms)",
|
||||
}, 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_verbose_all.test.ts")
|
||||
vim.bo[bufnr].filetype = "typescript"
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {
|
||||
'describe("outer", function() {',
|
||||
' it("inner 1", function() {',
|
||||
" -- inside 1",
|
||||
" })",
|
||||
"",
|
||||
' it("inner 2", function() {',
|
||||
" -- inside 2",
|
||||
" })",
|
||||
"})",
|
||||
})
|
||||
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
vim.api.nvim_win_set_cursor(0, { 7, 0 })
|
||||
|
||||
core.run_all()
|
||||
|
||||
local out_buf = vim.api.nvim_get_current_buf()
|
||||
@@ -338,6 +472,7 @@ describe("test-samurai output formatting", function()
|
||||
has_raw_verbose = true
|
||||
end
|
||||
end
|
||||
|
||||
assert.is_true(has_pass)
|
||||
assert.is_true(has_skip)
|
||||
assert.is_true(has_fail)
|
||||
|
||||
Reference in New Issue
Block a user