mirror of
https://github.com/pratiktri/dotfiles.git
synced 2026-02-05 00:41:44 +05:30
147 lines
6.5 KiB
Lua
147 lines
6.5 KiB
Lua
return {
|
|
-- Test runner integration
|
|
-- Taken from LazyVim
|
|
{
|
|
"nvim-neotest/neotest",
|
|
dependencies = {
|
|
"nvim-neotest/nvim-nio",
|
|
"nvim-lua/plenary.nvim",
|
|
"antoinemadec/FixCursorHold.nvim",
|
|
"nvim-treesitter/nvim-treesitter",
|
|
|
|
"marilari88/neotest-vitest", -- JS/TS/React/Vue
|
|
},
|
|
opts = {
|
|
-- Do NOT add adapters here
|
|
-- Add it to opts.adapters inside config function below
|
|
adapters = {},
|
|
status = { virtual_text = true },
|
|
output = { open_on_run = true },
|
|
quickfix = {
|
|
open = function()
|
|
if require("lazy.core.config").spec.plugins["trouble.nvim"] ~= nil then
|
|
require("trouble").open({ mode = "quickfix", focus = false })
|
|
else
|
|
vim.cmd("copen")
|
|
end
|
|
end,
|
|
},
|
|
},
|
|
config = function(_, opts)
|
|
local neotest_ns = vim.api.nvim_create_namespace("neotest")
|
|
vim.diagnostic.config({
|
|
virtual_text = {
|
|
format = function(diagnostic)
|
|
-- Replace newline and tab characters with space for more compact diagnostics
|
|
local message = diagnostic.message:gsub("\n", " "):gsub("\t", " "):gsub("%s+", " "):gsub("^%s+", "")
|
|
return message
|
|
end,
|
|
},
|
|
}, neotest_ns)
|
|
|
|
if require("lazy.core.config").spec.plugins["trouble.nvim"] ~= nil then
|
|
opts.consumers = opts.consumers or {}
|
|
opts.consumers.trouble = function(client)
|
|
client.listeners.results = function(adapter_id, results, partial)
|
|
if partial then
|
|
return
|
|
end
|
|
local tree = assert(client:get_position(nil, { adapter = adapter_id }))
|
|
|
|
local failed = 0
|
|
for pos_id, result in pairs(results) do
|
|
if result.status == "failed" and tree:get_key(pos_id) then
|
|
failed = failed + 1
|
|
end
|
|
end
|
|
vim.schedule(function()
|
|
local trouble = require("trouble")
|
|
if trouble.is_open() then
|
|
trouble.refresh()
|
|
if failed == 0 then
|
|
trouble.close()
|
|
end
|
|
end
|
|
end)
|
|
return {}
|
|
end
|
|
end
|
|
end
|
|
|
|
-- TIP: Add adapters here
|
|
table.insert(opts.adapters, require("neotest-vitest"))
|
|
table.insert(opts.adapters, require("rustaceanvim.neotest"))
|
|
|
|
if opts.adapters then
|
|
local adapters = {}
|
|
for name, config in pairs(opts.adapters or {}) do
|
|
if type(name) == "number" then
|
|
if type(config) == "string" then
|
|
config = require(config)
|
|
end
|
|
adapters[#adapters + 1] = config
|
|
elseif config ~= false then
|
|
local adapter = require(name)
|
|
if type(config) == "table" and not vim.tbl_isempty(config) then
|
|
local meta = getmetatable(adapter)
|
|
if adapter.setup then
|
|
adapter.setup(config)
|
|
elseif meta and meta.__call then
|
|
adapter(config)
|
|
else
|
|
error("Adapter " .. name .. " does not support setup")
|
|
end
|
|
end
|
|
adapters[#adapters + 1] = adapter
|
|
end
|
|
end
|
|
opts.adapters = adapters
|
|
end
|
|
|
|
require("neotest").setup(opts)
|
|
end,
|
|
-- stylua: ignore
|
|
keys = {
|
|
-- TIP: Shortcuts in test summary window:
|
|
-- r: Run the selected test
|
|
-- a: Attaches to the test result (output)
|
|
-- i: Jumps to the code of the test
|
|
{ "<leader>tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Test: Run All Test in Current File" },
|
|
{ "<leader>tT", function() require("neotest").run.run(vim.loop.cwd()) end, desc = "Test: Run All Test Files" },
|
|
{ "<leader>tn", function() require("neotest").run.run() end, desc = "Test: Run Nearest" },
|
|
{ "<leader>tR", function() require("neotest").run.run_last() end, desc = "Test: Re-Run Last" },
|
|
{ "<leader>ts", function() require("neotest").run.stop() end, desc = "Test: Stop" },
|
|
|
|
{ "<leader>to", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Test: Show Output" },
|
|
{ "<leader>tO", function() require("neotest").output_panel.toggle() end, desc = "Test: Toggle Output Panel" },
|
|
{ "<leader>tS", function() require("neotest").summary.toggle() end, desc = "Test: Toggle Summary Panel" },
|
|
},
|
|
},
|
|
|
|
{
|
|
"andythigpen/nvim-coverage",
|
|
dependencies = { "nvim-lua/plenary.nvim" },
|
|
config = function()
|
|
require("coverage").setup({
|
|
auto_load = true,
|
|
commands = true, -- Enable coverage commands
|
|
highlights = {
|
|
covered = { fg = "#C3E88D" }, -- Green for covered lines
|
|
uncovered = { fg = "#F07178" }, -- Red for uncovered lines
|
|
},
|
|
signs = {
|
|
covered = { hl = "CoverageCovered", text = "▎" },
|
|
uncovered = { hl = "CoverageUncovered", text = "▎" },
|
|
},
|
|
summary = {
|
|
min_coverage = 80.0, -- Minimum coverage percentage
|
|
},
|
|
})
|
|
|
|
vim.keymap.set("n", "<leader>tC", function()
|
|
require("coverage").summary()
|
|
end, { desc = "Test: Toggle coverage" })
|
|
end,
|
|
},
|
|
}
|