Skip to content

Commit

Permalink
refactor(neotest): replace table keybindings by opts function instead
Browse files Browse the repository at this point in the history
  • Loading branch information
cristobalgvera committed Sep 4, 2024
1 parent 6c9b679 commit 11ce8f0
Showing 1 changed file with 47 additions and 23 deletions.
70 changes: 47 additions & 23 deletions lua/astrocommunity/test/neotest/init.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,58 @@
local prefix = "<Leader>T"
---@type LazySpec
return {
"nvim-neotest/neotest",
lazy = true,
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-neotest/nvim-nio",
{ "AstroNvim/astroui", opts = { icons = { Tests = "󰗇" } } },
{
"AstroNvim/astrocore",
opts = {
mappings = {
n = {
[prefix] = { desc = "󰗇 Tests" },
[prefix .. "t"] = { function() require("neotest").run.run() end, desc = "Run test" },
[prefix .. "d"] = { function() require("neotest").run.run { strategy = "dap" } end, desc = "Debug test" },
[prefix .. "f"] = {
function() require("neotest").run.run(vim.fn.expand "%") end,
desc = "Run all tests in file",
},
[prefix .. "p"] = {
function() require("neotest").run.run(vim.fn.getcwd()) end,
desc = "Run all tests in project",
},
[prefix .. "<CR>"] = { function() require("neotest").summary.toggle() end, desc = "Test Summary" },
[prefix .. "o"] = { function() require("neotest").output.open() end, desc = "Output hover" },
[prefix .. "O"] = { function() require("neotest").output_panel.toggle() end, desc = "Output window" },
["]T"] = { function() require("neotest").jump.next() end, desc = "Next test" },
["[T"] = { function() require("neotest").jump.prev() end, desc = "previous test" },
},
},
},
opts = function(_, opts)
local maps = opts.mappings

local prefix = "<Leader>T"

maps.n[prefix] = {
desc = require("astroui").get_icon("Tests", 1, true) .. "Tests",
}
maps.n[prefix .. "t"] = {
function() require("neotest").run.run() end,
desc = "Run test",
}
maps.n[prefix .. "d"] = {
function() require("neotest").run.run { strategy = "dap" } end,
desc = "Debug test",
}
maps.n[prefix .. "f"] = {
function() require("neotest").run.run(vim.fn.expand "%") end,
desc = "Run all tests in file",
}
maps.n[prefix .. "p"] = {
function() require("neotest").run.run(vim.fn.getcwd()) end,
desc = "Run all tests in project",
}
maps.n[prefix .. "<CR>"] = {
function() require("neotest").summary.toggle() end,
desc = "Test Summary",
}
maps.n[prefix .. "o"] = {
function() require("neotest").output.open() end,
desc = "Output hover",
}
maps.n[prefix .. "O"] = {
function() require("neotest").output_panel.toggle() end,
desc = "Output window",
}
maps.n["]T"] = {
function() require("neotest").jump.next() end,
desc = "Next test",
}
maps.n["[T"] = {
function() require("neotest").jump.prev() end,
desc = "Previous test",
}
end,
},
{
"folke/neodev.nvim",
Expand Down

0 comments on commit 11ce8f0

Please sign in to comment.