return { 'neotest', keys = { { 't', '', desc = '+test' }, { 'tl', function() require('neotest').run.run_last() end, desc = 'run last', }, { 'to', function() require('neotest').output.open({ enter = true, auto_close = true }) end, desc = 'show output', }, { 'tO', function() require('neotest').output_panel.toggle() end, desc = 'toggle output panel', }, { 'tr', function() require('neotest').run.run() end, desc = 'run nearest', }, { 'ts', function() require('neotest').summary.toggle() end, desc = 'toggle summary', }, { 'tS', function() require('neotest').run.stop() end, desc = 'stop tests', }, { 'tt', function() require('neotest').run.run(vim.fn.expand('%')) end, desc = 'run file tests', }, { 'tT', function() require('neotest').run.run(vim.uv.cwd()) end, desc = 'run all tests', }, { 'tw', function() require('neotest').watch.toggle(vim.fn.expand('%')) end, desc = 'toggle watch', }, }, before = function() require('lz.n').trigger_load({ 'nvim-nio', 'plenary.nvim', 'nvim-treesitter', }) end, after = function() local neotest_ns = vim.api.nvim_create_namespace('neotest') vim.diagnostic.config({ virtual_text = { format = function(diagnostic) -- Replace newline/tab chars with spaces. return diagnostic.message :gsub('\n', ' ') :gsub('\t', ' ') :gsub('%s+', ' ') :gsub('^%s+', ' ') end, }, }, neotest_ns) local consumers = {} -- Refresh and auto-close trouble after running tests. local has_trouble, _ = pcall(require, 'trouble') if has_trouble then ---@type neotest.Consumer consumers.trouble = function(client) client.listeners.results = function(adapter_id, results, partial) if partial then return end local tree = assert(client:get_position(nil, { adapter = adapter_id })) local failed = 0 for pos_id, result in pairs(results) do if result.status == 'failed' and tree:get_key(pos_id) then failed = failed + 1 end end vim.schedule(function() local trouble = require('trouble') if trouble.is_open() then trouble.refresh() if failed == 0 then trouble.close() end end end) end return {} end end require('neotest').setup({ status = { virtual_text = true }, output = { virtual_text = true }, quickfix = { open = function() if has_trouble then require('trouble').open({ mode = 'quickfix', focus = false }) else vim.cmd('copen') end end, }, consumers = consumers, }) end, }