Skip to content

Commit

Permalink
feat(neotest): add watch keybindings (#1185)
Browse files Browse the repository at this point in the history
* feat(neotest): add watch keybindings

* refactor(neotest): replace table keybindings by opts function instead
  • Loading branch information
cristobalgvera authored Sep 9, 2024
1 parent d4bd90e commit 09e9359
Showing 1 changed file with 83 additions and 21 deletions.
104 changes: 83 additions & 21 deletions lua/astrocommunity/test/neotest/init.lua
Original file line number Diff line number Diff line change
@@ -1,35 +1,97 @@
local prefix = "<Leader>T"
---@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" },
},
icons = {
Tests = "󰗇",
Watch = "",
},
},
},
{
"AstroNvim/astrocore",
opts = function(_, opts)
local maps = opts.mappings

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

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(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",
}

local watch_prefix = prefix .. "W"

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-L632
---@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 09e9359

Please sign in to comment.