Improve nvim lua testing experience

main
Ensar Sarajčić 2022-05-07 20:56:11 +02:00
parent 0caec65ecf
commit 62a9f42561
1 changed files with 38 additions and 3 deletions

View File

@ -14,10 +14,45 @@ vim.keymap.set("n", "<Leader>ts", ":TestSuite<CR>", opts)
vim.keymap.set("n", "<Leader>tl", ":TestLast<CR>", opts)
vim.keymap.set("n", "<Leader>tg", ":TestVisit<CR>", opts)
local last_path = nil
vim.api.nvim_create_user_command("PlenaryTestFile", function()
require("plenary.test_harness").test_directory(vim.fn.expand("%:p"))
last_path = vim.fn.expand("%:p")
require("plenary.test_harness").test_directory(last_path)
end, {})
vim.api.nvim_create_user_command("PlenaryTestFileWithLocalMinInit", function()
require("plenary.test_harness").test_directory(vim.fn.expand("%:p"), { minimal_init = "tests/minimal.vim" })
vim.api.nvim_create_user_command("PlenaryTestSuite", function()
last_path = vim.fn["projectionist#path"]()
require("plenary.test_harness").test_directory(last_path)
end, {})
vim.api.nvim_create_user_command("PlenaryTestLast", function()
if not last_path then
vim.notify("No plenary tests run yet! Nothing to do here", vim.log.levels.WARN)
return
end
require("plenary.test_harness").test_directory(last_path)
end, {})
vim.api.nvim_create_user_command("PlenaryVisitLastTest", function()
if not last_path then
vim.notify("No plenary tests run yet! Nothing to do here", vim.log.levels.WARN)
return
end
vim.cmd("edit " .. last_path)
end, {})
local au_id = vim.api.nvim_create_augroup("plenary_test_group", {})
vim.api.nvim_create_autocmd("FileType", {
pattern = "lua",
group = au_id,
callback = function()
vim.keymap.set("n", "<Leader>tn", ":PlenaryTestFile<CR>", opts)
vim.keymap.set("n", "<Leader>tf", ":PlenaryTestFile<CR>", opts)
vim.keymap.set("n", "<Leader>ts", ":PlenaryTestSuite<CR>", opts)
vim.keymap.set("n", "<Leader>tl", ":PlenaryTestLast<CR>", opts)
vim.keymap.set("n", "<Leader>tg", ":PlenaryVisitLastTest<CR>", opts)
end,
})