98 lines
2.5 KiB
Lua
98 lines
2.5 KiB
Lua
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 stub_jobstart(opts_config)
|
|
local orig = vim.fn.jobstart
|
|
local config = opts_config or {}
|
|
vim.fn.jobstart = function(_cmd, opts)
|
|
local out = config.stdout or nil
|
|
if out and opts and opts.on_stdout then
|
|
if type(out) == "string" then
|
|
out = { out }
|
|
end
|
|
opts.on_stdout(1, out, nil)
|
|
end
|
|
if opts and opts.on_exit then
|
|
opts.on_exit(1, config.exit_code or 0, nil)
|
|
end
|
|
return 1
|
|
end
|
|
return orig
|
|
end
|
|
|
|
describe("test-samurai quickfix (js)", function()
|
|
before_each(function()
|
|
test_samurai.setup()
|
|
end)
|
|
|
|
after_each(function()
|
|
close_output_container()
|
|
vim.fn.setqflist({}, "r")
|
|
end)
|
|
|
|
it("mappt jest-verbose Failures auf die Zeile des Tests", function()
|
|
local root = vim.fs.joinpath(vim.loop.cwd(), "tests", "tmp_qf_js")
|
|
vim.fn.mkdir(root, "p")
|
|
local path = root .. "/foo_qf.test.ts"
|
|
vim.fn.writefile({
|
|
'describe("outer", function() {',
|
|
' it("inner 1", function() {',
|
|
" })",
|
|
"",
|
|
' it("inner 2", function() {',
|
|
" })",
|
|
"})",
|
|
}, path)
|
|
|
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
|
vim.api.nvim_buf_set_name(bufnr, path)
|
|
vim.bo[bufnr].filetype = "typescript"
|
|
vim.api.nvim_set_current_buf(bufnr)
|
|
|
|
local fail_symbol = string.char(0xE2, 0x9C, 0x95)
|
|
local orig_jobstart = stub_jobstart({
|
|
exit_code = 1,
|
|
stdout = { " " .. fail_symbol .. " inner 2" },
|
|
})
|
|
|
|
core.run_file()
|
|
|
|
local qf = vim.fn.getqflist()
|
|
assert.equals(1, #qf)
|
|
assert.equals(path, vim.fn.bufname(qf[1].bufnr))
|
|
assert.equals(5, qf[1].lnum)
|
|
|
|
vim.fn.jobstart = orig_jobstart
|
|
end)
|
|
end)
|