Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(neotest): add watch keybindings #1185

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 83 additions & 21 deletions lua/astrocommunity/test/neotest/init.lua
Uzaaft marked this conversation as resolved.
Show resolved Hide resolved
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
Loading