include stdout into the detail-float
All checks were successful
tests / test (push) Successful in 7s

This commit is contained in:
2026-01-06 12:27:19 +01:00
parent aa343f67ca
commit e4b4097999
4 changed files with 143 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ local runner = {
}
local RESULT_PREFIX = "TSAMURAI_RESULT "
local STDOUT_PREFIX = "TSAMURAI_STDOUT "
local STATUS_MAP = {
passed = "passes",
failed = "failures",
@@ -341,6 +342,15 @@ local function reporter_path()
return vim.fs.normalize(dir .. "/../../reporter/test_samurai_jest_reporter.js")
end
local function setup_path()
local source = debug.getinfo(1, "S").source
if source:sub(1, 1) == "@" then
source = source:sub(2)
end
local dir = vim.fs.dirname(source)
return vim.fs.normalize(dir .. "/../../reporter/test_samurai_jest_stdout.js")
end
local function base_cmd()
return {
"npx",
@@ -348,6 +358,8 @@ local function base_cmd()
"--testLocationInResults",
"--reporters",
reporter_path(),
"--setupFilesAfterEnv",
setup_path(),
}
end
@@ -366,6 +378,21 @@ local function parse_result_line(line)
return data
end
local function parse_stdout_line(line)
if not line or line == "" then
return nil
end
if line:sub(1, #STDOUT_PREFIX) ~= STDOUT_PREFIX then
return nil
end
local payload = line:sub(#STDOUT_PREFIX + 1)
local ok, data = pcall(vim.json.decode, payload)
if not ok or type(data) ~= "table" then
return nil
end
return data
end
local function update_location_cache(name, data)
if not name or name == "" then
return
@@ -675,9 +702,14 @@ function runner.parse_test_output(output)
if not output or output == "" then
return out
end
local jest_to_listing = {}
local pending = {}
for line in output:gmatch("[^\n]+") do
local data = parse_result_line(line)
if data and data.name and data.output then
if data.jestName and data.jestName ~= "" then
jest_to_listing[data.jestName] = data.name
end
out[data.name] = out[data.name] or {}
if type(data.output) == "string" then
for _, item in ipairs(split_output_lines(data.output)) do
@@ -691,6 +723,49 @@ function runner.parse_test_output(output)
end
end
end
local stdout = parse_stdout_line(line)
if stdout and (stdout.name or stdout.jestName) and stdout.output then
local stdout_name = stdout.name or stdout.jestName
local target = jest_to_listing[stdout_name] or stdout_name
if not jest_to_listing[stdout_name] then
pending[stdout_name] = pending[stdout_name] or {}
table.insert(pending[stdout_name], stdout.output)
else
out[target] = out[target] or {}
if type(stdout.output) == "string" then
for _, item in ipairs(split_output_lines(stdout.output)) do
if item ~= "" then
table.insert(out[target], item)
end
end
elseif type(stdout.output) == "table" then
for _, item in ipairs(stdout.output) do
if item and item ~= "" then
table.insert(out[target], item)
end
end
end
end
end
end
for jest_name, outputs in pairs(pending) do
local target = jest_to_listing[jest_name] or jest_name
out[target] = out[target] or {}
for _, items in ipairs(outputs) do
if type(items) == "string" then
for _, item in ipairs(split_output_lines(items)) do
if item ~= "" then
table.insert(out[target], item)
end
end
elseif type(items) == "table" then
for _, item in ipairs(items) do
if item and item ~= "" then
table.insert(out[target], item)
end
end
end
end
end
return out
end