neotest.lua
1 --- Neotest: <leader>tn run nearest, <leader>tf file, <leader>ts summary, etc. (nvim-nio, plenary, treesitter from other plugins) 2 return { 3 specs = { 4 { src = 'https://github.com/nvim-neotest/neotest', name = 'neotest' }, 5 { src = 'https://github.com/antoinemadec/FixCursorHold.nvim', name = 'FixCursorHold.nvim' }, 6 { src = 'https://github.com/nvim-neotest/neotest-plenary', name = 'neotest-plenary' }, 7 { src = 'https://github.com/nvim-neotest/neotest-vim-test', name = 'neotest-vim-test' }, 8 { src = 'https://github.com/fredrikaverpil/neotest-golang', name = 'neotest-golang' }, 9 }, 10 config = function() 11 local neotest = require('neotest') 12 if type(neotest) ~= 'table' or not neotest.setup then 13 return 14 end 15 local adapters = {} 16 local adapter_ok, golang = pcall(require, 'neotest-golang') 17 if adapter_ok and golang then 18 local cfg = { 19 go_test_args = { 20 '-v', 21 '-race', 22 '-count=1', 23 '-timeout=60s', 24 '-coverprofile=' .. vim.fn.getcwd() .. '/coverage.out', 25 }, 26 dap_go_enabled = true, 27 } 28 if type(golang.setup) == 'function' then 29 golang.setup(cfg) 30 end 31 adapters[#adapters + 1] = golang 32 end 33 local plenary_ok, plenary = pcall(require, 'neotest-plenary') 34 if plenary_ok and plenary then 35 adapters[#adapters + 1] = plenary 36 end 37 local vimtest_ok, vimtest = pcall(require, 'neotest-vim-test') 38 if vimtest_ok and vimtest then 39 adapters[#adapters + 1] = vimtest 40 end 41 neotest.setup({ adapters = adapters }) 42 vim.keymap.set('n', '<leader>ta', function() 43 neotest.run.attach() 44 end, { desc = '[t]est [a]ttach' }) 45 vim.keymap.set('n', '<leader>tf', function() 46 neotest.run.run(vim.fn.expand('%')) 47 end, { desc = '[t]est run [f]ile' }) 48 vim.keymap.set('n', '<leader>tA', function() 49 neotest.run.run(vim.uv.cwd()) 50 end, { desc = '[t]est [A]ll files' }) 51 vim.keymap.set('n', '<leader>tS', function() 52 neotest.run.run({ suite = true }) 53 end, { desc = '[t]est [S]uite' }) 54 vim.keymap.set('n', '<leader>tn', function() 55 neotest.run.run() 56 end, { desc = '[t]est [n]earest' }) 57 vim.keymap.set('n', '<leader>tl', function() 58 neotest.run.run_last() 59 end, { desc = '[t]est [l]ast' }) 60 vim.keymap.set('n', '<leader>ts', function() 61 neotest.summary.toggle() 62 end, { desc = '[t]est [s]ummary' }) 63 vim.keymap.set('n', '<leader>to', function() 64 neotest.output.open({ enter = true, auto_close = true }) 65 end, { desc = '[t]est [o]utput' }) 66 vim.keymap.set('n', '<leader>tO', function() 67 neotest.output_panel.toggle() 68 end, { desc = '[t]est [O]utput panel' }) 69 vim.keymap.set('n', '<leader>tt', function() 70 neotest.run.stop() 71 end, { desc = '[t]est [t]erminate' }) 72 vim.keymap.set('n', '<leader>td', function() 73 neotest.run.run({ suite = false, strategy = 'dap' }) 74 end, { desc = 'Debug nearest test' }) 75 end, 76 }