refactor(vim): move jest commands to use Run rather than run in process
The jest out put is quite hard to process. This points that were add into the quickfix list where often incorrect. This is a bit pointless and I would find myself running it again in the terminal to see all of the output. This will have todo until I can find time to create proper test runner, I really don't like the look of any of the plugins available.
This commit is contained in:
parent
fde2a7ae78
commit
a0c35f90b5
1 changed files with 8 additions and 89 deletions
|
|
@ -68,105 +68,24 @@ local function get_all_tests()
|
||||||
return tests
|
return tests
|
||||||
end
|
end
|
||||||
|
|
||||||
local function parse_results(results)
|
local base_jest_command = "jest --maxWorkers=25\\% --silent"
|
||||||
local issues = {}
|
|
||||||
|
|
||||||
for _, result in ipairs(results.testResults) do
|
|
||||||
if result.status ~= "passed" then
|
|
||||||
local file = result.message:match "([^:(]+):%d+:%d+"
|
|
||||||
local line = result.message:match "[^:]+:(%d+):%d+"
|
|
||||||
local message = result.message:match "\n\n%s+([^\n]+)"
|
|
||||||
|
|
||||||
table.insert(issues, { text = message, filename = file, lnum = line })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return issues
|
|
||||||
end
|
|
||||||
|
|
||||||
local function run_at_cursor()
|
local function run_at_cursor()
|
||||||
vim.fn.jobstart({
|
local command = string.format("%s -t '%s' %s", base_jest_command, get_test_name_at_cursor(), vim.fn.expand "%")
|
||||||
"jest",
|
vim.cmd("Run " .. command)
|
||||||
"--maxWorkers=25%",
|
|
||||||
"--silent",
|
|
||||||
"--json",
|
|
||||||
"-t",
|
|
||||||
get_test_name_at_cursor(),
|
|
||||||
vim.fn.expand "%",
|
|
||||||
}, {
|
|
||||||
stdout_buffered = true,
|
|
||||||
on_stdout = function(_, output)
|
|
||||||
local results = vim.json.decode(output[1])
|
|
||||||
local issues = parse_results(results)
|
|
||||||
|
|
||||||
if #issues == 0 then
|
|
||||||
-- print "All tests passed"
|
|
||||||
else
|
|
||||||
vim.fn.setqflist({}, "r", { title = "Jest Failers", items = issues })
|
|
||||||
vim.cmd "copen"
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
on_stderr = function(_, data)
|
|
||||||
-- This will display the progress for the tests
|
|
||||||
print(data[1])
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function run_file()
|
local function run_file()
|
||||||
vim.fn.jobstart({
|
local command = string.format("%s %s", base_jest_command, vim.fn.expand "%")
|
||||||
"jest",
|
vim.cmd("Run " .. command)
|
||||||
"--maxWorkers=25%",
|
|
||||||
"--silent",
|
|
||||||
"--json",
|
|
||||||
vim.fn.expand "%",
|
|
||||||
}, {
|
|
||||||
stdout_buffered = true,
|
|
||||||
on_stdout = function(_, output)
|
|
||||||
local results = vim.json.decode(output[1])
|
|
||||||
local issues = parse_results(results)
|
|
||||||
|
|
||||||
if #issues == 0 then
|
|
||||||
-- print "All tests passed"
|
|
||||||
else
|
|
||||||
vim.fn.setqflist({}, "r", { title = "Jest Failers", items = issues })
|
|
||||||
vim.cmd "copen"
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
on_stderr = function(_, data)
|
|
||||||
-- This will display the progress for the tests
|
|
||||||
print(data[1])
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function run_all()
|
local function run_all()
|
||||||
vim.fn.jobstart({
|
vim.cmd("Run " .. base_jest_command)
|
||||||
"jest",
|
|
||||||
"--maxWorkers=25%",
|
|
||||||
"--silent",
|
|
||||||
"--json",
|
|
||||||
}, {
|
|
||||||
stdout_buffered = true,
|
|
||||||
on_stdout = function(_, output)
|
|
||||||
local results = vim.json.decode(output[1])
|
|
||||||
local issues = parse_results(results)
|
|
||||||
|
|
||||||
if #issues == 0 then
|
|
||||||
-- print "All tests passed"
|
|
||||||
else
|
|
||||||
vim.fn.setqflist({}, "r", { title = "Jest Failers", items = issues })
|
|
||||||
vim.cmd "copen"
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
on_stderr = function(_, data)
|
|
||||||
-- This will display the progress for the tests
|
|
||||||
print(data[1])
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("Jest", run_all, { bang = true })
|
vim.api.nvim_create_user_command("Jest", run_all, { bang = true })
|
||||||
vim.api.nvim_create_user_command("JestFile", run_file, { bang = true })
|
vim.api.nvim_create_user_command("JestFile", run_file, { bang = true })
|
||||||
vim.api.nvim_create_user_command("JestAtCursor", run_at_cursor, { bang = true })
|
vim.api.nvim_create_user_command("JestAtCursor", run_at_cursor, { bang = true })
|
||||||
vim.api.nvim_set_keymap("n", "t", "<cmd>JestAtCursor<CR>", { nowait = true, silent = true })
|
vim.api.nvim_set_keymap("n", "tt", "<cmd>JestAtCursor<CR>", { nowait = true, silent = true })
|
||||||
|
vim.api.nvim_set_keymap("n", "tf", "<cmd>JestFile<CR>", { nowait = true, silent = true })
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue