Skip to content

Commit 387164f

Browse files
committed
Add keybindings for neotest
The summary is a little bit strange for now, but it'll get better as neotest improves. The main problem is that it opens the help window in a buffer that needs to be :q'd before it goes away.
1 parent ea51d38 commit 387164f

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

lua/plugins/testing.lua

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,41 @@ return {
55
'nvim-lua/plenary.nvim',
66
'antoinemadec/FixCursorHold.nvim',
77
'nvim-treesitter/nvim-treesitter',
8+
'jfpedroza/neotest-elixir',
9+
'zidhuss/neotest-minitest',
810
},
11+
config = function()
12+
require('neotest').setup {
13+
adapters = {
14+
require 'neotest-elixir',
15+
require 'neotest-minitest',
16+
},
17+
}
18+
19+
local map = function(keys, func, desc, mode)
20+
mode = mode or 'n'
21+
vim.keymap.set(mode, keys, func, { desc = desc })
22+
end
23+
24+
local cmd_prefix = ':lua require("neotest")'
25+
local run_prefix = cmd_prefix .. '.run'
26+
local out_prefix = cmd_prefix .. '.output'
27+
local sum_prefix = cmd_prefix .. '.summary'
28+
local jump_prefix = cmd_prefix .. '.jump'
29+
30+
-- Test Running Keybindings
31+
map('<leader>tl', run_prefix .. '.run()<CR>', 'Neo[T]est: [l]aunch/run test')
32+
map('<leader>tx', run_prefix .. '.stop()<CR>', 'Neo[T]est: Stop test (i.e. click "[X]")')
33+
map('<leader>ta', run_prefix .. '.run(vim.fn.expand("%"))<CR>', 'Neo[T]est: Run [a]ll tests in the file')
34+
35+
map('<leader>ti', out_prefix .. '.open()<CR>', 'Neo[T]est: [i]nspect output in hover mode')
36+
map('<leader>to', out_prefix .. '.open({enter = true})<CR>', 'Neo[T]est: [o]pen output in copy mode')
37+
map('<leader>tp', cmd_prefix .. '.output_panel.toggle()', 'Neo[T]est: Toggle output [p]anel')
38+
map('<leader>tc', cmd_prefix .. '.output_panel.clear()', 'Neo[T]est: [C]lear output panel')
39+
40+
map('<leader>ts', sum_prefix .. '.toggle()<CR>', 'Neo[T]est: Toggle [s]ummary')
41+
42+
map('<leader>tn', jump_prefix .. '.next({ status = "failed" })<CR>', 'Neo[T]est: Jump to [n]ext failed test')
43+
map('<leader>tN', jump_prefix .. '.prev({ status = "failed" })<CR>', 'Neo[T]est: Jump to [p]revious failed test')
44+
end,
945
}

lua/plugins/which-key.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ return { -- Useful plugin to show you pending keybinds.
6060
{ '<leader>s', group = '[S]earch & [S]ort' },
6161
{ '<leader>si', group = '[S]ort [i]nside character pair' },
6262
{ '<leader>sI', group = 'Reverse [S]ort [I]nside character pair' },
63-
{ '<leader>t', group = '[T]oggle' },
63+
{ '<leader>t', group = '[T]est & [T]oggle' },
6464
{ '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } },
6565
},
6666
},

0 commit comments

Comments
 (0)