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 82beddb commit d8077c0
Showing 1 changed file with 82 additions and 46 deletions.
128 changes: 82 additions & 46 deletions lua/astrocommunity/test/neotest/init.lua
Original file line number Diff line number Diff line change
@@ -1,60 +1,96 @@
local prefix = "<Leader>T"
local watch_prefix = prefix .. "W"

---@type LazySpec
return {
"nvim-neotest/neotest",
lazy = true,
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-neotest/nvim-nio",
{
"AstroNvim/astrocore",
"AstroNvim/astroui",
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" },

[watch_prefix] = { desc = " Watch" },
[watch_prefix .. "t"] = {
function() require("neotest").watch.toggle() end,
desc = "Toggle watch test",
},
[watch_prefix .. "f"] = {
function() require("neotest").watch.toggle(vim.fn.expand "%") end,
desc = "Toggle watch all test in file",
},
[watch_prefix .. "p"] = {
function() require("neotest").watch.toggle(vim.fn.getcwd()) end,
desc = "Toggle watch all tests in project",
},
[watch_prefix .. "S"] = {
function()
--- NOTE: The proper type of the argument is missing in the documentation
---@see https://github.com/nvim-neotest/neotest/blob/master/doc/neotest.txt#L626
---@diagnostic disable-next-line: missing-parameter
require("neotest").watch.stop()
end,
desc = "Stop all watches",
},
},
icons = {
Tests = "󰗇",
Watch = "",
},
},
},
{
"AstroNvim/astrocore",
opts = function(_, opts)
local maps = opts.mappings

local prefix = "<Leader>T"
local watch_prefix = prefix .. "W"

local get_file_path = function() return vim.fn.expand "%" end
local get_project_path = function() return vim.fn.getcwd() end

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(get_file_path()) end,
desc = "Run all tests in file",
}
maps.n[prefix .. "p"] = {
function() require("neotest").run.run(get_project_path()) 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",
}

maps.n[watch_prefix] = {
desc = require("astroui").get_icon("Watch", 1, true) .. "Watch",
}
maps.n[watch_prefix .. "t"] = {
function() require("neotest").watch.toggle() end,
desc = "Toggle watch test",
}
maps.n[watch_prefix .. "f"] = {
function() require("neotest").watch.toggle(get_file_path()) end,
desc = "Toggle watch all test in file",
}
maps.n[watch_prefix .. "p"] = {
function() require("neotest").watch.toggle(get_project_path()) end,
desc = "Toggle watch all tests in project",
}
maps.n[watch_prefix .. "S"] = {
function()
--- NOTE: The proper type of the argument is missing in the documentation
---@see https://github.com/nvim-neotest/neotest/blob/master/doc/neotest.txt#L626
---@diagnostic disable-next-line: missing-parameter
require("neotest").watch.stop()
end,
desc = "Stop all watches",
}
end,
},
{
"folke/neodev.nvim",
opts = function(_, opts)
Expand Down

0 comments on commit d8077c0

Please sign in to comment.