fix false detecting skipped tests
tests / test (push) Failing after 6s

This commit is contained in:
2026-06-12 12:13:29 +02:00
parent 770e49d98a
commit 279fc56ee5
3 changed files with 156 additions and 47 deletions
+85 -1
View File
@@ -38,7 +38,7 @@ local function get_reporter_path()
source = source:sub(2)
end
local dir = vim.fs.dirname(source)
return vim.fs.normalize(dir .. "/../../reporter/test_samurai_vitest_reporter.js")
return vim.fs.normalize(dir .. "/../../reporter/test_samurai_vitest_reporter.mjs")
end
describe("test-samurai-vitest-runner", function()
@@ -539,4 +539,88 @@ describe("test-samurai-vitest-runner", function()
local result = parser.on_line("some random vitest output line", state)
assert.is_nil(result)
end)
it("parse_results deduplicates across buckets (first skipped, then passed)", function()
local output = "TSAMURAI_RESULT " .. vim.json.encode({
name = "footer/evergreen",
status = "skipped",
file = "/tmp/footer.test.ts",
location = { line = 5, column = 1 },
}) .. "\n"
.. "TSAMURAI_RESULT " .. vim.json.encode({
name = "footer/evergreen",
status = "passed",
file = "/tmp/footer.test.ts",
location = { line = 5, column = 1 },
})
local results = runner.parse_results(output)
assert.equals(1, #results.passes)
assert.equals(0, #results.skips)
assert.equals("footer/evergreen", results.passes[1])
end)
it("build_command uses local node_modules/.bin/vitest if available", function()
with_project(VITEST_PACKAGE, function(root)
local bin_dir = root .. "/node_modules/.bin"
vim.fn.mkdir(bin_dir, "p")
write_file(bin_dir .. "/vitest", "#!/bin/sh\necho mock")
vim.fn.setfperm(bin_dir .. "/vitest", "rwxr-xr-x")
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(bufnr, root .. "/example.test.ts")
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {
'describe("footer", function()',
' it("evergreen", function()',
' assert.true(true)',
' end)',
'end)',
})
local spec = runner.find_nearest(bufnr, 2, 0)
local cmd = runner.build_command(spec).cmd
assert.equals(root .. "/node_modules/.bin/vitest", cmd[1])
end)
end)
it("base_cmd includes --config for vitest.config.ts", function()
with_project(VITEST_PACKAGE, function(root)
write_file(root .. "/vitest.config.ts", "export default { }")
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(bufnr, root .. "/example.test.ts")
local cmd = runner.build_file_command(bufnr).cmd
local has_config = false
for i, arg in ipairs(cmd) do
if arg == "--config" and cmd[i + 1] and cmd[i + 1]:match("vitest%.config%.ts$") then
has_config = true
break
end
end
assert.is_true(has_config)
end)
end)
it("reporter_path() returns .mjs file", function()
local path = get_reporter_path()
assert.is_true(path:match("test_samurai_vitest_reporter%.mjs$") ~= nil)
end)
it("build_file_command includes .mjs reporter path", function()
with_project(VITEST_PACKAGE, function(root)
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(bufnr, root .. "/example.test.ts")
local cmd = runner.build_file_command(bufnr).cmd
local has_mjs_reporter = false
for _, arg in ipairs(cmd) do
if arg:match("test_samurai_vitest_reporter%.mjs$") then
has_mjs_reporter = true
break
end
end
assert.is_true(has_mjs_reporter)
end)
end)
end)